Access Modbus pins directly with Python - doable?

More
10 years 10 months ago #67613 by Simpson36
First Post here. I am a newbee to both Linux and have been working to port a product over from MACH4. I have a PyVCP panel with buttons and other controls that works great for most of the controls, but . . . .

For the last piece of the puzzle, I need Python to have access to read and write the TCP Modbus pins that are set-up by mb2hal on startup.

FWIW, I have done lots of homework on this and searches, tutorials and research has turned up a bunch of related stuff but all having to do with using the GUI and/or over a serial connection. I have also played with the Python interface, which gets all of the info you could want . . except the pins.

If there a way to read/write TCP Modbus pins directly from Python?

Please Log in or Create an account to join the conversation.

  • seb_kuzminsky
  • Administrator
  • Administrator
More
10 years 10 months ago #67619 by seb_kuzminsky
Replied by seb_kuzminsky on topic Access Modbus pins directly with Python - doable?
The best way is to have your python program "import hal" and create its own hal pins, then net those pins to the mb2hal pins you want to access.

Here's an example of a python program that makes hal pins: github.com/jepler/linuxcnc-mirror/blob/m...anger/m61/test-ui.py

And here's the "postgui.hal" config that it runs after creating its pins, to connect the pins to pre-existing hal nets: github.com/jepler/linuxcnc-mirror/blob/m...nger/m61/postgui.hal

Those nets are created by an earlier hal file: github.com/jepler/linuxcnc-mirror/blob/m...ger/m61/core_sim.hal

Hope this helps.

Please Log in or Create an account to join the conversation.

More
10 years 10 months ago #67622 by andypugh
Do you mean that you want to read/set the values of HAL pins?

One way is to write a Python HAL component that creates its own pins, and those can be netted to the HAL pins you want to read/write.

Can you give a bit more detail about what the desired result is?

Please Log in or Create an account to join the conversation.

More
10 years 10 months ago #67646 by Simpson36
Thanks very much for the response!

I have PyVCP panel with a bunch of 'nets' to the mb2hal pins and that works great for the CNC control signals. The need for Python to access existing pins outside of the GUI will be explained in my next post.

Again, thanks for responding!

Please Log in or Create an account to join the conversation.

More
10 years 10 months ago #67648 by Simpson36
I hope this is not seen as 'advertising' and gets bounced, but the best way to explain the task is with a video. I will attempt to link it and if you look here at about 3 minutes in, you will see the communication that I want to use Python/direct access to the pins for.
The process is this:

The pendant has an unlimited number of 'CELs' that contain any CNC command, text, G-code fragment, Macro, parameters, or whatever the user creates. each CEL content is assigned a unique number and kept in a disk file on the CNC computer.

the process, over simplified, is this

1) the user touches a cel on screen, and the pendant loads the item number into a Modbus register and then sends a 'trip' to the CNC via a modbus coil. At this point the CNC also displays an message on the CNC screen stating that a remote command has come in
2) the CNC gets the trip, then reads the item number out of the Modbus register
3) the CNC places this item number on a different modbus register and sends an 'acknowledge' signal (bit) to the pendant on a coil
4) the pendant detects the ack and reads out the item number sent by the CNC and reads the returned item number from the Modbus reg.
5) the pendant compares the item number sent to the item number returned and only if they match it sends an 'OK to proceed' (bit) back to the CNC on yet another coil.
6) the CNC looks up the data for that item number on a disk file and sends the contents to the CNC for execution (or whatever action is indicated).
7) when successfully completed, the CNC sends a last acknowledge to the pendant, again via Modbus
8) the pendant the displays the status (successful, error, or whatever) in text and echos that message number over a Modbus register back to the CNC for display on the CNC screen.

Notice that step 8 is the only one that woud use the GUI. All of the rest are 'invisible' communications between the pendant processor and the Python program via Modbus.

There are some other tasks that require processing (exponential curves for rotary control knobs on the pendant, etc) that require some calculations (including conditional statements) before being sent on to the CNC and that would be a lot to try to stuff into an 'action'. tripped by the GUI pin.

- Steve

Please Log in or Create an account to join the conversation.

More
10 years 10 months ago #67651 by Simpson36
Here is the screen so far. All of the buttons/sliders, etc on the right side PyVCP panel are hooked up and working fine. A lot of data has to go thru conversions and/or other work arounds but this part was pretty easy once I got my brain around how the various pieces fit together ('net' function, ini files and so on.).

I have another thread going about fixing some things in the mb2hal and the C header file has been located and there are instructions from 'Big John' on downloading some development tools. I am familiar with C and compilers (to a degree) , but at this point I have no idea how to go about compiling code for Linux/LinuxCNC or how to contribute and navigate the git stuff.

I am more than happy to help out, but I'll need a project lead (or equiv) to give me specific tasks to do . . . and probably how to do them . . . :blush:

image missing http://www.thecubestudio.com/LinuxCNC/Photos/ScreenshotInTurnLinuxCNC_WEB_R1.jpg

Please Log in or Create an account to join the conversation.

Time to create page: 0.810 seconds
Powered by Kunena Forum