Communication with OpenPNP through python socket

45 views
Skip to first unread message

Moussa Valipour

unread,
May 10, 2022, 8:13:27 AM5/10/22
to OpenPnP
Hello everyone
I want to communicate with OpenPNP software through python socket library. my goal is to create simple motion controller to connect Gcodedriver to my machine.
In openPNP machine setup > driver > configuration > communication type I selected TCP/IP and set the IP to 127.0.0.1 and port to 65432
Screenshot from 2022-05-10 10-00-22.png
On the other hand, I wrote a simple script to create a server socket. when I run the echo_server.py script which is attached, and click the green bottom(start machine) the connection between openPNP and python script will establish.
 
Screenshot from 2022-05-10 10-16-12.png

In openPNP machine setup > driver > console  I send a command for example G21 to the script and I can get it and print it on terminal. Then I send "ok" to the openPNP to confirm that I get a command.
My problem is here. I don't know why openPNP don't get my confirm command ( "ok") in order to complete G21 command.
I did Machine Setup based on OpenPNP user manual which is in git hub. I set the COMMAND_CONFIRM_REGEX to default that is ^ok.*
I would really appreciate if anyone help me.
Mousa
echo_server.py

Ian Arkver

unread,
May 10, 2022, 9:25:24 AM5/10/22
to OpenPnP
Hi. Try adding a newline after the ok (i.e. b"ok\n"). You probably are sending the ok but OpenPnP will be waiting for the \n.

Also, once you get further in you might want separate reader and writer threads otherwise your loop will block in the recv. You might get away without this if you never need unsolicited output.

Regards,
Ian
Reply all
Reply to author
Forward
0 new messages