Using Python to interface with the PM
Using Python to interface with the PM
I've been working on a python script to allow for easier communication between the computer and the Concept 2 PM. It has been used successfully with a single erg setup but has not been extensively tested. I've included a link below in hope that other people may have some use for it too.
http://www.newhavenrowingclub.org/pyrow/
http://www.newhavenrowingclub.org/pyrow/
Re: Using Python to interface with the PM
I'm stuck at trying to get my system updated with the requirments need to run the script.
I'm using an ubuntu linux machine (after failing harder on a mac) and after installing libusb, pyusb, setting permissions on 'udev' rules, I finally hit the wall with "usb.core.USBError: Resource busy":
I really need some help because I want to do some cool stuff.
I'm using an ubuntu linux machine (after failing harder on a mac) and after installing libusb, pyusb, setting permissions on 'udev' rules, I finally hit the wall with "usb.core.USBError: Resource busy":
Code: Select all
python statshow.py
Traceback (most recent call last):
File "statshow.py", line 18, in <module>
erg = pyrow.pyrow(ergs[0])
File "/home/zaf/tmp/pyrow/pyrow.py", line 32, in __init__
erg.set_configuration() #required to configure USB connection
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 514, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 85, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "/usr/local/lib/python2.7/dist-packages/usb/_debug.py", line 53, in do_trace
return f(*args, **named_args)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 451, in set_configuration
_check(_lib.libusb_set_configuration(dev_handle, config_value))
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 353, in _check
raise USBError(_str_error[retval.value])
usb.core.USBError: Resource busy
Re: Using Python to interface with the PM
Zaf,
After doing some searching around it appears that pyusb may require an extra step when connecting to a device in linux. I've updated the code and reposted it at the above link. I do not have access to a linux machine that could be easily located next to my erg so I have not had a chance to test the new code in linux. If you have a chance please give it a try and let me know how it goes.
After doing some searching around it appears that pyusb may require an extra step when connecting to a device in linux. I've updated the code and reposted it at the above link. I do not have access to a linux machine that could be easily located next to my erg so I have not had a chance to test the new code in linux. If you have a chance please give it a try and let me know how it goes.
Re: Using Python to interface with the PM
Thanks for the reply!
I'm downloading now and testing.
I'm downloading now and testing.
Re: Using Python to interface with the PM
Same error. Heres the dump:
Code: Select all
python statshow.py
Traceback (most recent call last):
File "statshow.py", line 18, in <module>
erg = pyrow.pyrow(ergs[0])
File "/home/zaf/tmp/pyrow/pyrow.py", line 39, in __init__
erg.set_configuration() #required to configure USB connection
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 514, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 85, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "/usr/local/lib/python2.7/dist-packages/usb/_debug.py", line 53, in do_trace
return f(*args, **named_args)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 451, in set_configuration
_check(_lib.libusb_set_configuration(dev_handle, config_value))
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb10.py", line 353, in _check
raise USBError(_str_error[retval.value])
usb.core.USBError: Resource busy
Re: Using Python to interface with the PM
Zaf,
I have a few more theories and ideas as to your usb issues with linux. However I would need some testing and feedback from you in regards to each idea. Instead of flooding Concept 2's forum with trial and error I figured it would make more sense to try working this through email then posting a solution if we find one.
If you're willing please shot me an email at: pyrow [at] newhavenrowingclub [dot] org
I have a few more theories and ideas as to your usb issues with linux. However I would need some testing and feedback from you in regards to each idea. Instead of flooding Concept 2's forum with trial and error I figured it would make more sense to try working this through email then posting a solution if we find one.
If you're willing please shot me an email at: pyrow [at] newhavenrowingclub [dot] org
Re: Using Python to interface with the PM
Email shot 

Re: Using Python to interface with the PM
In case any reads this - we solved the issues and I have a linux machine communicating with the PM3 on the rowing machine using python. And its really cool 
I'd like to thank gambrell for creating the pyrow library and for helping out to get this to work.
Finally, if there is a Concept2 employee reading this, please let your management know that they really need to change the hardware/software on the future PM5 regarding the USB communications with the outside world. It would be less headache for your engineers and developers by using current trends in hardware and software. Seriously, this could determine the success or failure for your future products.

I'd like to thank gambrell for creating the pyrow library and for helping out to get this to work.
Finally, if there is a Concept2 employee reading this, please let your management know that they really need to change the hardware/software on the future PM5 regarding the USB communications with the outside world. It would be less headache for your engineers and developers by using current trends in hardware and software. Seriously, this could determine the success or failure for your future products.
Re: Using Python to interface with the PM
And a thanks from me for the PyRow library - I'm giving it a try on the Raspberry Pi.
Cheers
Chris
Cheers
Chris
Re: Using Python to interface with the PM
May I know how you solve this issue? I've got exactly the same problem and it's a bit frustrating, so close from the goal !zaf wrote:In case any reads this - we solved the issues and I have a linux machine communicating with the PM3 on the rowing machine using python. And its really cool
I'd like to thank gambrell for creating the pyrow library and for helping out to get this to work.
Finally, if there is a Concept2 employee reading this, please let your management know that they really need to change the hardware/software on the future PM5 regarding the USB communications with the outside world. It would be less headache for your engineers and developers by using current trends in hardware and software. Seriously, this could determine the success or failure for your future products.

Re: Using Python to interface with the PM
Hi, All,
I've been waiting years for adevelopment like this. Thanks! I'm having trouble, unfortunately. On my Debian Wheezy machine (Python 2.7.3 with non-Debian pyusb 1.0 installed), I get the following error:
~/pyrow-beta-01-18-2012$ python pyrow.py
File "pyrow.py", line 39
else:
^
SyntaxError: invalid syntax
I don't use python often, so I may be making a stupid mistake. I'd appreciate any suggestions.
Streph
I've been waiting years for adevelopment like this. Thanks! I'm having trouble, unfortunately. On my Debian Wheezy machine (Python 2.7.3 with non-Debian pyusb 1.0 installed), I get the following error:
~/pyrow-beta-01-18-2012$ python pyrow.py
File "pyrow.py", line 39
else:
^
SyntaxError: invalid syntax
I don't use python often, so I may be making a stupid mistake. I'd appreciate any suggestions.
Streph
- Citroen
- SpamTeam
- Posts: 8062
- Joined: March 16th, 2006, 3:28 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Using Python to interface with the PM
Python being an awful language (I hate semantic whitespace) has two active versions (because the entirely stupid developers made python3 so that it is not 100% compatible with python2). When you get inexplicable errors the first thing to do is try it with the other flavour of python. So in this case try python3.
There are words to describe the omnishambles created by the python2 vs python3 debacle, but they are mostly not for use in a family forum.
There are words to describe the omnishambles created by the python2 vs python3 debacle, but they are mostly not for use in a family forum.
Re: Using Python to interface with the PM
Thanks, Citroen,
Unfortunately, I get the same error with python3.
Streph
Unfortunately, I get the same error with python3.
Streph
- Citroen
- SpamTeam
- Posts: 8062
- Joined: March 16th, 2006, 3:28 pm
- Location: A small cave in deepest darkest Basingstoke, UK
Re: Using Python to interface with the PM
Looks like all the python files need to be unmangled with "dos2unix".
Also there's a coding problem in lines 37 through to 43 in pyrow.py.
Here's an untested patch file
Code: Select all
find . -name "*py" | xargs dos2unix
Here's an untested patch file
Code: Select all
--- pyrow.py 2014-02-25 01:13:46.272848657 +0000
+++ pyrow.py~~ 2014-02-25 01:13:44.132615324 +0000
@@ -27,22 +27,24 @@
return ergs
class pyrow:
-
def __init__(this, erg):
#Configures usb connection and sets erg value
-
if sys.platform != 'win32':
try:
#Check to see if driver is attached to kernel (linux)
if erg.is_kernel_driver_active(interface):
erg.detach_kernel_driver(interface)
- else:
- print "DEBUG: usb kernel driver not on " + sys.platform
+ else:
+ print "DEBUG: usb kernel driver not on " + sys.platform
- #Claim interface (Needs Testing To See If Necessary)
+ #Claim interface (Needs Testing To See If Necessary)
+ except:
+ pass
+
usb.util.claim_interface(erg, interface)
#Linux throws error, reason unknown
+
try:
erg.set_configuration() #required to configure USB connection
#Ubuntu Linux returns 'usb.core.USBError: Resource busy' but rest of code still works
Re: Using Python to interface with the PM
Thanks for the patch.
I have statshow.py working now. Enclosing all of the print statements in parentheses got rid of the errors, and I have to run it as root, but it's working! It's exciting to contemplate finally having an interface between my PM3 and a Linux machine.
I have statshow.py working now. Enclosing all of the print statements in parentheses got rid of the errors, and I have to run it as root, but it's working! It's exciting to contemplate finally having an interface between my PM3 and a Linux machine.