bytes类型和str类型python_%的操作数类型不受支持:“bytes”和“str”

我收到以下行中的错误:command = input("please type command.example open 1")

#call the serial_connection() function

ser.write(b"%d\r\n"%command)

实际上,我希望用户编写输入并将其解析为ser.写入,而不要求输入并直接将字符串放入ser.write中,例如:

^{pr2}$

工作正常,只有当我试图将输入结果用作要包含的字符串时才会出现问题ser.写入在

更多的代码:ser = 0

#Initialize Serial Port

def serial_connection():

COMPORT = int(input("Please enter the port number: "))

ser = serial.Serial()

ser.baudrate = 38400 #Suggested rate in Southco documentation, both locks and program must be at same rate

ser.port = COMPORT - 1 #counter for port name starts at 0

#check to see if port is open or closed

if not ser.isOpen():

print ('The Port %d is open - Will attempt to close lock 1 Stephan: '%COMPORT + ser.portstr)

#timeout in seconds

ser.timeout = 10

ser.open()

command = input("please type command.example open 1")

#call the serial_connection() function

ser.write(b"%d\r\n"%command)

else:

print ('The Port %d is **open** Stephan' %COMPORT)

如有任何澄清,请告知。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值