Author Topic: Windows 7 WinUSB driver issue  (Read 22054 times)

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Windows 7 WinUSB driver issue
« on: March 25, 2012, 10:46:30 am »
I programmed in pic_usb_device_winusb_jan_axelson_10.zip into the microcontroller. In the Windows 7 device manager, it appears as WinUSB Demo. When I updated the driver using the inf from winusb_vb_181\winusb_vb\inf, this is the error message: Windows found driver software for your device but encountered an error while attempting to install it. WinUSB Demo. The system cannot find the file specified. If you know the manufacturer of your device, you can visit its website and check the support section for driver software.

Please advise how to address this issue. I do not know what file missing.

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Windows 7 WinUSB driver issue
« Reply #1 on: March 25, 2012, 11:46:48 am »
I fixed the driver issue. However, I still not sure how to use the VB GUI to send this data to the WinUSB device "SYST"FWREV?". The microcontroller will return data then and when it is captured in the VB GUI?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Windows 7 WinUSB driver issue
« Reply #2 on: March 25, 2012, 12:30:30 pm »
To send and receive text, take a look at the code for the SendAndReceiveViaBulkTransfers routine.

Jan

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Windows 7 WinUSB driver issue
« Reply #3 on: March 25, 2012, 11:26:59 pm »
I have some concerns with The SendAndReceiveViaBulkTransfers routine.

(a) I set a breakpoint at txtDataInOUt.Text = txtBulkDataToSend.Text. When I clicked on the Send button at the UI, it does not allow me to step the codes. Instead, it sends and reads data automatically.

(b) When I send a command to the microcontroller, it may returned few data. I want the ReadDataViaBulkTransfer() routine to display the data whenever there is any data coming from the microcontroller. How to address this issue? In this case, ReadDataViaBulkTransfer() is running independently.

(c) I add in these codes to ReadDataViaBulkTransfer() routine right after ar
ar = MyReadFromDeviceDelegate.BeginInvoke _
                    (myWinUsbDevice.myDevInfo.bulkInPipe, _
                    bytesToRead, _
                    buffer, _
                    bytesRead, _
                    success, _
                    New AsyncCallback(AddressOf GetReceivedBulkData), _
                    MyReadFromDeviceDelegate)
                Dim j As Integer
                txtDataInOUt.Text = ""
                For j = 0 To 63
                    txtDataInOUt.Text = txtDataInOUt.Text & Chr(buffer(j))
                Next

lstResults gives read data of Rev: A (12th March 2012) but txtDataInOut  = "ch 2012)" only. Please advise

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Windows 7 WinUSB driver issue
« Reply #4 on: March 26, 2012, 01:57:00 pm »
>(a) I set a breakpoint at txtDataInOUt.Text = txtBulkDataToSend.Text. When I clicked on the Send button at the UI, it does not allow me to step the codes. Instead, it sends and reads data automatically.

Try putting the breakpoint further up, in cmdSendAndReceiveViaBulkTransfers_Click, or further down, in SendViaBulkTransfer.

>(b) When I send a command to the microcontroller, it may returned few data. I want the ReadDataViaBulkTransfer() routine to display the data whenever there is any data coming from the microcontroller. How to address this issue? In this case, ReadDataViaBulkTransfer() is running independently.

Call ReadDataViaBulkTransfer again after it returns data.

>(c) I add in these codes to ReadDataViaBulkTransfer() routine right after ar
ar = MyReadFromDeviceDelegate.BeginInvoke _
                    (myWinUsbDevice.myDevInfo.bulkInPipe, _
                    bytesToRead, _
                    buffer, _
                    bytesRead, _
                    success, _
                    New AsyncCallback(AddressOf GetReceivedBulkData), _
                    MyReadFromDeviceDelegate)
                Dim j As Integer
                txtDataInOUt.Text = ""
                For j = 0 To 63
                    txtDataInOUt.Text = txtDataInOUt.Text & Chr(buffer(j))
                Next

lstResults gives read data of Rev: A (12th March 2012) but txtDataInOut  = "ch 2012)" only. Please advise

If the data read from the device doesn't match the data the PC sent, isolate the problem by verifying that the PC sent the correct data, then checking to see if the device firmware is sending back what it received (or whatever data it's supposed to be sending).

Jan

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Windows 7 WinUSB driver issue
« Reply #5 on: March 26, 2012, 11:06:52 pm »
(a) I forgot to set it to "debug" mode in order to step the VB codes.

(b) User can send a command to the microcontroller to query for the stored data in the external flash. For an example, user may query for 100 sets of data or 1000 sets of data.
- Microcontroller takes time to send the data set one by one. How to synchronize ReadDataViaBulkTransfer with received data? My concern is what if the received data is not ready yet when I call the ReadDataViaBulkTransfer. 
- I used mcHID.dll before and it has the capability to read the incoming data automatically and display it.
- Can I configure WinUSB to do so?

(c) I expect the VB codes to read "Rev: A (12th March 2012)". This is the value returned by the microcontroller. The bulk transfer send button returned the correct value in lstResult. I just want to add in a text box to display this data too but failed to do so. Even I added in a message box at the send button, VB returns error too.

        ''' <summary>
        ''' Calls a routine to exchange data via bulk transfers.
        ''' </summary>

        Private Sub cmdSendAndReceiveViaBulkTransfers_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSendandReceiveViaBulkTransfers.Click
            txtDataInOUt.Text = txtBulkDataToSend.Text
            Try
                'Don't allow another transfer request until this one completes.

                cmdSendandReceiveViaBulkTransfers.Enabled = False

                SendAndReceiveViaBulkTransfers()

            Catch ex As Exception
                Throw
            End Try

            Wait(2)
            Dim temp As Integer
            temp = lstResults.Items.Count - 1
            MsgBox(lstResults.SelectedItems.Item(temp).ToString)

        End Sub

Wait(2) is a subroutine that delay by 2 seconds.

VB error:
An unhandled exception of type 'System.IndexOutOfRangeException' occured in System.Windows.Forms.dll

Additional information: Index was outside the bounds of the array.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Windows 7 WinUSB driver issue
« Reply #6 on: March 26, 2012, 11:39:42 pm »
The application uses a Delegate and the BeginInvoke and EndInvoke methods to read data asynchronously, so the application's main thread doesn't have to wait for the device to return data. A callback routine uses marshaling to send data to the form, whose code runs in a different thread.

See the GetReceivedBulkData routine to see how to put received data on the form.

Jan


lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Windows 7 WinUSB driver issue
« Reply #7 on: April 03, 2012, 10:18:05 am »
I have a question about the UI. When I added in a button to the frmMain, it appearance is different when I generated the .exe. What I have to change?

I noticed that the font, style and etc not the same as what I designed in the frmMain.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Windows 7 WinUSB driver issue
« Reply #8 on: April 03, 2012, 12:22:18 pm »

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Windows 7 WinUSB driver issue
« Reply #9 on: April 08, 2012, 10:37:17 pm »
When I read the data from the uController using ReadDataViaBulkTransfer, error may occur where "The attempt to read bulk data has failed."

In my application, I send a command to the microcontroller to erase the contents of an external flash. Upon completed the task, the microcontroller will return a message to the host as "DONE". The problem is the time take for erasing the external flash depends on the flash size.

How should I modify the VB codes such that ReadDataViaBulkTransfer() subroutine will wait for the returned result without using delay? I want the ReadDataViaBulkTransfer() amd GetReceivedBulkData() to wait and display the data automatically upon received?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Windows 7 WinUSB driver issue
« Reply #10 on: April 09, 2012, 09:59:12 am »
My WinUSB example code does this. See the GetReceivedBulkData routine.

Increase pipeTimeout in the InitializeDevice routine.

Jan
« Last Edit: April 09, 2012, 10:00:48 am by Jan Axelson »

lcpoon

  • Frequent Contributor
  • ****
  • Posts: 58
Re: Windows 7 WinUSB driver issue
« Reply #11 on: April 10, 2012, 03:25:26 am »
Increase pipeTimeout works perfectly.

What is the function to query for product and serial number information under device descriptor?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Windows 7 WinUSB driver issue
« Reply #12 on: April 10, 2012, 10:23:02 am »
You could try WinUsb_GetDescriptor.

Jan

ali

  • Member
  • ***
  • Posts: 2
Re: Windows 7 WinUSB driver issue
« Reply #13 on: July 02, 2012, 01:06:12 pm »
Hello
I used example WinUSB Demo code in order to implement USB in my circuit. Works fine in XP but I could not install the driver in Windows 7. 
What will I do for Windows7

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: Windows 7 WinUSB driver issue
« Reply #14 on: July 03, 2012, 01:31:19 am »
Quote
all:
What will I do for Windows7

Does an "Unknown device" appear under "Other Devices" on Device Manager, while the device plugs in to the PC?
Apply the INF file, distributed with her WinUSB host examples, to this "Unknown device".

Tsuneo