Reading data from USB using C ++ in Windows 7

I am trying to read the output of a Trimble SPS-361 GPS receiver that connects to a Windows 7 computer via USB using C ++ (preferably) or Java . I know that people have asked similar questions, but I can’t find what I’m looking for. Looks like libusb is my best bet, is that true? If so, what is a good tutorial / guide / sample code?

It looks like I need to install / write some kind of driver for a specific device, and then I can read data from the device using C ++ via libusb. Is this a general USB reading process or am I confused?

To summarize what seems necessary to me (I know that I am everywhere):

  • Explanation / tutorial on how to communicate with USB in general
  • More specific tutorial / guide / sample code for reading data from a USB device in Windows 7
  • What is libusb and is this what I'm looking for?
+4
source share
2 answers

Well, if you need raw data from a device, you can find it in the list of USB devices and literally read from it like a file.

Start by getting all the devices:

HDEVINFO hDevInfo = SetupDiGetClassDevs( &HIDWatch::GUID_DEVINTERFACE_HID, 0, 0, DIGCF_DEVICEINTERFACE ); 

List everything until you find what you are looking for:

 SetupDiEnumInterfaceDevice( hDevInfo, NULL, &HIDWatch::GUID_DEVINTERFACE_HID, index++, &InterfaceInfoData ) 

Get the device part through SetupDiGetInterfaceDeviceDetail ... then open the file descriptor on the device path via CreateFile using GENERIC_READ access ... run DeviceIoControl to get the product line using IOCTL_HID_GET_PRODUCT_STRING . If this is not your device, close the CloseHandle file. If it belongs to you, sit in a loop (preferably in a stream), making a ReadFile , and you will receive raw records from the device.

That should make you ...

+4
source

Usually, the GPS sensor appears as a serial port in Windows. No special USB processing required.

Just do serial communication through CreateFile / ReadFile and analyze the received GPS NMEA data.

0
source

Source: https://habr.com/ru/post/1490966/


All Articles