本文整理汇总了Python中serial_manager.SerialManager.read_to方法的典型用法代码示例。如果您正苦于以下问题:Python SerialManager.read_to方法的具体用法?Python SerialManager.read_to怎么用?Python SerialManager.read_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类serial_manager.SerialManager
的用法示例。
在下文中一共展示了SerialManager.read_to方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkErr
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import read_to [as 别名]
def checkErr(* flag):
for index in range(len(flag)):
if flag[index] != 0:
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write('O000'+'\r'):
relayStatus=SerialManager.read_to('\r')
print 'relay status is:',relayStatus
示例2: serialProcessor
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import read_to [as 别名]
def serialProcessor():
global quitFlag
RelayStatus=0
'''
process serial command and send response.
'V' // UART-command for receiving
'T' //UART-command for read temperature
'F' //UART-command for read flag
'R' //UART-command for read total voltage
'I' //UART-command for read total current
'C' //UART-command for close the relay
'O' //UART-command for open the relay
'P' //UART-command for receiving the PWM rate
'J' //UART-command for read time
'K' //UART-command for kill the simulation
'''
while True:
try:
chars = SerialManager.read_to('\r')
if len(chars) > 0:
print('Processing Command:' + chars)
stackNum = int(chars[1])
cellNum = int(chars[2:4])
#cellNum=int(chars[2])*10 + int(chars[3])
index = stackNum*tm.NumberOfCells+cellNum
#print "stackNum %d, cellNum %d, index %d" %(stackNum,cellNum,index)
if chars[0] == 'V':
SerialManager.write(str(tm.status['voltageList'][index])+ '\r')
elif chars[0] == 'B':
tm.bg[index].balanceRate = 1.0 * int(chars[4:])/100.0
#print 'balcenRate is:', tm.bg[index].balanceRate
elif chars[0] == 'T':
SerialManager.write(str(0)+ '\r')
elif chars[0] == 'R':
totalVoltage=sum(tm.status['voltageList'][:])
SerialManager.write(str(totalVoltage)+ '\r')
elif chars[0] == 'I':
totalCurrent=sum(tm.status['voltageList'][:])/tm.load
SerialManager.write(str(totalCurrent)+ '\r')
elif chars[0] == 'C':
RelayStatus=1
SerialManager.write(str(RelayStatus)+ '\r')
elif chars[0] == 'O':
RelayStatus=0
SerialManager.write(str(RelayStatus)+ '\r')
elif chars[0] == 'J':
SerialManager.write(str(tm.clock)+ '\r')
elif chars[0] == 'K':
quitFlag = True
else:
print 'Command Not Defined'
SerialManager.write('Command Not Defined'+ '\r')
time.sleep(0.08)
except:
print("error when processing command")
time.sleep(0.1)
示例3: sendCommand
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import read_to [as 别名]
def sendCommand(command):
#clear rx_buffer
SerialManager.read_existing()
if SerialManager.write(command + '\r'):
return SerialManager.read_to('\r')
else:
return 'error'
示例4: stopBalancing
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import read_to [as 别名]
def stopBalancing(stackNum,cellNum):
balanceCommand='S'+str(stackNum)+str(cellNum)
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write( balanceCommand +'\r'):
balanceStopTime=SerialManager.read_to('\r')
print 'balance stop time is:',balanceStopTime
示例5: commandGenerator
# 需要导入模块: from serial_manager import SerialManager [as 别名]
# 或者: from serial_manager.SerialManager import read_to [as 别名]
print 'balance stop time is:',balanceStopTime
if __name__ == '__main__':
#if not SERIAL_PORT:
# SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
commandGenerator();
flag=[]
voltage=[]
temperature=[]
relayStatus=0
SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
#while SerialManager.is_connected():
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write('C000'+'\r'):
relayStatus=SerialManager.read_to('\r')
print 'relay status is:',relayStatus
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write('R000'+'\r'):
totalVoltage=SerialManager.read_to('\r')
print 'total voltage is:',totalVoltage
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write('I000'+'\r'):
totalCurrent=SerialManager.read_to('\r')
print 'total current is:', totalCurrent
SerialManager.read_existing() #clear rx_buffer
if SerialManager.write('F800'+'\r'):
readCellFlagStatus=SerialManager.read_to('\r')