I started a project that seemed simple enough.....but stuck at the very beginning.
Goal:
Send / Receive commands over TCP from a Python program on a PC to an industrial controller.
The test setup was to configure all machines involved and used PuTTY to verify everything is connected and working. All good.
The data is very simple, each command is only a few characters long. I can watch the display on the industrial controller side.
Here is what is have done in PuTTY
?E10 45
>!
>?Q600 10
>MACRO, 45.0
>
The commands start with ?Q or ?E. In this example, I wrote the value of 45 to location 10 and read location 10 to get the value of 45 back.
PuTTY session is RAW.
In Python, I have not been able to send the same commands. I even monitored in Wireshark and it looks like it is sending the right data to the right place but the remote controller system does not recognize the command. No errors.
Test code snippet.....
import socket
import time
# TCP data for remote Controller
ip = "192.168.198.225"
portDprnt = 8080
portData = 2525
addressDprnt = (ip, portDprnt)
addressData = (ip, portData)
HEADER = 60
FORMAT = "utf-8"
# Connect to remote server CNC machine
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as clientData:
clientData.connect(addressData)
# Grab some number of lines of data
for i in range(5):
cncCommand = "?E10 " + str(i+1)
clientData.sendall(cncCommand.encode(FORMAT))
print(cncCommand)
time.sleep(.5)
print("All done")
Trying to send "?E10 1" , "?E10 2",...... through "?E10 5" as a test. No errors, I can see the data on Wireshark yet the controller does nothing. Wireshark looks the same when I manually send the same data over PuTTY.
Guessing I am missing something very minor....maybe an LF or something?