1

I am trying to start using libusb for communication via COM port ( EDIT: for my Rs232 device), on windows 10 x64 only. My IDE is Code:blocks. I have a couple of questions:

I downloaded libusb from their website (latest windows binaries)

libusb download

But I noticed there is a libusb-win32 ''version'' of it in sourceforge. It says

"libusb-win32 is a port of libusb-0.1 under Windows"

  1. What does this mean, and should I use the "latest windows binaries" version or the "libusb-win32" version?

Also, the Readme file from their website (the 'libusb windows binaries' one) has instructions for compiling in Visual Studio and Mingw and there are files for Visual studio and Mingw only.

  1. Does this means I cannot compile the libusb it in GNU GCC compiler?

EDIT: the question 2) is already answered here: https://stackoverflow.com/a/38252750/13294095

  • What environment are you developing on? – ryyker Jun 10 '21 at 12:12
  • 1
    Windows 10, Code:blocks. Let me add this detail on the question. – Christianidis Vasileios Jun 10 '21 at 12:12
  • 1
    Then the Windows binaries are all you need. You do not need to build them, just include the .dll and .lib in project. – ryyker Jun 10 '21 at 12:18
  • Your question is not clear though, are you interested in compiling the source into your own binaries, or is your interest more pointed toward using existing binaries to start coding? – ryyker Jun 10 '21 at 12:25
  • 1
    My second comment was not exactly correct. If you just want to use the provided binaries from the download, then include .lib and .h into your project, and place the .dll where it will be visible. For development I usually just place the .dll in the same directory as the .exe that will use it. Later it should go into C:\Windows\sysWOW64 if `32bit`, or C:\Windows\System32 for `64bit` – ryyker Jun 10 '21 at 12:31
  • @ryyker So the libusb-win32 are pre-compiled files for windows? I did not figure that out. Thanks. Their website just said "libusb-win32 is a port of the USB library libusb 0.1 " but they did not say that its just pre-compiled binaries, I could not understand what "port"meant there. – Christianidis Vasileios Jun 10 '21 at 12:31
  • 1
    Yes, they are compatible with windows. Look in the examples directory for testlibusb.c. If you have the .lib and .h, installed in project, and .dll is visible, this file should compile without a problem. – ryyker Jun 10 '21 at 12:36
  • 1
    libusb is for USB devices, COM ports are RS-232 devices, so I'm not sure on how you'll use libusb for COM port access. But libusb 1.0.24 builds perfectly fine with MinGW-w64 in MSYS2 shell using `./configure --disable-udev && make` – Brecht Sanders Jun 10 '21 at 12:37
  • @BrechtSanders I am using a RS-232 device (I want to communicate with my microcontroller). I will add this detail to the question as well – Christianidis Vasileios Jun 10 '21 at 12:42
  • Are the com ports you refer to virtual or based on a physical UART device. – ryyker Jun 10 '21 at 12:47
  • 1
    @ChristianidisVasileios if you want serial RS-232 comunication, than why don't you use something like the library at http://www.teuniz.net/RS-232/ instead? – Brecht Sanders Jun 10 '21 at 12:49
  • @ryyker I have a physical uart device after the Rs232, I my MCU. I use the Rs-232 to translate from UART to USB protocol. -Even though I do not know what "Virtual com port" is. – Christianidis Vasileios Jun 10 '21 at 12:51
  • @BrechtSanders I will check it out, thanks – Christianidis Vasileios Jun 10 '21 at 12:52
  • 1
    If you have a device that when you plug it into your PC via a USB port, it instantiates a COM port, then that device does have a UART. The device must also have driver that upon connecting to the PC is installed, and results in establishing the serial port you can see in device manager (under ports) Read about [USB serial driver](https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-driver-installation-based-on-compatible-ids) for some background. – ryyker Jun 10 '21 at 13:02
  • I see. Then as I replied above, my device has UART and its not virtual com port. – Christianidis Vasileios Jun 10 '21 at 13:04
  • 1
    Well, your device may have a UART, but when you plug it into a PC via a USB port, a virtual serial port is created via a driver on the PC... _"When the USB to serial adapter is connected to the computer via the USB port the driver on the computer creates a virtual COM port which shows up in Device Manager on Windows, "_ Read [more here](https://en.wikipedia.org/wiki/USB_adapter). (under Architecture) – ryyker Jun 10 '21 at 13:23
  • Hmm I see. libusb is used to talk to USB, so I might not be able to use it to talk to COM port. – Christianidis Vasileios Jun 10 '21 at 13:31
  • 1
    ...So, it is still unclear to me why you need to use libusb. i.e. if when you plug your device into the PC, you can see a port that has been created in Device Manager, then all the work is done. Your code can use [a C serial port library](https://stackoverflow.com/a/24698145/645128) to open a port and send/receive serial messages, etc. However, if you are _developing_ the device with the UART to work on a Windows PC via a USB port, then yes, you need to create a driver. Maybe then libUSB is for you. – ryyker Jun 10 '21 at 13:32
  • After seeing the comments here I wont use libusb, and you are right, I need to communicate with COM port, not USB, so libusb is useless in this scenario. I will use a C serial port library. Thank you everyone. Some of you should shall post a complete answer based on the question and the comments so I can accept it as correct. – Christianidis Vasileios Jun 10 '21 at 13:46

1 Answers1

1

"I am trying to start using libusb for communication via COM port ( EDIT: for my Rs232 device), on windows 10 x64 only"

If you have a device that when you plug it into your PC via a USB port, it instantiates a COM port, then that device does have a UART. The device must also have driver that upon connecting to the PC is installed, and results in establishing the serial port you can see in device manager (under ports) Read about USB serial driver for some background.

"I have a physical uart device after the Rs232, I my MCU. I use the Rs-232 to translate from UART to USB protocol. -Even though I do not know what "Virtual com port" is."

Your device may have a UART, but when you plug it into a PC via a USB port, a virtual serial port is created via a driver on the PC... "When the USB to serial adapter is connected to the computer via the USB port the driver on the computer creates a virtual COM port which shows up in Device Manager on Windows"... Read more here. (under Architecture)

In short, if when you plug your device into the PC, you can see a port that has been created in Device Manager, then all the work is done. Your application code can incorporate a C serial port library to open a port and send/receive serial messages, etc. However, if you are developing the device with the UART to work on a Windows PC via a USB port, then yes, you need to create a driver. Maybe then libUSB is for you.

ryyker
  • 22,849
  • 3
  • 43
  • 87