4

I'm trying to read the output from a Trimble SPS-361 GPS receiver, which is connected to a Windows 7 machine via USB, using C++ (preferably) or Java. I know people have asked similar questions, but I can't seem to find what I'm looking for. It sounds like libusb is my best bet, is that true? If so, what is a good tutorial/guide/example code?

It sounds like I need to install/write some sort of device-specific driver and then I can read data off the device with C++ through libusb. Is that the general process for reading from a USB or am I confused?

To summarize what I think need (I know I'm all over the place):

  1. An explanation/tutorial of how to communicate with USB's in general
  2. A more specific tutorial/guide/example code of how to read data off a USB device on Windows 7
  3. What exactly is libusb and is it what I am looking for?
1
  • Many USB GPS receivers act as if they're serial ports, precisely so they don't need a custom USB driver
    – MSalters
    Jul 12, 2013 at 7:59

2 Answers 2

5

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

Start with getting all the devices:

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

Enumerate each one until you find what you're looking for:

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

Get the device detail via SetupDiGetInterfaceDeviceDetail... then open a file handle to the device path via CreateFile with GENERIC_READ access... run an DeviceIoControl to get the product string using IOCTL_HID_GET_PRODUCT_STRING. If it's not your device, close up the file CloseHandle. If it is yours, sit in a loop (preferably on a thread) doing a ReadFile and you'll get raw records from the device.

That should get you going...

2
  • +1 Thanks, this is really helpful. I'm guessing The HDEVINFO class and the two SetupDi* methods are from libusb Library? Jul 11, 2013 at 20:35
  • The API is Microsoft's, check out this link for docs on the first method. Also, the example I showed is for "human interface devices"... if your device isn't presenting a HID interface you might need to expand your search into other device types.
    – mark
    Jul 12, 2013 at 13:16
0

Normally a GPS sensor is exposed as a serial port in Windows. There is no need do specific USB handling.

Simply do serial communication via CreateFile/ReadFile and parse the received GPS NMEA data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.