Hello Guest it is March 28, 2024, 11:04:22 AM

Author Topic: Using the Serial plugin from a macro  (Read 1815 times)

0 Members and 1 Guest are viewing this topic.

Using the Serial plugin from a macro
« on: April 01, 2019, 02:49:56 PM »
Hello all-
I have what you might consider to be a mist/flood attachment i'd like come on with M3 and turn off with M5 (on top of the spindle on/off relay).  It takes serial commands for on/off with additional parameters (like flow rate, for instance) over a traditional COM port. I've tested it and it works well through CoolTerm, but I'd like to write a macro that M3 and M5 turns it on/off.  I loaded the COM parameters in to the Serial plugin that ships with Mach4, but I'm wondering how to call it from a Macro using Lua.  Do I need to import luars232 or is it callable via an mc() function available from the serial plugin?
I'm using Mach4+ESS on windows 10, with a 3-axis router table.
Re: Using the Serial plugin from a macro
« Reply #1 on: April 01, 2019, 04:02:16 PM »
Hi,
I'm not familiar with the serial port plugin.

I set up a trial port, seems to work OK.

Would you explain what CoolTerm is?

I imagine that you send/receive data for the port using registers like you would with Modbus. If that's
the case then writing some code to update the registers should be easy enough.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using the Serial plugin from a macro
« Reply #2 on: April 01, 2019, 06:24:21 PM »
I would use the laurs232 module instead.  Do it all in your M3/M4/M5 mocros.  The serial plugin is old... pre LUA modules.  Once we put LUA modules in, it pretty much eliminated the need for the serial plugin. 
Re: Using the Serial plugin from a macro
« Reply #3 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?
Re: Using the Serial plugin from a macro
« Reply #4 on: April 01, 2019, 09:41:59 PM »
Hi,
one possibility is to rewrite m3, m4 and m5.

Note the deliberate use of lowercase and without leading zeros. That's how the Gcode interpreter treats all Gcode,
mostly M03 still gets treated as m3 but occasionally it does not too! Real tricky fault to find.

As you know there an m3 already built in to Mach, you can't change it. When Mach encounters an m3 (or m4,m5....)
it in the first instance searches in the macro directory of the current profile. If it finds an m3 there that is what it
uses. If not it will search until it finds one. usually the built in m3.

Thus if you write your own m3 that is what will be executed. You need to include all the functionality of the built in m3
PLUS whatever extra fruity bits you want to include. The best place to see what happens within the existing m3 is to look at
the screen button script.

In the screen editor the function associated with the button is:
Code: [Select]
SpinCW()
--local inst = mc.mcGetInstance();
--local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
--local sigState = mc.mcSignalGetState(sigh);
--if (sigState == 1) then
--    mc.mcSpindleSetDirection(inst, 0);
--else
--    mc.mcSpindleSetDirection(inst, 1);
--end

The function is just SpinCW(), all the rest of the code is commented out, its just to give you a sample of
the code the function contains, it is not the function definition itself. The actual function
definition is in the screen load script, approximately line 140:
Code: [Select]
---------------------------------------------------------------
-- Spin CW function.
---------------------------------------------------------------
function SpinCW()
    local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
    local sigState = mc.mcSignalGetState(sigh);
   
    if (sigState == 1) then
        mc.mcSpindleSetDirection(inst, 0);
    else
        mc.mcSpindleSetDirection(inst, 1);
    end
en
So to get your pump running you could modify this code or you could rewrite it including your instructions to get the
pump to run into your own m3() in the macros folder of our profile.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using the Serial plugin from a macro
« Reply #5 on: April 03, 2019, 08:58:58 AM »
I've gotten ASCII serial working well for communications over RS485 to some servo drives. The scripting in LUA is relatively easy. If you have specific questions about how to get Mach to read/write serial I would be happy to help.

Also remember that only one program can "own" a serial port on a computer, so if you have a terminal emulator running, Mach won't be able to talk on the port.
Re: Using the Serial plugin from a macro
« Reply #6 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?

Offline reuelt

*
  •  520 520
    • View Profile
Re: Using the Serial plugin from a macro
« Reply #7 on: April 08, 2019, 05:14:15 PM »
The latest ver of MACH4 hobby already include
luars232.dll and luars232-Example.lua
in the modules folder.

People who dropped luars232.dll into earlier MACH4 in 2015 could not get it working.
"the gift of God is eternal life through Jesus Christ our Lord"
Re: Using the Serial plugin from a macro
« Reply #8 on: April 08, 2019, 05:15:55 PM »
Very strange, my install of Mach4 hobby (latest version) did not come with luars232.dll
Re: Using the Serial plugin from a macro
« Reply #9 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?