Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 Support, PM5 Bug Fix, and Updated Readme #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ PyRow is python code that allows one to interact with a Concept 2 Rowing Ergomet

For an explanation of the csafe commands please use the following documentation:

- [Concept2 PM Communication Interface Definition](http://www.concept2.com/service/software/software-development-kit)
- [Concept2 PM Communication Interface Definition](https://www.concept2.com/files/pdf/us/monitors/PM5_CSAFECommunicationDefinition.pdf)

_Need to download the SDK to get the document_

- [Communications Specification for Fitness Equipment](http://www.fitlinxx.com/CSAFE/)
- [Communications Specification for Fitness Equipment](https://web.archive.org/web/20080614002257/http://www.fitlinxx.com/CSAFE/)

Site: http://www.newhavenrowingclub.org/pyrow/

Expand All @@ -26,7 +24,7 @@ Licensed under the Simplified BSD License.

PyRow has been tested on an Ubuntu machine with the software versions listed below, PyRow should be able to work on any machine that can run Python & PyUSB but this has not been tested and confirmed.

- [Python](http://python.org/) (Tested with 2.7.2)
- [Python](http://python.org/)
- [libusb](http://www.libusb.org/)

sudo apt-get install libudev-dev libusb-dev python
Expand Down Expand Up @@ -169,8 +167,8 @@ ex: getting pace and printing it out

command = ['CSAFE_GETPACE_CMD',]
result = erg.send(command)
print "Stroke Pace = " + str(result['CSAFE_GETPACE_CMD'][0])
print "Stroke Units = " + str(result['CSAFE_GETPACE_CMD'][1])
print("Stroke Pace = " + str(result['CSAFE_GETPACE_CMD'][0]))
print("Stroke Units = " + str(result['CSAFE_GETPACE_CMD'][1]))
Comment on lines -172 to +171

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and all the print() fixes are already fixed in Py3Row


## FILES

Expand Down
25 changes: 13 additions & 12 deletions csafe_cmd.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#ToDo: change print statments to proper errors
#ToDo: change print() calls to proper errors
import csafe_dic

def __int2bytes(numbytes, integer):
if not 0 <= integer <= 2 ** (8 * numbytes):
print "Integer is outside the allowable range"
print("Integer is outside the allowable range")

byte = []
for k in range(numbytes):
Expand Down Expand Up @@ -122,24 +122,25 @@ def write(arguments):

#check for frame size (96 bytes)
if len(message) > 96:
print "Message is too long: " + len(message)
print("Message is too long: " + len(message))

#report IDs
maxmessage = max(len(message) + 1, maxresponse)

if maxmessage <= 21:
message.insert(0, 0x01)
message += [0] * (21 - len(message))
elif maxmessage <= 63:
message.insert(0, 0x04)
message += [0] * (63 - len(message))
## see https://github.com/wemakewaves/PyRow/issues/5
#elif maxmessage <= 63:
# message.insert(0, 0x04)
# message += [0] * (63 - len(message))
Comment on lines -133 to +136

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change (i.e. just the commit this was in) can be straight up cherry picked onto the py3row codebase with no merge conflicts

Thanks for keeping the commits organized and separated btw!

elif (len(message) + 1) <= 121:
message.insert(0, 0x02)
message += [0] * (121 - len(message))
if maxresponse > 121:
print "Response may be too long to recieve. Max possible length " + str(maxresponse)
print("Response may be too long to recieve. Max possible length " + str(maxresponse))
else:
print "Message too long. Message length " + str(len(message))
print("Message too long. Message length " + str(len(message)))
message = []

return message
Expand All @@ -164,7 +165,7 @@ def __check_message(message):

#checks checksum
if checksum != 0:
print "Checksum error"
print("Checksum error")
return []

#remove checksum from end of message
Expand All @@ -188,7 +189,7 @@ def read(transmission):
elif startflag == csafe_dic.Standard_Frame_Start_Flag:
j = 2
else:
print "No Start Flag found."
print("No Start Flag found.")
return []

while j < len(transmission):
Expand All @@ -199,7 +200,7 @@ def read(transmission):
j += 1

if not stopfound:
print "No Stop Flag found."
print("No Stop Flag found.")
return []

message = __check_message(message)
Expand Down Expand Up @@ -247,7 +248,7 @@ def read(transmission):

#checking that the recieved data byte is the expected length, sanity check
if abs(sum(msgprop[1])) != 0 and bytecount != abs(sum(msgprop[1])):
print "Warning: bytecount is an unexpected length"
print("Warning: bytecount is an unexpected length")

#extract values
for numbytes in msgprop[1]:
Expand Down
6 changes: 3 additions & 3 deletions pyrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def __init__(self, erg):
if erg.is_kernel_driver_active(INTERFACE):
erg.detach_kernel_driver(INTERFACE)
else:
print "DEBUG: usb kernel driver not on " + sys.platform
print("DEBUG: usb kernel driver not on " + sys.platform)
except:
print "EXCEPTION"
print("EXCEPTION")

#Claim interface (Needs Testing To See If Necessary)
usb.util.claim_interface(erg, INTERFACE)
Expand Down Expand Up @@ -116,7 +116,7 @@ def get_force_plot(self):
results = self.send(command)

forceplot = {}
datapoints = results['CSAFE_PM_GET_FORCEPLOTDATA'][0] / 2
datapoints = results['CSAFE_PM_GET_FORCEPLOTDATA'][0] // 2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has already been fixed in Py3Row so no need to port it over

forceplot['forceplot'] = results['CSAFE_PM_GET_FORCEPLOTDATA'][1:(datapoints+1)]
forceplot['strokestate'] = results['CSAFE_PM_GET_STROKESTATE'][0]

Expand Down
8 changes: 4 additions & 4 deletions statshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if len(ergs) == 0:
exit("No ergs found.")
erg = pyrow.pyrow(ergs[0])
print "Connected to erg."
print("Connected to erg.")

#Create a dictionary of the different status states
state = ['Error', 'Ready', 'Idle', 'Have ID', 'N/A', 'In Use',
Expand Down Expand Up @@ -35,11 +35,11 @@
results = erg.send(command)
if cstate != (results['CSAFE_GETSTATUS_CMD'][0] & 0xF):
cstate = results['CSAFE_GETSTATUS_CMD'][0] & 0xF
print "State " + str(cstate) + ": " + state[cstate]
print("State " + str(cstate) + ": " + state[cstate])
if cstroke != results['CSAFE_PM_GET_STROKESTATE'][0]:
cstroke = results['CSAFE_PM_GET_STROKESTATE'][0]
print "Stroke " + str(cstroke) + ": " + stroke[cstroke]
print("Stroke " + str(cstroke) + ": " + stroke[cstroke])
if cworkout != results['CSAFE_PM_GET_WORKOUTSTATE'][0]:
cworkout = results['CSAFE_PM_GET_WORKOUTSTATE'][0]
print "Workout " + str(cworkout) + ": " + workout[cworkout]
print("Workout " + str(cworkout) + ": " + workout[cworkout])
time.sleep(1)
8 changes: 4 additions & 4 deletions strokelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
exit("No ergs found.")

erg = pyrow.pyrow(ergs[0])
print "Connected to erg."
print("Connected to erg.")

#Open and prepare file
write_file = open('workout.csv', 'w')
write_file.write('Time, Distance, SPM, Pace, Force Plot\n')

#Loop until workout has begun
workout = erg.get_workout()
print "Waiting for workout to start ..."
print("Waiting for workout to start ...")
while workout['state'] == 0:
time.sleep(1)
workout = erg.get_workout()
print "Workout has begun"
print("Workout has begun")

#Loop until workout ends
while workout['state'] == 1:
Expand Down Expand Up @@ -57,4 +57,4 @@
workout = erg.get_workout()

write_file.close()
print "Workout has ended"
print("Workout has ended")