Trying to define a serial port to get data.
def init_serial():
print "Found Ports:"
for n,s in scan():
print "%s" % s
print " "
COMNUM = 5 #set you COM port # here
global ser #must be declared in each fxn used
ser = serial.Serial()
ser.baudrate = 4800
ser.port = COMNUM -1#starts at 0, so subtract 1def init_serial():
print "Found Ports:"
for n,s in scan():
print "%s" % s
print " "
I get the foll. error:
%run "C:/Users/Dell/Downloads/lat_lon1.py"
C:\Users\Dell\Downloads\lat_lon1.py:26: SyntaxWarning: name 'ser' is assigned to before global declaration
global ser #must be declared in each fxn used
ValueErrorTraceback (most recent call last)
C:\Users\Dell\Downloads\lat_lon1.py in <module>()
27 ser = serial.Serial()
28 ser.baudrate = 4800
---> 29 ser.port = COMNUM -1#starts at 0, so subtract 1
30
31 ser.timeout = 1 #you must specify a timeout (in seconds) so that the serial port doesn't hang
C:\Users\Dell\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\serial\serialutil.pyc in port(self, port)
262 """
263 if port is not None and not isinstance(port, basestring):
--> 264 raise ValueError('"port" must be None or a string, not {}'.format(type(port)))
265 was_open = self.is_open
266 if was_open:
ValueError: "port" must be None or a string, not <type 'int'>
def init_serial():
print "Found Ports:"
for n,s in scan():
print "%s" % s
print " "
COMNUM = 5 #set you COM port # here
global ser #must be declared in each fxn used
ser = serial.Serial()
ser.baudrate = 4800
ser.port = COMNUM -1#starts at 0, so subtract 1def init_serial():
print "Found Ports:"
for n,s in scan():
print "%s" % s
print " "
I get the foll. error:
%run "C:/Users/Dell/Downloads/lat_lon1.py"
C:\Users\Dell\Downloads\lat_lon1.py:26: SyntaxWarning: name 'ser' is assigned to before global declaration
global ser #must be declared in each fxn used
ValueErrorTraceback (most recent call last)
C:\Users\Dell\Downloads\lat_lon1.py in <module>()
27 ser = serial.Serial()
28 ser.baudrate = 4800
---> 29 ser.port = COMNUM -1#starts at 0, so subtract 1
30
31 ser.timeout = 1 #you must specify a timeout (in seconds) so that the serial port doesn't hang
C:\Users\Dell\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\serial\serialutil.pyc in port(self, port)
262 """
263 if port is not None and not isinstance(port, basestring):
--> 264 raise ValueError('"port" must be None or a string, not {}'.format(type(port)))
265 was_open = self.is_open
266 if was_open:
ValueError: "port" must be None or a string, not <type 'int'>