Hello Guest it is April 19, 2024, 06:38:19 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jm1937

Pages: 1 2 »
1
Mach4 General Discussion / Re: Using modules from Mcodes
« on: July 22, 2020, 08:30:14 PM »
Note:
I fixed this problem, albeit in a work-around way.

I wrote a module which has functions to open the serial communication to the device (a syringe pump), close the serial port, and print any commands relevant to me to the serial port.
It turned out that, while not the cleanest implementation, opening and closing the serial port for each and every command string sent was pretty fast; not noticeably slower than opening the serial port once at load time.  I'd imagine this approach can prevent hang-ups if the socket gets broken or something, which is a side-benefit.

The screen loads the module with this code in the screen load script:

package.path = package.path .. ";./Modules/?.lua;"
package.cpath = package.cpath .. ";./Modules/?.dll;"
package.loaded.SyringePump = nil
sp=require "SyringePump"

And I used the following lines at the start of my macro to get the module loaded for the separate Lua instance that runs for macros:

package.path = package.path .. ";./Modules/?.lua;"
package.cpath = package.cpath .. ";./Modules/?.dll;"
sp=require "SyringePump"

In this way, all the commands in my module are available for both the screen and MCodes. 

Again, it's not a very clean implementation -- the serial object could have conflicts if the screen and a macro try to open it at the same time --  but it's code-efficient (the functions live in one file) and it works fairly robustly. What I wouldn't give for some semaphores, or, a single Lua instance, or god forbid some thread-safe implementation of Mach4 :-D

Hope someone finds this useful!

2
Mach4 General Discussion / Re: Using modules from Mcodes
« on: June 04, 2020, 04:43:29 PM »
Has anyone ever implemented a solution like this:

A macro which loads an instance of a module, but checks to see if that module is already loaded by the screen/GUI -- if it is, cleanly unload it (close the serial port, in this case)?

That way, the serial port isn't being passed around or used exclusively by one Lua Instance (screen or macro), but being used on by the Lua runtime which is relevant to the call at the moment

3
Mach4 General Discussion / Re: Using modules from Mcodes
« on: June 03, 2020, 08:57:16 PM »
That may work.  I will try to dig up some code examples.  Frankly, it seems like setting a status variable and having a timer check it is a hack.

As a side note (puts on computer scientist hat) there really *should* be a way to either have thread-safe ways to pass variables between the two instances (semaphores, locking) or have the same Lua instance run macros and the screen.  I can imagine there's good reasons for keeping the instances separate, but I can easily imagine race conditions arising if we are accessing registers from two separate stacks.

Has anyone thought about a way to do this robustly?  I know realtime actions like GCode execution probably need some sort of thread safety but I do think we should be able to access Mach4 Screen variables from macros.

4
Mach4 General Discussion / Re: Using modules from Mcodes
« on: June 03, 2020, 04:13:43 PM »
Turning on/off is the most important feature, but setting the rate is important too.
I'm not sure I understand how your suggestion works -- I have the macro update a signal, and the Mach4GUI instance would command it's instance of the module to control the pump?

5
Mach4 General Discussion / Re: Using modules from Mcodes
« on: June 03, 2020, 03:17:42 PM »
Update-  I've discovered from further reading about "coroutines" but it still doesn't seem that a macro can explicitly access the LUA session that the screen uses.
Can I have my module store the serial port object in a register?  Do registers accept lua objects?

6
Mach4 General Discussion / Using modules from Mcodes
« on: June 03, 2020, 02:38:47 PM »
I know this question has been asked & answered, and I've found those forums posts already -- please read without dismissing, there's a nuance here.

I have a module I've written which connects to a serial device (a small pump).  I wrote button for my screen set to use the module to communicate with the pump, and it works well.  For simplicity, I put the "connect" function of my module in the screen load script.

I also want to be able to turn the pump on & off in m-code macros during movement operations, using the "load_modules.mcs" script which is floating around this forum.  However, when I run the Mcode, the serial port is unavailable -- it's already open in a *separate* lua instance from the screen buttons!  I removed the "connect" function from my screen load script and made a connect/disconnect button on my screen, but the operator will need to remember to disconnect from the pump before running any Gcode w/ macros.

How can I have the Mcode macros and my screen "share" an instance of a module? I can't find any documentation related to passing objets back and forth to macros outside of registers.



How can I make the screen and my macros

7
Mach4 General Discussion / Re: Using the Serial plugin from a macro
« on: April 08, 2019, 05:34:00 PM »
After installing Mach4 to another machine and copying the Luars232.dll to my desired machine, everything is working — the example script runs beautifully in the the ZeroBrane studio and controls my device. I copied the example code in to a M-macro and it works. I’ll use other examples I’ve see for taking arguments to M macros to improve its functionality.

One question- when I made the macro, I copied over the library imports and port setup as well. Would it make it faster if I somehow used registers to make a port object (?) and called it from the macro?

8
Mach4 General Discussion / Re: Using the Serial plugin from a macro
« on: April 08, 2019, 05:15:55 PM »
Very strange, my install of Mach4 hobby (latest version) did not come with luars232.dll

9
Mach4 General Discussion / Re: Using the Serial plugin from a macro
« on: April 08, 2019, 04:48:48 PM »
I’m trying to write a custom M3 macro to operate this machine, but it seems like my Mach4 didn’t ship with the luars232 library. Does is sound right that I need to download it and it put it in my Modules folder?

10
Mach4 General Discussion / Re: Using the Serial plugin from a macro
« on: April 01, 2019, 09:04:45 PM »
Thanks for the replies.

CoolTerm is a separate program from Mach4 which simply allows you read/write commands to a serial port.

If I understand, the serial plugin is outdated, and I should use Lua with luars232 in M-code macros to control this accessory. Will that allow me to pass in arguments (like flow rate) from the GCode program?  As an example: I would like to call M% 1500 (where % is some unreserved M code) and that would specify a flow rate of 1500 and also trigger M3 to enable the spindle relay.
Does anyone have an example like this?

Craig- what do you mean you set up a trial port?

Pages: 1 2 »