python串口发送数据
Ⅰ 如何用串口工具模拟器向python发送数据
串口模块的波特率比较特别,找了几个串口工具都不支持。。。所以,干脆用python自己来写了,其实已经好奇好久了,别人的工具各种不顺手。
需要pyserial的支持,兼容各种平台,不需要新编译二进制文件。
先贴一个定时发送的代码:
import serial
import time
ser = serial.Serial('/dev/ttyUSB0', 250000, timeout=1)
print ser.isOpen()
words="gggggggggggggggg"
while (1):
print "send 256x\""+words+"\" to remotes"
startTime = time.time()
times = 256
while (times):
times -= 1
s = ser.write(words)
endTime = time.time()
print "use time: "+str(endTime-startTime)
print ""
time.sleep(5)
ser.close()
Ⅱ python中Pyserial如何实现RS485串口通讯
RS485 的数据线要交叉才能通讯,如果你是两台电脑通讯测试,另外一台要有返回才行。就好像你给人家说话,人家听到了重复一遍你才能听到。不然就是单向传输,收不到任何回应。
Ⅲ 如何用python写个串口通信的程序
import serial
# 创建serial实例
serialport = serial.Serial()
serialport.port = 'COM1'
serialport.baudrate = 9600
serialport.parity = 'N'
serialport.bytesize = 8
serialport.stopbits = 1
serialport.timeout = 0.6
try:
serialport.open()
serialport.setDTR(True)
serialport.setRTS(True)
except Exception, ex:
print ex
# 发送数据
serialport.write(raw_data)
# 根据项目要求,可以开一个线程扫描接收数据
Ⅳ python3 socket的send方法如何发送数据
用如下代码:
name='bruce'
s.send(b'hihi'+name.encode())
要把name变成二进制才能拼接
望采纳