Headless/No HMI w/Python module, can stream data or only poll?

More
04 Dec 2023 18:35 - 04 Dec 2023 18:35 #287210 by kyleh
I'd like to remotely control and stream data from LinuxCNC preferably with Python. Seems like I could run an API (e.g. Flask/FastAPI) on the LinuxCNC comp that creates access to the LinuxCNC python control features and streams the "outs" via WebSockets, allowing a remote HMI set up however I want. Glancing through the docs however it looks like the python module is set up for polling things like machine position, sensor states, etc. 

Is there some interface where I can access/subscribe to a stream of the machine's outputs as they are updated, or a place where I can see how PyVCP and similar access this data? 
Last edit: 04 Dec 2023 18:35 by kyleh.

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

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
04 Dec 2023 22:43 #287224 by tommylight

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

More
05 Dec 2023 13:55 - 05 Dec 2023 14:10 #287274 by kyleh

linuxcnc.org/docs/html/man/man1/linuxcncrsh.1.html
 

Thanks, this looks focused on headless communication but still seems to be primarily "poll" based requiring Get <emc command> rather than a stream of sensor/position data. I could certainly poll every N ms, but it seems better to understand how the VCPs get their stream of data (i.e. do they also constantly poll?) then push that data where it needs to go every 100ms rather than handle potential 4+ clients all making 50ms polls.

It looks like from the source and examples the <halpin> XML tag can receive this data, so I'll review the docs on HAL pins and see if I can get it. 

EDIT: Oops, I wouldnt need 4+ polling, just one locally that then pushes it however often I want. 

It looks like the HAL pin states are what I want, so I'll dig into the HAL docs and try to learn some more fundamentals there. Appreciate the reply. 
Last edit: 05 Dec 2023 14:10 by kyleh.
The following user(s) said Thank You: tommylight

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

More
05 Dec 2023 14:29 #287276 by JacobRush
I've never written anything of substance in python but trolling through the linuxcnc github it looks like this might be a place to start?
github.com/LinuxCNC/linuxcnc/blob/master...ython/linux_event.py

Also you could try reading through the source code of various interfaces (axis, gmoccapy etc) to see how they implement reading the machine state and updating their interfaces. I think you'll find at some level its polling the state periodically.

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

  • Aciera
  • Aciera's Avatar
  • Away
  • Administrator
  • Administrator
More
05 Dec 2023 14:31 #287277 by Aciera

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

More
05 Dec 2023 20:44 #287308 by rodw

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

More
06 Dec 2023 11:06 #287346 by TheRoslyak
OPC UA fully accomplishes all tasks. It's even possible, without creating a database, to make a variable that will remember readings over time. (Say, 10,000 points per hour). There is also a library for working with Python. You can use it to create your own client.

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

More
06 Dec 2023 11:43 - 06 Dec 2023 11:43 #287348 by TheRoslyak
If you need to create buttons for local use, you need to scan the HAL environment using the rtapi_mutex_get() function. Then, by name or other parameters, find the address of the pin, signal, or parameter you need. This address can be used for a button, for recording in a database, or for displaying on a graph. Perhaps OPC UA history can record data faster than 50 milliseconds, but I haven't tried it.
Last edit: 06 Dec 2023 11:43 by TheRoslyak.

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

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
21 Dec 2023 13:34 #288757 by tommylight
Spammer left...

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

Time to create page: 0.070 seconds
Powered by Kunena Forum