Yes, that is a simple version of what I need. Thanks your sample is helpful and gives me some additional ideas for how to do things. Using Chris's links I've managed to create something that does almost everything that I need although I still have to add a CRC calculation for the output messages and finish the Arduino code. My main challenge has been the undocumented usage of halcmd with PathPilot's GUI!
-----Original Message----- From: Ernesto Lo Valvo <[email protected]> Sent: December 11, 2020 11:06 AM To: [email protected] Subject: Re: [Emc-users] Sample code On Tue, Dec 8, 2020 at 7:53 AM <[email protected]> wrote: > I am attempting to produce a Python component which periodically > outputs X/Y/Z/A coordinates via a serial port that is actually a USB connection. > This is similar to what is required for pendants that display the > current coordinates. Can anyone suggest a tutorial or source code that > could be adapted to my needs? > > I have looked at > http://linuxcnc.org/docs/html/man/man1/xhc-hb04.1.html > but > I'm hoping for something simpler and a little easier to adapt to Python. > I have made something similar to what you ask between a Raspberry and an Arduino board with a 16x2 LCD display. The Python program that runs on the Raspberry is this: ------ import linuxcnc import serial, time ser = serial.Serial('/dev/ttyUSB0') # open serial port data = linuxcnc.stat() try: while True: data.poll() x=data.actual_position[0]-data.g5x_offset[0] y=data.actual_position[1]-data.g5x_offset[1] z=data.actual_position[2]-data.g5x_offset[2] a=data.actual_position[3]-data.g5x_offset[3] r0=("X{x:5.2f} Y{y:5.2f}".format(x=x,y=y)) r1=("Z{z:5.2f} A{a:5.2f}".format(z=z,a=a)) ser.write(r0.encode('utf-8')+'%') ser.write(r1.encode('utf-8')+'%') time.sleep(.05) except KeyboardInterrupt: ser.close() ------ The Arduino program is this: ------ /* [email protected] @ 2020 */ #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x3F, 16, 2); char riga=0; void setup() { Serial.begin(9600); while (!Serial) ; Serial.print("Avvio"); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Avvio"); } void loop() { while(Serial.available()) { inputString=Serial.readStringUntil('%'); Serial.println(inputString); lcd.setCursor(0, riga); lcd.print(inputString); riga = 1-riga; } } ------ I used the '%' character to signal the newline which was giving me some trouble. Let me know if that's what you were looking for. Ernesto Lo Valvo -- From: Prof. Ernesto Lo Valvo Dipartimento di Architettura Universita' di Palermo Viale delle Scienze 90128 Palermo (Italy) Tel: +39-091-23861845 (direct) _______________________________________________ Emc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-users _______________________________________________ Emc-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/emc-users
