def setDeviceID(dev, id):
if id < 0 or id > 255:
raise ValueError("ID must be an unsigned byte!")
try:
com = serial.Serial(dev, timeout=5)
packet = DriverSerial._generateHeader(CMDTYPE.SETID, 1)
packet.append(id)
com.write(packet)
resp = com.read(1)
if len(resp) == 0:
DriverSerial._comError()
else:
if ord(resp) != RETURN_CODES.SUCCESS:
DriverSerial._printError(ord(resp))
except serial.SerialException:
log.error("Problem connecting to serial device.")
raise IOError("Problem connecting to serial device.")
评论列表
文章目录