In order to improve my rather poor Python skills I've spent the last day fighting with Python 3 Thonny on my WIN-10 laptop. The issue is the change from Python 2 to 3 to handle extended characters which a small module like the CANUSB has no knowledge of. So dealing with 0x07 (bell character) and 0x0D (CR character) requires strange statements like
# Initialize CANUSB dongle ser.eol = '\r'.encode('utf-8') ser.write('C\r'.encode('utf-8')) # Close first ser.write('F\r'.encode('utf-8')) # Clear Error Flags by reading them ser.write('S5\r'.encode('utf-8')) # set 250kbps ser.write('O\r'.encode('utf-8')) # Open CANUSB for communication. Received data requires the same hoops. Anyway, I think I have a simple character accumulation and parsing program working that now sends a message to toggle an output and moves the CANopen node reporting NMT PRE-OP status into OPERATIONAL a which point it starts sending PDO messages with status. This is not a LinuxCNC Python program. That one works fine setting say MIST COOLANT ON/OFF via the AXIS screen button. This parsing of messages etc is designed to get data back from a CANopen module into LinuxCNC when I move it to the LinuxCNC version. Anyway attached is the output showing the messages and how the module comes on line. I'll post the code when I've ported it to the LinuxCNC version. John Dammeyer > -----Original Message----- > From: John Dammeyer [mailto:jo...@autoartisans.com] > Sent: September-10-21 10:11 AM > To: 'Enhanced Machine Controller (EMC)' > Subject: Re: [Emc-users] Serial Port access > > Hi Andy, > > The output below shows CANopen PDO message #2 (0x300) to ID 0x18, 1 byte, > alternating between 0x01 and 0x00 being issued once > per second. > > pi@raspberrypi:~/projects/python $ python TestSerial.py > Sent CAN message with relay value = t318101 > Sent CAN message with relay value = t318100 > Sent CAN message with relay value = t318101 > Sent CAN message with relay value = t318100 > Sent CAN message with relay value = t318101 > > The little module shown in that photo I posted last time is connected to a > pneumatic valve on Output #1. It clicks ON and OFF once > per second. The code is running as a Python Command line program on a > standard Raspian distro. I'll bring out the Pi4 with > LinuxCNC and take a look at linking into the HAL file. > > IMHO the Python serial is very clumsy for dealing with serial with all the > format and .encode parameters for simple character strings. > The source code is attached. > > John Dammeyer > > > From: andy pugh [mailto:bodge...@gmail.com] > > On Thu, 9 Sept 2021 at 05:31, John Dammeyer < > > <mailto:jo...@autoartisans.com> jo...@autoartisans.com> wrote: > > > I've been reading > > > <http://linuxcnc.org/docs/2.4/html/hal_comp.html> > > > http://linuxcnc.org/docs/2.4/html/hal_comp.html > > > > For this application I think that a Python userspace component using > > Pyserial is probably the easier approach. > > > > <http://linuxcnc.org/docs/2.8/html/hal/halmodule.html> > > http://linuxcnc.org/docs/2.8/html/hal/halmodule.html > > > > -- > > atp
PythonCAN-1.pdf
Description: Adobe PDF document
_______________________________________________ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users