LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unstable Communication with USB RAW Device

Hi everyone,

 

I am communicating with an HID device. I have already created a NI USB driver for it.

However, i found that the communication is unstable that sometimes my commands sent will get response only after few retries.

 

I hope someone can help me to take a look on my attached code and point out is there anything wrong with the code.

 

Thanks so much.

 

Best regards,

Crystal

0 Kudos
Message 1 of 10
(3,632 Views)

Are the VISA Events a requirement to enable your device to work? In particular, could they be replaced using VISA Read and an appropriate timeout or waiting period? I ask because it seems you're receiving responses, not asynchronous events, and I've recently read that the VISA Events can be problematic.


GCentral
0 Kudos
Message 2 of 10
(3,576 Views)

Hi Cbutcher,

 

Yes. I can only communicate with my device using that method.

My device is a USB Raw device. I have created an NI USB VISA driver for it.

I am constantly getting error from VISA WAIT ON EVENT (Error -1073807339) if i run the code for only once.

I hope there are method for me not running my LabVIEW code in a while loop.

Capture.PNG

 

Best regards,

Crystal

0 Kudos
Message 3 of 10
(3,564 Views)

Well, technically your device is NOT an USB Raw device but an USB HID device. The USB standard does not know a USB Raw device class. NI VISA only supports USB TMC as a device class (and USB COMM but that goes outside of NI VISA, as Windows will capture that and give access to it through its own serial COMM API that the NI VISA ASRL driver accesses) and anything else can MAYBE be made to work with the USB Raw VISA.

USB HID while not very complex does use a few features that NI-VISA USB Raw doesn't really support such as optional non-default endpoints for the interrupt transfer mode. The interrupt transfer mode is implemented in NI VISA through the VISA Event but assumes endpoint 0.

There is somewhere an example of how to make this kind of work with other endpoint values. I believe it is done by setting the bulk endpoint property temporarily to that number but that can have undesired side effects if any other transfer is going on while the interrupt handling is active.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 10
(3,540 Views)

Also, are you sure your HID device needs bulk transfer commands? Usually HID devices use Control transfers to tell them something from the host. There are special VIs in the Interface Specific VISA submenu for USB Control In and Out.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 10
(3,531 Views)

Hi Rolf Kalbermatter,

 

Thank you for the reply.

I think my device needs bulk transfer commands.

 

Attached are the screenshots on Device Monitoring Studio where i sniffed the commands to be sent to device and receive the response from my device. I have sent and received the commands and responses through a 3rd-party command manager software with the device is still on default driver.

Capture.PNGCapture.PNGCapture.PNG

In order to be able to communicate with the HID device through LabVIEW, I have to create a driver using NI-VISA Driver Wizard.

 

There is somewhere an example of how to make this kind of work with other endpoint values.

I would be appreciate if you could show me the method as i couldn't find other example of doing it.

 

Best regards,

Crystal

 

 

0 Kudos
Message 6 of 10
(3,487 Views)

Have you seen this thread and read everything in there? There is much more in there than I could possibly tell you as my information is mostly from lurking on the fora when USB communication is mentioned rather than programming real devices. As to the values for the parameters of the USB Control  functions you would definitely have to read the according USB specs. That's not easy task as those specs tend to be in a somewhat special tech speak with descriptions that seem to be unneccessarily complex and unclear. The other challenge is to find the relevant places in those specs. The entire USB specification is almost a library in its own.

 

As to how to do Interrupt Out in VISA to a specific endpoint, this is what I remembered. But from the pic you show I do not really see such an Interrupt Out transfer, it just seems to me the setup of the Interrupt In link, where the host announces to the device that it is welcome to send interrupt messages and the maximum parameters the host is willing to handle. No actual data seems to be transfered in the Down transaction.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 7 of 10
(3,451 Views)

@rolfk wrote:

Have you seen this thread and read everything in there? There is much more in there than I could possibly tell you as my information is mostly from lurking on the fora when USB communication is mentioned rather than programming real devices. As to the values for the parameters of the USB Control  functions you would definitely have to read the according USB specs. That's not easy task as those specs tend to be in a somewhat special tech speak with descriptions that seem to be unneccessarily complex and unclear. The other challenge is to find the relevant places in those specs. The entire USB specification is almost a library in its own.

 

As to how to do Interrupt Out in VISA to a specific endpoint, this is what I remembered. But from the pic you show I do not really see such an Interrupt Out transfer, it just seems to me the setup of the Interrupt In link, where the host announces to the device that it is welcome to send interrupt messages and the maximum parameters the host is willing to handle. No actual data seems to be transfered in the Down transaction.


Hi Rolf Kalbermatter,

 

Yes i have read and in fact my VI is refer to that post. 

 

Based on the author of that post, using the same method he can received 4 bytes return for each command sent (without a loop). But for my case, i cannot get what i want. I get nothing when i run the VI for the first 10 times. I get the desired result only after the 11th retry.

 

This sounds funny but it happened to my device. The photo i have posted in previous reply is what i get from the device monitoring when the data sending and receiving between the device and pc.

 

 

Best regards,

Crystal

0 Kudos
Message 8 of 10
(3,440 Views)

Hello,

 

as far as i can seen from your screenshot, your device is using Interrupt Transfers - that is what HID devices usually do.

 

Here is a LabVIEW sample project, that you can use to test it: www.hidxplat.com.

 

Best regards,

Sammy

0 Kudos
Message 9 of 10
(3,108 Views)

Bear in mind that the description for what is included in a return packet for a HID can be different for each device. Some devices may have 2 axes, some may have 3 or more, there may be 2 buttons, there can be 16.

 

You have to know what your device is sending back to be able to interface with it. The device descriptor and HID descriptor will tell you what you need to know. Refer to the HID document from the USB Implementers forum to find out more. https://www.usb.org/document-library/device-class-definition-hid-111

 

But a big problem is newer versions of Windows not allowing installation of custom drivers for HIDs. It defaults to its own implementation. Part of the reason I have not continued with such work. It turned out to be very difficult on newer Windows OSes.

0 Kudos
Message 10 of 10
(3,087 Views)