Re: [Emc-users] Debugging Python under LinuxCNC
A bit more information on debugging the Python. When run from the command line with a Python error you get the same information that happens if you run from the desktop. The added advantage is that when it's running correctly you can still get log messages. I've added a print statement and serial write statement in the except KeyboardInterrupt: print("CANSUB: Closing CANUSB") ser.write('C\r'.encode('utf-8')) raise SystemExit And that print now shows up in the terminal screen when LCNC is closed. It does not show up in the two log files: /home/pi/linuxcnc_print.txt /home/pi/linuxcnc_debug.txt My python program also sends out, once per minute, an 'F' command to the CANUSB to request/reset error flags for detecting things like bus and buffer errors. h.newpin("CANUSB_Flags", hal.HAL_U32, hal.HAL_OUT) I read this in LinuxCNC as h.CANUSB_Flags. If there is an error it remains for 1 minute until the next 'F' command. Don't know how to throw up a dialog box if the value is non-zero but probably should. Maybe also want this to be an IO pin to send back a request to resend the 'F' to see if the problem is sticky or transient. John > -Original Message- > From: John Dammeyer [mailto:jo...@autoartisans.com] > Sent: September-14-21 1:01 PM > To: 'Enhanced Machine Controller (EMC)' > Subject: Re: [Emc-users] Debugging Python under LinuxCNC > > > From: andy pugh [mailto:bodge...@gmail.com] > > > > On Mon, 13 Sept 2021 at 21:49, John Dammeyer wrote: > > > > > If I add print() statements where would they show up? Or would they at > > > all? > > > > In the terminal, if you start LinuxCNC from the command line. > > Otherwise I fear that they might simply get lost. > > > Thanks Andy, > From the desktop I can enable the start from terminal and leave it active but > it's really hard to cut and paste information from that. > Starting the same command line as the desktop icon but from a terminal gives > he ability to copy to the clipboard. > I then edited the serial-relay.py to remove a comment from in front of a > print statement, re-ran it, and indeed there are the CAN > messages. I've attached a bit of that if anyone is interested they can see > how it's part of the output that occurs when LCNC doesn't > start up correctly. > > Is by chance this information already being logged to some other file > somewhere when not started as a terminal session? > > John > > ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
> From: andy pugh [mailto:bodge...@gmail.com] > > On Mon, 13 Sept 2021 at 21:49, John Dammeyer wrote: > > > If I add print() statements where would they show up? Or would they at all? > > In the terminal, if you start LinuxCNC from the command line. > Otherwise I fear that they might simply get lost. > Thanks Andy, >From the desktop I can enable the start from terminal and leave it active but >it's really hard to cut and paste information from that. Starting the same command line as the desktop icon but from a terminal gives he ability to copy to the clipboard. I then edited the serial-relay.py to remove a comment from in front of a print statement, re-ran it, and indeed there are the CAN messages. I've attached a bit of that if anyone is interested they can see how it's part of the output that occurs when LCNC doesn't start up correctly. Is by chance this information already being logged to some other file somewhere when not started as a terminal session? John pi@linuxcnc:~ $ /usr/bin/linuxcnc '/home/pi/linuxcnc/configs/G3616-Pi4/G3616-Pi4.ini' LINUXCNC - 2.8.2 Machine configuration directory is '/home/pi/linuxcnc/configs/G3616-Pi4' Machine configuration file is 'G3616-Pi4.ini.expanded' Starting LinuxCNC... Found file(REL): ./G3616-Pi4.hal Note: Using POSIX realtime hm2: loading Mesa HostMot2 driver version 0.15 hm2_eth: loading Mesa AnyIO HostMot2 ethernet driver version 0.2 hm2_eth: 192.168.1.121: INFO: Hardware address (MAC): 00:60:1b:12:07:93 hm2_eth: discovered 7I92 hm2/hm2_7i92.0: Low Level init 0.15 hm2/hm2_7i92.0: 34 I/O Pins used: hm2/hm2_7i92.0: IO Pin 000 (P2-01): IOPort hm2/hm2_7i92.0: IO Pin 001 (P2-14): StepGen #5, pin Step (Output) hm2/hm2_7i92.0: IO Pin 002 (P2-02): StepGen #0, pin Step (Output) hm2/hm2_7i92.0: IO Pin 003 (P2-15): IOPort hm2/hm2_7i92.0: IO Pin 004 (P2-03): StepGen #0, pin Direction (Output) hm2/hm2_7i92.0: IO Pin 005 (P2-16): StepGen #5, pin Direction (Output) hm2/hm2_7i92.0: IO Pin 006 (P2-04): StepGen #1, pin Step (Output) hm2/hm2_7i92.0: IO Pin 007 (P2-17): StepGen #4, pin Step (Output) hm2/hm2_7i92.0: IO Pin 008 (P2-05): StepGen #1, pin Direction (Output) hm2/hm2_7i92.0: IO Pin 009 (P2-06): StepGen #2, pin Step (Output) hm2/hm2_7i92.0: IO Pin 010 (P2-07): StepGen #2, pin Direction (Output) hm2/hm2_7i92.0: IO Pin 011 (P2-08): StepGen #3, pin Step (Output) hm2/hm2_7i92.0: IO Pin 012 (P2-09): StepGen #3, pin Direction (Output) hm2/hm2_7i92.0: IO Pin 013 (P2-10): IOPort hm2/hm2_7i92.0: IO Pin 014 (P2-11): IOPort hm2/hm2_7i92.0: IO Pin 015 (P2-12): IOPort hm2/hm2_7i92.0: IO Pin 016 (P2-13): IOPort hm2/hm2_7i92.0: IO Pin 017 (P1-01): IOPort hm2/hm2_7i92.0: IO Pin 018 (P1-14): IOPort hm2/hm2_7i92.0: IO Pin 019 (P1-02): PWMGen #0, pin Out0 (PWM or Up) (Output) hm2/hm2_7i92.0: IO Pin 020 (P1-15): IOPort hm2/hm2_7i92.0: IO Pin 021 (P1-03): IOPort hm2/hm2_7i92.0: IO Pin 022 (P1-16): IOPort hm2/hm2_7i92.0: IO Pin 023 (P1-04): IOPort hm2/hm2_7i92.0: IO Pin 024 (P1-17): IOPort hm2/hm2_7i92.0: IO Pin 025 (P1-05): IOPort hm2/hm2_7i92.0: IO Pin 026 (P1-06): IOPort hm2/hm2_7i92.0: IO Pin 027 (P1-07): IOPort hm2/hm2_7i92.0: IO Pin 028 (P1-08): IOPort hm2/hm2_7i92.0: IO Pin 029 (P1-09): IOPort hm2/hm2_7i92.0: IO Pin 030 (P1-10): IOPort hm2/hm2_7i92.0: IO Pin 031 (P1-11): IOPort hm2/hm2_7i92.0: IO Pin 032 (P1-12): IOPort hm2/hm2_7i92.0: IO Pin 033 (P1-13): IOPort hm2/hm2_7i92.0: registered Found file(REL): ./custom.hal Received CANopen Msg = 718105 Received CANopen Msg = 298701 note: MAXV max: 3.000 units/sec 180.000 units/min note: LJOG max: 3.000 units/sec 180.000 units/min note: LJOG default: 1.000 units/sec 60.000 units/min note: AJOG max: 180.000 units/sec 10800.000 units/min note: AJOG default: 90.000 units/sec 5400.000 units/min Received CANopen Msg = 718105 Received CANopen Msg = 298701 note: jog_order='XYZA' note: jog_invert=set([]) Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 718105 Received CANopen Msg = 298701 Received CANopen Msg = 298701 Received CANopen Msg = 7
Re: [Emc-users] Debugging Python under LinuxCNC
> From: ken.stra...@gmail.com [mailto:ken.stra...@gmail.com] > > Hopefully not to completely hijack this thread but... > > I am working on a project that will use a Pi Pico interfaced to LinuxCNC. > Are there any debugging tools for microPython? > Hi Ken, Not really hijacking. I'm curious. What will your Pi Pico do? How will you interface to LinuxCNC? John ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
Hopefully not to completely hijack this thread but... I am working on a project that will use a Pi Pico interfaced to LinuxCNC. Are there any debugging tools for microPython? -Original Message- From: Fox Mulder Sent: September 14, 2021 1:27 PM To: emc-users@lists.sourceforge.net Subject: Re: [Emc-users] Debugging Python under LinuxCNC That's not true for Python development in general. If you develop a standalone Python program you can use IDEs with all their features like breakpoints and show/edit variable contents etc. :) The problem starts if the python program is called from another program which is not attached to the debugger. In most cases the IDE can't attach to this python instance and therefor can't be used. Debugging like in the old days with print or better a logging system is still the best way. But this is the same for C/C++ or other programs which are executed from another program outside the IDE. Am 14.09.21 um 19:06 schrieb John Dammeyer: > I'm more used to working with program development systems that have breakpoints, allow single stepping through assembly code and examining variable values and even processor registers. Working with Python is like writing in BASIC with the Radio Shack TRS80 home computer. I've gone back to the dark ages... Ciao, Rainer ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
That's not true for Python development in general. If you develop a standalone Python program you can use IDEs with all their features like breakpoints and show/edit variable contents etc. :) The problem starts if the python program is called from another program which is not attached to the debugger. In most cases the IDE can't attach to this python instance and therefor can't be used. Debugging like in the old days with print or better a logging system is still the best way. But this is the same for C/C++ or other programs which are executed from another program outside the IDE. Am 14.09.21 um 19:06 schrieb John Dammeyer: I'm more used to working with program development systems that have breakpoints, allow single stepping through assembly code and examining variable values and even processor registers. Working with Python is like writing in BASIC with the Radio Shack TRS80 home computer. I've gone back to the dark ages... Ciao, Rainer ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
On Tue, 14 Sept 2021 at 19:09, John Dammeyer wrote: > I'm more used to working with program development systems that have > breakpoints, allow single stepping through assembly code and examining > variable values and even processor registers. You can do that in Python. https://realpython.com/python-debugging-pdb/ -- atp "A motorcycle is a bicycle with a pandemonium attachment and is designed for the especial use of mechanical geniuses, daredevils and lunatics." — George Fitch, Atlanta Constitution Newspaper, 1912 ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
> From: andy pugh [mailto:bodge...@gmail.com] > > On Mon, 13 Sept 2021 at 21:49, John Dammeyer wrote: > > > If I add print() statements where would they show up? Or would they at all? > > In the terminal, if you start LinuxCNC from the command line. > Otherwise I fear that they might simply get lost. > > -- Thanks Andy, I thought maybe I was missing some special hot key that would launch a window from within LCNC that then displayed print messages. Like working with the various IDE's for code development that have a window panel for terminal output. I'm more used to working with program development systems that have breakpoints, allow single stepping through assembly code and examining variable values and even processor registers. Working with Python is like writing in BASIC with the Radio Shack TRS80 home computer. I've gone back to the dark ages... However I do have CAN bus communications with the CANUSB functional in both directions to/from the CANOpen device. The next step is to see if I can use socketCAN instead of pySerial since then the component doesn't care if it's a CANUSB on the Pi4 or a HAT using an MCP2515. For the PC it would still have to be USB based but the component remains the same. If anyone is interested I'll post my serial-relays.py program. John Dammeyer ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
On Mon, 13 Sept 2021 at 21:49, John Dammeyer wrote: > If I add print() statements where would they show up? Or would they at all? In the terminal, if you start LinuxCNC from the command line. Otherwise I fear that they might simply get lost. -- atp "A motorcycle is a bicycle with a pandemonium attachment and is designed for the especial use of mechanical geniuses, daredevils and lunatics." — George Fitch, Atlanta Constitution Newspaper, 1912 ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users
Re: [Emc-users] Debugging Python under LinuxCNC
I'll answer part of my own question but it doesn't answer how to debug Python programs launched by LCNC. First of all it's now working! These two lines # Copies of CAN dataRelayImage = 0 # No relays set yet. Mist_PWM = 0# Mister pump motor speed 0 Fan_PWM = 0 # Cooling fan off. Should be: # Copies of CAN data RelayImage = 0 # No relays set yet. Mist_PWM = 0# Mister pump motor speed 0 Fan_PWM = 0 # Cooling fan off. Somehow in editing the new line between the commented line and the RelayImage was deleted. No Error from the Python program to LCNC. Other than that it did nothing. Therefore Send_PDO_2(RelayImage) # Update device relays with default values. The above line failed because RelayImage had not yet been defined. So the question still stands. How to debug a Python program that has the statement import hal If I run ./serial-relays.py I get an error: HAL: ERROR: duplicate component name 'serial-relays' Traceback (most recent call last): File "./serial-relays.py", line 49, in h = hal.component("serial-relays") hal.error Invalid argument Oh and what I did to get there was to replace the CANUSB with a Serial USB dongle and a null modem cable to connect to the COM1: of my PC. Then see what it was sending as text commands using the ser.write() function and where it hung. Thanks John > -Original Message- > From: John Dammeyer [mailto:jo...@autoartisans.com] > Sent: September-13-21 12:46 PM > To: Enhanced Machine Controller (EMC) > Subject: [Emc-users] Debugging Python under LinuxCNC > > The Python program I wrote includes hal. I'm using a Pi4 with LinuxCNC to > test all this. Thonny on the Pi4 will run a similar pySerial > project that doesn't include hal and spits out CAN messages through the > CANUSB so my hardware works. > > The original 'simple' version of serial_relays.py still works. > > However, the latest upgraded serial_relays.py program does not work properly. > I've been commenting out all sorts of stuff but still > no luck. > > How does one get diagnostics from a python program loaded in the hal file as > loadusr -Wn serial-relays ./serial-relays.py > > If I add print() statements where would they show up? Or would they at all? > > Suggestions? > > Thanks > John > > > "ELS! Nothing else works as well for your Lathe" > Automation Artisans Inc. > www dot autoartisans dot com > > > ___ > Emc-users mailing list > Emc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/emc-users ___ Emc-users mailing list Emc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-users