Hello Guest it is April 16, 2024, 12:30:54 AM

Author Topic: Custom script CSMIO/IP-A Mach4  (Read 2108 times)

0 Members and 1 Guest are viewing this topic.

Custom script CSMIO/IP-A Mach4
« on: May 20, 2019, 08:18:25 AM »
Hello, Iam currently retrofitting an old Masterwood project 309 with Mach4 and the csmio/ip-a controller. I am at the phase to write custom scripts to make the machine function as it should.

The problem is that I cant seem to find a manual on how to use lua with this controller( and no good manual for lua itself). So I am unsure on how to set an output high.
I wanted to try and set an output high with an m-code to get familiar with the language. This is the code I wrote:
function m126 ()
local inst = mc.mcGetInstance();
io = mc.mcIoGetHandle(inst,"CSMIO-IP/out.3");
mc.mcIoSetState(io,1);
end


I am an novice at programming with lua but i have experience with c an c++

Thanks in advance
Re: Custom script CSMIO/IP-A Mach4
« Reply #1 on: May 20, 2019, 02:37:13 PM »
Hi,

Quote
I am an novice at programming with lua but i have experience with c an c++

If you can program in C and C++ then Lua will be a walk in the park. You could write scripts in C but you would
have to compile, edit and debug outside of Mach. Don't waste your time.


Mach4's latest builds have migrated to Lua 5.3 which has a few subtle variations on 5.2:

https://www.lua.org/manual/5.2/

I notice you are using an Io? I assume that the CSMIO plugin has registered the Io you are addressing?
You cannot register an Io object from a script, registering an Io object is done by a plugin and the object is 'owned'
by the plugin. I don't think that your string correctly addresses the object, assuming it exists.

May I suggest you use a regular output. Output #5 for instance.

function m(126)
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT5)
mc.mcSignalSetState(hsig,1)
end

Assign a pin of your controller to Mach's output in the controller plugin and your done. This is how I would address an output
of my ESS for instance.

Note the I chose Output5 with malice aforethought because there is an LED for it in the outputs section of the
Machine Diagnostics tab. Allows you to see what you are doing.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Custom script CSMIO/IP-A Mach4
« Reply #2 on: May 21, 2019, 07:49:45 AM »
Hi,

Quote
I am an novice at programming with lua but i have experience with c an c++

If you can program in C and C++ then Lua will be a walk in the park. You could write scripts in C but you would
have to compile, edit and debug outside of Mach. Don't waste your time.


Mach4's latest builds have migrated to Lua 5.3 which has a few subtle variations on 5.2:

https://www.lua.org/manual/5.2/

I notice you are using an Io? I assume that the CSMIO plugin has registered the Io you are addressing?
You cannot register an Io object from a script, registering an Io object is done by a plugin and the object is 'owned'
by the plugin. I don't think that your string correctly addresses the object, assuming it exists.

May I suggest you use a regular output. Output #5 for instance.

function m(126)
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT5)
mc.mcSignalSetState(hsig,1)
end

Assign a pin of your controller to Mach's output in the controller plugin and your done. This is how I would address an output
of my ESS for instance.

Note the I chose Output5 with malice aforethought because there is an LED for it in the outputs section of the
Machine Diagnostics tab. Allows you to see what you are doing.

Craig

Thanks for the reply. I am not a pro in c and c++ but can find my way around.

I got an reply from the csmio manufacter and I can call an output via an string. But I think the problem is where I put my macro file.

I tried my code in the m6 function and it worked, the output was set high. But when I make a custom macro m126 and put it in the macro folder within the profile the function doesn't seem to work. I tried to call the macro with the MDI window. Could you or someone help me with the custom macro file location? Because the mach4 manual said to save it within the profile and give it the macro name (m126).

Thanks in advance.

Jelle