Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Serial Communication with a Garmin Device

Serial Communication with a Garmin Device

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++sharepointtutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dinesh_pam
    wrote on last edited by
    #1

    Hi, am new to MS VC++, and I need to interface a PC to a handeheld GPS device (Garmin etrex). Am using a serial to USB cable, and I can connect using hyperterminal so HW is ok. However, when I try to use some example code supplied on the Garmin website, I cant connect! The relevant code fragment is (I believe): HDEVINFO theDevInfo = SetupDiGetClassDevs((GUID*) &GUID_DEVINTERFACE_GRMNUSB, NULL, NULL, DIGCF_ALLCLASSES ); SP_DEVICE_INTERFACE_DATA theInterfaceData; theInterfaceData.cbSize = sizeof( theInterfaceData ); if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) && GetLastError() == ERROR_NO_MORE_ITEMS ) { gHandle = 0; return; } -------------- Garmin tech support wont help and any help would be GREATLY appreciated :confused: Thanks! Dinesh

    C K L 3 Replies Last reply
    0
    • D dinesh_pam

      Hi, am new to MS VC++, and I need to interface a PC to a handeheld GPS device (Garmin etrex). Am using a serial to USB cable, and I can connect using hyperterminal so HW is ok. However, when I try to use some example code supplied on the Garmin website, I cant connect! The relevant code fragment is (I believe): HDEVINFO theDevInfo = SetupDiGetClassDevs((GUID*) &GUID_DEVINTERFACE_GRMNUSB, NULL, NULL, DIGCF_ALLCLASSES ); SP_DEVICE_INTERFACE_DATA theInterfaceData; theInterfaceData.cbSize = sizeof( theInterfaceData ); if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) && GetLastError() == ERROR_NO_MORE_ITEMS ) { gHandle = 0; return; } -------------- Garmin tech support wont help and any help would be GREATLY appreciated :confused: Thanks! Dinesh

      C Offline
      C Offline
      cppcook
      wrote on last edited by
      #2

      hey man, why do you want to do this? Garmin products have features other than navigation? btw, I have a garmin streetpilot i5 and it works very well.:)

      1 Reply Last reply
      0
      • D dinesh_pam

        Hi, am new to MS VC++, and I need to interface a PC to a handeheld GPS device (Garmin etrex). Am using a serial to USB cable, and I can connect using hyperterminal so HW is ok. However, when I try to use some example code supplied on the Garmin website, I cant connect! The relevant code fragment is (I believe): HDEVINFO theDevInfo = SetupDiGetClassDevs((GUID*) &GUID_DEVINTERFACE_GRMNUSB, NULL, NULL, DIGCF_ALLCLASSES ); SP_DEVICE_INTERFACE_DATA theInterfaceData; theInterfaceData.cbSize = sizeof( theInterfaceData ); if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) && GetLastError() == ERROR_NO_MORE_ITEMS ) { gHandle = 0; return; } -------------- Garmin tech support wont help and any help would be GREATLY appreciated :confused: Thanks! Dinesh

        K Offline
        K Offline
        kitty5
        wrote on last edited by
        #3

        dinesh_pam wrote:

        if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) && GetLastError() == ERROR_NO_MORE_ITEMS ) { gHandle = 0; return; }

        In the above try this so see what the error exactly is: // Find the requested interface if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) ) { if(GetLastError()== ERROR_NO_MORE_ITEMS) { printf("**Error: couldn't find device(no more items), (0)\n"); SetupDiDestroyDeviceInfoList(theDevInfo); gHandle = 0; return -1; } else { printf("**Error: couldn't enum device, (%d)\n"), GetLastError()); SetupDiDestroyDeviceInfoList(theDevInfo); gHandle = 0; return -1; } } Kitty5

        D 1 Reply Last reply
        0
        • K kitty5

          dinesh_pam wrote:

          if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) && GetLastError() == ERROR_NO_MORE_ITEMS ) { gHandle = 0; return; }

          In the above try this so see what the error exactly is: // Find the requested interface if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) ) { if(GetLastError()== ERROR_NO_MORE_ITEMS) { printf("**Error: couldn't find device(no more items), (0)\n"); SetupDiDestroyDeviceInfoList(theDevInfo); gHandle = 0; return -1; } else { printf("**Error: couldn't enum device, (%d)\n"), GetLastError()); SetupDiDestroyDeviceInfoList(theDevInfo); gHandle = 0; return -1; } } Kitty5

          D Offline
          D Offline
          dinesh_pam
          wrote on last edited by
          #4

          thank you kindly for the reply. The error is couldnt find device. i.e. "**Error: couldn't find device(no more items), (0)" Is there anyway I could just read the virtual COM port like hyperterminal is doing instead of this? Dinesh

          K 1 Reply Last reply
          0
          • D dinesh_pam

            thank you kindly for the reply. The error is couldnt find device. i.e. "**Error: couldn't find device(no more items), (0)" Is there anyway I could just read the virtual COM port like hyperterminal is doing instead of this? Dinesh

            K Offline
            K Offline
            kitty5
            wrote on last edited by
            #5

            Not quite sure how to:

            dinesh_pam wrote:

            Is there anyway I could just read the virtual COM port like hyperterminal is doing instead of this?

            However: Did you include the file that contains the device's GUID? It's usually a .h file that looks like: #ifdef DEFINE_GUID // The GUID that is used to identify this device's interface // {AF1B231E-1180-420b-8CB6-2ED2A53F9F92} DEFINE_GUID(GUID_DEVINTERFACE_ALTGENERIC, 0xaf1b231e, 0x1180, 0x420b, 0x8c, 0xb6, 0x2e, 0xd2, 0xa5, 0x3f, 0x9f, 0x92); #endif If you don't have a GUID for your device the PC will not be able to create a handle to the device. The handle is what give you the ability to communicate to the device. Also, make sure that you: #include "INITGUID.H" in that GUID .h file. Kitty5

            D 1 Reply Last reply
            0
            • K kitty5

              Not quite sure how to:

              dinesh_pam wrote:

              Is there anyway I could just read the virtual COM port like hyperterminal is doing instead of this?

              However: Did you include the file that contains the device's GUID? It's usually a .h file that looks like: #ifdef DEFINE_GUID // The GUID that is used to identify this device's interface // {AF1B231E-1180-420b-8CB6-2ED2A53F9F92} DEFINE_GUID(GUID_DEVINTERFACE_ALTGENERIC, 0xaf1b231e, 0x1180, 0x420b, 0x8c, 0xb6, 0x2e, 0xd2, 0xa5, 0x3f, 0x9f, 0x92); #endif If you don't have a GUID for your device the PC will not be able to create a handle to the device. The handle is what give you the ability to communicate to the device. Also, make sure that you: #include "INITGUID.H" in that GUID .h file. Kitty5

              D Offline
              D Offline
              dinesh_pam
              wrote on last edited by
              #6

              Thanks, but all that's done further up in the file. I'm really frustrated with this. I find it hard to believe such a simple task can be so complicated.. Anybody else help me out please?:~ Dinesh

              1 Reply Last reply
              0
              • D dinesh_pam

                Hi, am new to MS VC++, and I need to interface a PC to a handeheld GPS device (Garmin etrex). Am using a serial to USB cable, and I can connect using hyperterminal so HW is ok. However, when I try to use some example code supplied on the Garmin website, I cant connect! The relevant code fragment is (I believe): HDEVINFO theDevInfo = SetupDiGetClassDevs((GUID*) &GUID_DEVINTERFACE_GRMNUSB, NULL, NULL, DIGCF_ALLCLASSES ); SP_DEVICE_INTERFACE_DATA theInterfaceData; theInterfaceData.cbSize = sizeof( theInterfaceData ); if( !SetupDiEnumDeviceInterfaces( theDevInfo, NULL, (GUID* &GUID_DEVINTERFACE_GRMNUSB, &theInterfaceData ) && GetLastError() == ERROR_NO_MORE_ITEMS ) { gHandle = 0; return; } -------------- Garmin tech support wont help and any help would be GREATLY appreciated :confused: Thanks! Dinesh

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                Well your call to SetupDiEnumDeviceInterfaces does not have matching parenthesis so something very wrong is there. You are not checking the HDEVINFO return value so you may not even have a valid handle to pass to SetupDiEnumDeviceInterfaces

                HDEVINFO hDevInfoSet = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_ALLCLASSES );
                if( INVALID_HANDLE_VALUE == hDevInfoSet)
                {
                DWORD dwErr = ::GetLastError();
                // display error information or whatever
                }
                else
                { ...}

                You are not initializing the SP_DEVICE_INTERFACE_DATA structure which is probably not a problem but you never know.

                SP_DEVICE_INTERFACE_DATA devInterfaceData = {0};
                devInterfaceData.cbSize = sizeof(devInterfaceData);

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups