以上型号用于Rs485通信。在
实际上我用arduino试过简单的代码。每2秒通过客户端发送串行数据void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("SMCB1,1,1,1,1,2,3,4,5,6,6,7,8,9,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2");
delay(2000);
}
我使用下面的python代码,从客户机1和客户机2接收数据
^{pr2}$
现在我已经上传了Modbus RTU代码,我正在发送请求并尝试获得响应。请求需要以十六进制格式发送。我试过用有线通讯似乎工作得很好。
我分享了下面的请求格式。但我可以阅读任何东西的过程中都会进行阅读import socket
TCP_IP = '192.168.1.3'
TCTCP_IP1='192.168.1.2'
TCP_PORT = 8899
BUFFER_SIZE = 1000
BUFFER_SIZE1=1000
#MESSAGE = "01 03 00 00 00 1d 85 c3"
#MESSAGE1 = "02 03 00 00 00 1d 85 fo"
MESSAGE = "01030000001d85c3"
MESSAGE1 = "02030000001d85fo"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "Before connect"
s.connect((TCP_IP, TCP_PORT))
s1.connect((TCTCP_IP1, TCP_PORT))
print "After connect"
print MESSAGE
print MESSAGE1
print "request before sending"
s.send(MESSAGE1)
s1.send(MESSAGE)
print "request after sending"
data = s.recv(BUFFER_SIZE)
data1= s1.recv(BUFFER_SIZE)
s.close()
s1.close()
print "received data:", data
print "received data:", data1
现在我面临的问题,我试图发送请求,但我无法得到答复。有了有线通讯,我可以得到数据。在