我正在尝试读取串行端口。问题在于脚本有效,但读取命令似乎不尊重参数(2个字节要读(。
。脚本的典型输出(返回函数中的ANS变量" readPosValue"(是:
print(currTime,readPosValue(serPort))
(1517909247.176, '0b11000010110111001110011')
它们显然超过16位。二手脚本:
import time
import struct
import binascii
import serial
ser = serial.Serial(
port='COM2',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
(
def inficonAcquisition(serPort):
try:
while True:
position = readPosValue(serPort)
currTime = time.time()
print(currTime,position)
except KeyboardInterrupt:
serPort.close()
exit()
def readPosValue(serPort):
ans = ''
while serPort.inWaiting() > 0:
ans += serPort.read(2)
return bin(int(binascii.hexlify('ans'), 16))
问题在indewaiting((函数中。在这种读数中不需要。