473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Garmin GPS and USB [PyGarUSB package]

Hello,

I am starting this discussion in an effort to get my Garmin GPS to work with pyUSB, and a place to exchange information and code appropriate for this topic.

According to bartonc, in another discussion, Garmin and pyUSB don't work together because of the way Garmin installs in Windows. Can anyone explain why? And is there a workaround for this?

Really, the simplest way to get this to work is to buy another GPS, but I would like to know if this is a battle worth fighting first. I spent $100 on this Garmin so I hope I can make it work.

Any help is greatly appreciated. I will post any code that I find worth sharing.

/Robin
May 1 '07 #1
10 5194
bartonc
6,596 Expert 4TB
Hello,

I am starting this discussion in an effort to get my Garmin GPS to work with pyUSB, and a place to exchange information and code appropriate for this topic.

According to bartonc, in another discussion, Garmin and pyUSB don't work together because of the way Garmin installs in Windows. Can anyone explain why? And is there a workaround for this?

Really, the simplest way to get this to work is to buy another GPS, but I would like to know if this is a battle worth fighting first. I spent $100 on this Garmin so I hope I can make it work.

Any help is greatly appreciated. I will post any code that I find worth sharing.

/Robin
Hi Robin (you can call me Barton). I finished a very solid foundation for my PyGarminUSB package last night. Unforotunately, that machine is not hooked up to internet service at the moment. I'll get it hooked up and attach the zipped package (probably tonight).

It' uses ctypes (2.5 compatable) and a module that used to be part of ctypes which was split off as of verson 1 of ctypes. I think it's called comtypes (for GUID creation). It's may or may not be crutial - you may want to research that.

Keep in touch,
Barton
May 2 '07 #2
bartonc
6,596 Expert 4TB
Hi Robin (you can call me Barton). I finished a very solid foundation for my PyGarminUSB package last night. Unforotunately, that machine is not hooked up to internet service at the moment. I'll get it hooked up and attach the zipped package (probably tonight).

It' uses ctypes (2.5 compatable) and a module that used to be part of ctypes which was split off as of verson 1 of ctypes. I think it's called comtypes (for GUID creation). It's may or may not be crutial - you may want to research that.

Keep in touch,
Barton
You may also want to check out the USBSDK on the Garmin web site. Even if you don't have VS, there is a very useful PDF doc in that downlowd.
May 2 '07 #3
bartonc
6,596 Expert 4TB
You may also want to check out the USBSDK on the Garmin web site. Even if you don't have VS, there is a very useful PDF doc in that downlowd.
One good thing came from a night's delay: The package is that much closer to a final release. My hope in posting this now is that some colaboration may come from the early release and the package will benefit (as well as all future users). So please keep in touch on this one and post any mods/improvements/additions for inclusion in the final release. Thanks so much.

SEE ATTACHMENT <Attachment removed due to out of date modules>
May 3 '07 #4
bartonc
6,596 Expert 4TB
One good thing came from a night's delay: The package is that much closer to a final release. My hope in posting this now is that some colaboration may come from the early release and the package will benefit (as well as all future users). So please keep in touch on this one and post any mods/improvements/additions for inclusion in the final release. Thanks so much.

SEE ATTACHMENT
In particular, I was having difficulty with this section (removed from the PyGarUSB.py file):
Expand|Select|Wrap|Line Numbers
  1.             pyBuffer += self.readBuffer[:nBytesReturned.value]
  2.             # Was this the last packet?
  3.             if nBytesReturned.value < ASYNC_DATA_SIZE:
  4.                 # Yes.
  5.                 ### ctypes.cast() seems to leak memory the way that it is used below ###
  6.                 ### The substitute code on the next 2 lines isn't elegant, but works ###
  7.                 ### For emergency use only ###   The leak seemed to be 4K per call   ###
  8.                 packetID = (UBYTE(pyBuffer[5]).value * 256) + UBYTE(pyBuffer[4]).value
  9.                 thePacket = CreatePacket(UBYTE(pyBuffer[0]).value, packetID,
  10.                                          tuple(pyBuffer[PACKET_STRUCT_SIZE:]))
  11. ##                print thePacket.mPacketId
  12.  
  13. ##                # this gets released #
  14. ##                theBuffer = CreateByteBuffer(pyBuffer)   # Copy py type to C type
  15. ##                # Create a custom pointer just for this instance
  16. ##                # .. so does this #
  17. ##                P_Packet_t = GetPackClassPointer(len(pyBuffer) - PACKET_STRUCT_SIZE)
  18.                 # empty the buffer
  19.                 del pyBuffer[:]
  20. ##                # I don't think that this checks!! #
  21. ##                ## thePacket = (Packet_t*) theBuffer; ##
  22. ##                thePacketPtr = cast(theBuffer, P_Packet_t)
  23. ##                thePacket = thePacketPtr.contents
  24. ##                print theBuffer, thePacketPtr.contents, thePacket
  25. ##                del thePacketPtr, P_Packet_t
  26.                 break
May 4 '07 #5
Barton! I don't know how to thank you properly. It's so awesome that you've takend the time to make this work. Not that I have gotten it to work yet (some includes missing such as win32file), but I am still amazed. I hope I can get it to work soon and undertand it well enough to be of any help in this discussion. Enormously grateful. Thanks!
May 4 '07 #6
bartonc
6,596 Expert 4TB
Barton! I don't know how to thank you properly. It's so awesome that you've takend the time to make this work. Not that I have gotten it to work yet (some includes missing such as win32file), but I am still amazed. I hope I can get it to work soon and undertand it well enough to be of any help in this discussion. Enormously grateful. Thanks!
I'm glad to be giving badk to the Python community in this way and I'm looking forward to your participation.

I made a change in the startup last night. It allows for the device to be unplugged when the GUI is started: The self.hasDeviceInfo variablle is new:
Expand|Select|Wrap|Line Numbers
  1. class GPS_Model:
  2.     """This model of a Garmin GPS provide startup logic (which is almost a direct translation
  3.        of the USBSDK). It is broken into two parts to allow for creating the model without an
  4.        actual connection: Even if EnumDevices() Open() will call __init__()
  5.        . _connect() will open a file handle and init
  6.        the device driver and the USB_Device class for use by ReadPacket() and WritePacket()
  7.     """
  8.     def __del__(self):
  9.         """In case Close() is not called.
  10.         """
  11.         self.Close()
  12.  
  13.     def __init__(self, guid):
  14.         """Calls functions from both SetupAPI dll to get the ball rolling.
  15.         """
  16.         self.guid = guid
  17.         self.devHandle = HANDLE(INVALID_HANDLE_VALUE)
  18.         self.hasDeviceInfo = False
  19.  
  20.         self.usb_device = None
  21.         self.PVTTimeoutTime = 0
  22.         self.PVTStage = 0
  23.  
  24.         # Get a HDEVINFO pointer into OS memory
  25.         theDevInfo = GetClassDevs(byref(guid), None, None,
  26.                                   DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
  27.  
  28.         # Create an Interface data object
  29.         theInterfaceData = SP_DEVICE_INTERFACE_DATA(sizeof(SP_DEVICE_INTERFACE_DATA))
  30.  
  31.         self.theDevInfo = theDevInfo
  32.         self.theInterfaceData = theInterfaceData
  33.  
  34.         # try to connect to the device and fill in the Device Interface Data #
  35. ##        success = self._connect(theDevInfo, guid, theInterfaceData)
  36.         success = EnumDevices(theDevInfo, None, byref(guid), 0, byref(theInterfaceData))
  37.         ## Will fail if there is no device on the buss ##
  38.         if success:
  39.             self.hasDeviceInfo = False
  40.             self._connect(theDevInfo, theInterfaceData)
and in Open():
Expand|Select|Wrap|Line Numbers
  1.     def Open(self):
  2.         """If the file handle is invalid, attempt to open it. Otherwise, send
  3.            a test command to see if Window still thinks that the handle is valid.
  4.            Return True if a conncetion exists.
  5.         """
  6.         if not self.hasDeviceInfo:
  7.             self.__init__(self.guid)
  8.         if self.devHandle.value == INVALID_HANDLE_VALUE:
  9.             try:
  10.                 return self._connect(self.theDevInfo, self.theInterfaceData)
  11.             except (WindowsError, PyGarUSBError):
  12.                 return False
  13.         else:
  14.             try:
  15.                 self.AbortOperation()
  16.                 return True
  17.             except WindowsError:
  18.                 return False
May 4 '07 #7
bartonc
6,596 Expert 4TB
Barton! I don't know how to thank you properly. It's so awesome that you've takend the time to make this work. Not that I have gotten it to work yet (some includes missing such as win32file), but I am still amazed. I hope I can get it to work soon and undertand it well enough to be of any help in this discussion. Enormously grateful. Thanks!
StopBackground seems like a sensible addition to Abort, but I haven't tested it yet.
Expand|Select|Wrap|Line Numbers
  1.  
  2.     def AbortOperation(self):
  3.         """Besides aborting a command, its also handy for testing connectivity because
  4.            it doesn't expect any reply."""
  5.         if not self.usb_device.StopBgRead():
  6.             raise PyGarUSBError("Couldn't stop background task")
  7.         theCmdPacket = CreatePacket(*(L001.Pid_Command_Data + A010.Cmnd_Abort_Transfer))
  8.         self.WritePacket(theCmdPacket)
  9.         return True # No errors occured #
May 4 '07 #8
bartonc
6,596 Expert 4TB
One good thing came from a night's delay: The package is that much closer to a final release. My hope in posting this now is that some colaboration may come from the early release and the package will benefit (as well as all future users). So please keep in touch on this one and post any mods/improvements/additions for inclusion in the final release. Thanks so much.

SEE ATTACHMENT
I just had a look inside that folder. Sorry about the clutter created during testing.
The current files are:
Frame2.py (the View; parent of the Control)
wxGPS.py (the Control)
PyGarUSB.py (the Model)
May 4 '07 #9
Hello Barton
Is your pyGarUSB still somewhere available to download ?
Regards
Joris Peumans
Apr 7 '08 #10
bartonc
6,596 Expert 4TB
I'm sorry that that package has moved out of the public domain.
Apr 13 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
3
by: Petterson Mikael | last post by:
Hi, I have the following package names ( in an xml) that I will transform to html. I need to sort them. <package name="se.company.product.subproduct.boam.fpx.testsignals"> <package...
3
by: shorti | last post by:
running on AIX with DB2 v8.2.2 I ran across a problem with naming source files with similar names. For instance, if I have these three files: upd_startaccessingdb.sqc upd_startusingdb.sqc...
1
by: Joseph Geretz | last post by:
Anyone write code to interface with the Garmin Edge via USB? (Or Forerunner - I think these are pretty much the same.) I'm not looking for real-time GPS feed, but rather I'd like to get the data...
0
by: Skywave | last post by:
Hi All Firstly: I have searched everywhere! I couldn't find anything! Secondly: I am VERY new (1 and a half days) to C#, but I have been doing VB6 and VB.Net for years now. I want to learn C# ! ...
2
by: =?Utf-8?B?Um9iZQ==?= | last post by:
Hi, I need that someone suggest me some library for .NET Framework to create an application that use a Garmin's GPS device. Thanks.
0
debasisdas
by: debasisdas | last post by:
The following thread contains some useful tips/sample codes regarding PACKAGES in oracle, that the forum members may find useful. A package is a collection of procedures,functions,cursors,global...
3
by: borjolujo | last post by:
I want to call Garmin API (http://developer.garmin.com/mobile/mobile-sdk/) in VB.Net Compact Framework project. The API is in C++, so i´m making a C# dll project as intermediate way between API dll...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.