Home > Software design >  Why can I open STMicroelectronics STLINK V2 with LibUSB, but not with STMicroelectronics Virutal COM
Why can I open STMicroelectronics STLINK V2 with LibUSB, but not with STMicroelectronics Virutal COM

Time:11-22

I have a LibUSB example in C code and I'm trying trying to connect STMicroelectronics Virtual COM Port and I cannot connect it, even if I have the right Vendor ID and Product ID

But if I'm using my LibUSB example to connect STMicroelectronics STLINK-V2, then I can connect.

Question:

So why can LibUSB not connect to STMicroelectronics Virtual COM Port with LibUSB, but I can connecto at STMicroelectronics STLINK-V2.

When I run this code snippet, device_handle returns NULL because libusb cannot connect when vendorID = 1155, productID = 22336. These numbers are for STMicroelectronics Virtual COM Port.

device_handle = libusb_open_device_with_vid_pid(ctx, vendorID, productID);

Update:

My goal is to connect my PC with my USB device so I can transfer and receive data from that USB device.

My operative system is Windows 11. There is nothing wrong with my USB device. I can connect it using QT C and transfer data to it. But not with libusb, it seems.

Update 2:

My USB device is a CDC - Communication Device Class.

CodePudding user response:

On Windows, libusb cannot connect to just any USB device or interface; it can only connect to USB interfaces that have a specific driver attached to them that enables the kind of raw USB access that libusb needs. One such driver is WinUSB (winusb.sys).

Your virtual serial port device is very likely using a different driver, like usbser.sys. Therefore you cannot connect to it with libusb. However, you could connect to it using the standard serial port functions in the Windows API, specifically: CreateFile, WriteFile, ReadFile, CloseFile, SetCommTimeouts, SetCommState.

  • Related