Hello Guest it is May 15, 2021, 07:45:41 PM

Author Topic: Working complex Lua Modules into Mach4  (Read 205 times)

0 Members and 1 Guest are viewing this topic.

Working complex Lua Modules into Mach4
« on: March 11, 2021, 07:35:06 PM »
Hello,

I am trying to figure out a way to communicate DRO values to a computer other than the one that will be running Mach4. The solution that another team member found on her side of the problem is a server that uses the WebSocket protocol on top of vanilla TCP/IP, but I have been having trouble making it work from my end. Mach4 comes with a Lua sockets module that can handle vanilla TCP/IP, but to communicate over a WebSocket I would have to add in a Lua module that someone else made, like lua-websocket or lua-http, or write the thing myself.

I'd like to avoid implementing a communication protocol myself, but the problem with installing lua-websocket or lua-http is that they aren't a set of DLL's and Lua files I can just drop into the Modules directory; they are complicated modules that require compilation and that have a list of dependencies. Of course, they depend on lua-sockets, but Mach4's version of the lua-sockets module isn't in a state that package managers like LuaRocks can take advantage of for compiling module DLLs.

So my question is, has anyone has managed to add in any complicated Lua modules to Mach4? Is there a way to trick LuaRocks or LuaDist to do this for me?
Re: Working complex Lua Modules into Mach4
« Reply #1 on: March 12, 2021, 07:45:04 AM »
I can't answer your question but Mach4 has a remote GUI that you can run on another PC and view DRO's etc.. It's Mach4GUIR.exe in the Mach4Hobby folder. You just have to specify the IP address of the PC you want to connect in the 'Target' of the desktop short. You can even use a different screenset to the one running the machine.

Offline smurph

*
  • *
  •  1,402 1,402
  • "That there... that's an RV."
    • View Profile
Re: Working complex Lua Modules into Mach4
« Reply #2 on: March 12, 2021, 01:26:39 PM »
To build compiled modules, you will need to get a full dev environment setup.  It is a can of worms!  The version of LUA that we use is 5.3.4.  So you will need to start with finding that source.  Then find the source for all of the websocket dependencies.  Then you compile them all into modules.  But only install the websockets, as the rest are already present in the modules directory. 

It isn't easy.  :(  But it is not impossible.

Steve

Re: Working complex Lua Modules into Mach4
« Reply #3 on: March 12, 2021, 03:20:21 PM »
Mach4GUIR.exe unfortunately won't work since the other computer is a Linux machine. There haven't been any successful attempts to get Mach4 running on Linux, has there? I think LinuxCNC got that side of the CNC world covered well enough, probably.

But yep, compiling it outside of Mach4 and then copying the modules into Mach4's Module directory was what I was expecting. Glad to know that it is at least possible. I just have to figure out how to get the build scripts to stop looking for a compiler that isn't there.

In the meantime I convinced my other team member to try something that uses vanilla TCP/IP on her end. It isn't as nice as the server/listener that used Websockets but hopefully it will do.
« Last Edit: March 12, 2021, 03:24:47 PM by Mondrata »

Offline smurph

*
  • *
  •  1,402 1,402
  • "That there... that's an RV."
    • View Profile
Re: Working complex Lua Modules into Mach4
« Reply #4 on: March 12, 2021, 04:31:35 PM »
We launched Mach 4 at IMTS running on Linux.  Meaning Mach 4 ran on Linux before it ran on Windows.  :)  We don't ship a Linux version because we don't have a good software protection options on Linux. 

I was trying to find time to compile up a websockets module for you.  But if you can use regular TCP sockets, that would probably be a better options for you in the long run. 

Steve
Re: Working complex Lua Modules into Mach4
« Reply #5 on: March 13, 2021, 04:23:37 AM »
I tried the socket programming in LUA panels in Mach4 but I'm pretty sure there's a "resource sharing problem" because it would always stop working when sent too much data too fast (LUA is not thread safe). Here is the example: https://www.machsupport.com/forum/index.php?topic=43283.msg279798#msg279798

But, as long as the computers are on the same network, you could use the Modbus plugin and add cheap hardware in between to host a server. The attached is a bad example, but it's a start. Look here (https://randomnerdtutorials.com/esp32-dht11-dht22-temperature-humidity-web-server-arduino-ide/) for a better approach; an asynchronous solution to handling the server.

For the example I attached, you have to refresh the page and it will work...sometimes.

The attached is Arduino sketch. You can find more info about how to configure the modbus here using the DRO float example: https://www.machsupport.com/forum/index.php?topic=44512.0

The ESP32 has 2 cores and 1 of them is almost always never used. You could easily separate the modbus polling and the webserver on each core.

The best solution for this would be a mobile app that communicates Modbus via TCP. There are already apps that work. I think I might start working on this.

For initial setup, you can find more info about modbus TCP, Mach4 and the ESP32 here: https://github.com/kethort/esp32-cnc-mpg-handwheel-conversion-mach4