lundi 7 juillet 2014

How do I specify a serial port in the following python script using sys.argv and serial?


Vote count:

0




I am relatively new to python, and am trying to specify a bluetooth serial port to be used with a script I obtained from GitHub (http://ift.tt/1oCHfi8). I am on a mac and want to specify a bluetooth device whose port looks like this: "/dev/tty.XXXX-XXX-XXX". So far all of my attempts result in the "no device specified" error provided by the program. How to I embed my serial port path into this script?



#!/usr/bin/python
import sys, struct, array, time, serial

def wait_for_ack():
ddata = ""
ack = struct.pack('B', 0xff)
while ddata != ack:
ddata = ser.read(1)
return

if len(sys.argv) < 2:
print "no device specified"
print "You need to specifiy the serial port of the shimmer you wish to connect to"
print "example:"
print " getBtStreamVersion.py Com5"
print " or"
print " getBtStreamVersion.py /dev/rfcomm0"

print
else:
ser = serial.Serial(sys.argv[1], 115200)
ser.flushInput()


Thanks for your help and sharing your expertise!



asked 31 secs ago






Aucun commentaire:

Enregistrer un commentaire