ID_MSG = "%cIDTCMV001%c" % (MESSAGE_ID_0,1)
WAIT_MSG = "%cIDTWAITPCR" % (MESSAGE_ID_0)
- @staticmethod
- def IsWindows():
- """Return True if windows platform, False if not"""
- if platform.system() == "Windows":
- return True
- return False
-
def __init__(self, uo, serverPort, dataStore, debug):
self.__uo = uo
self.__serverPort = serverPort
s=None
for i in range(255):
try:
- if CM160.IsWindows():
- portname ="\\.\\COM%d" % (i)
- s = serial.Serial(portname)
- else:
- portname = "/dev/ttyUSB" + `i` # bmcm-p1: force portname on linux
- s = serial.Serial(portname)
+ portname = "/dev/ttyUSB" + `i` # bmcm-p1: force portname on linux
+ s = serial.Serial(portname)
s.close()
available.append( (i, s.portstr))
except serial.SerialException as e:
self.__ser = None
try:
- if CM160.IsWindows():
- self.__ser = serial.Serial(self.__serialPortName, 250000, bytesize=8, parity='N', stopbits=1, xonxoff=0, rtscts=0, dsrdtr = 0, timeout=30)
- else:
- #Assume we have the custom cp210x driver loaded that maps the requested baud rate of 0 to a physical port speed of 250000 Bps required
- #for the CM160 device.
- self.__ser = serial.Serial(self.__serialPortName, 0, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30)
-
- sd = self.__ser.getSettingsDict()
- keys = sd.keys()
- for k in keys:
- self.__uo.debug("%s=%s" % (k, sd[k]) )
- self.__uo.info("Opened serial port %s." % (self.__serialPortName) )
+ #Assume we have the custom cp210x driver loaded that maps the requested baud rate of 0 to a physical port speed of 250000 Bps required
+ #for the CM160 device.
+ self.__ser = serial.Serial(self.__serialPortName, 0, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30)
+
+ sd = self.__ser.getSettingsDict()
+ keys = sd.keys()
+ for k in keys:
+ self.__uo.debug("%s=%s" % (k, sd[k]) )
+ self.__uo.info("Opened serial port %s." % (self.__serialPortName) )
except ValueError:
#If we fail to open the serial port with a ValueError then it is probably the baud rate that is the problem
pass
def connectToSerialPort(self, serialPort):
- self.__serialPortName = None
-
- #We need to do things differently on windows :-(
- if CM160.IsWindows():
- self.__serialPortName="\\.\\COM%d" % (serialPort)
- else:
- self.__serialPortName = "/dev/ttyUSB%d" % (serialPort)
+ self.__serialPortName = "/dev/ttyUSB%d" % (serialPort)
#If the serial port will open with the CM160 settings
self.openSerialPort()
serialPort=int(a)
#Validate serial port
- lowSerialPort=0
- if CM160.IsWindows():
- if serialPort == 0:
- raise OWLError("Serial port numbering starts at 1, not 0 on Windows platforms.")
- lowSerialPort=1
-
- if serialPort < lowSerialPort or serialPort > 255:
- raise OWLError("Serial port out of range (%d - 255)." % (lowSerialPort) )
+ if serialPort < 0 or serialPort > 255:
+ raise OWLError("Serial port out of range (0 - 255).")
elif o == "-d":
debug = True