fbpx
Tags:   #   #   #   #

The current plugin release provides only two analog inputs (two potentiometers) for FRO and SRO values control. If you want to control some other value in Mach4 using an analog input we will show you how to do this with RRO as an example. The easiest way to support the analog input is through a macro, and more specifically by a PLC script which is a part of Mach4 screen. The macro is executed at 50ms frequency what provides very fast reaction. If you do not know what is the PLC script you can read about it in the „3.2.3 PLC Script” chapter of the guide:
 https://www.machsupport.com/wp-content/uploads/2014/05/Mach4%20Scripting%20Manual.pdf

  1. On the main Mach4 screen press the options as follows:
  • „Operator” option
  • „Edit Screen” option

After that Mach4 goes into screen edit mode.

 

2. It the Mach4 screen editor window press as follows: 

  • the „wxRout” option („wxLathe” for a lathe)
  • the „Events” button (a sheet of paper with a lightning sign)
  • the „PLC Script” area (to highlight another button)
  • the ellipsis button (three dots)

After that, you will see the LUA scripts editor window where you can see the PLC script code. 

3. Scroll down the PLC script to the end and find the line marked below.

4. Place the cursor over the line and press „Enter” for a few times to make some space for the code. 

 

NOTE: According to the information contained in the marked line you can’t put your own code below it. 

 

5. Next place the below code in the prepared area, save the macro and quit the screen editor.

local Analog_In_Reg = mc.mcRegGetHandle(inst, "CSMIO-IP/Analog Input 2")                                  
local Analog_In_Val = mc.mcRegGetValue(Analog_In_Reg)
local maxval = scr.GetProperty('slideRRO', 'Max Value')
local minval = scr.GetProperty('slideRRO', 'Min Value')
local RRO = Analog_In_Val / (10 / tonumber(maxval))
if (RRO < tonumber(minval)) then
 RRO = tonumber(minval);
end
if (RRO > tonumber(maxval)) then
 RRO = tonumber(maxval);
end
scr.SetProperty('slideRRO', 'Value', tostring(RRO));

The above code reads voltage value of the analog input no. 2, changes it to percentage value and passes it to slideRRO. The code verifies if the RRO value doesn’t exceed the minimum and maximum RRO slide value. 

If you want to read the voltage value of any other analog inputs use the two first lines from the above code:

local Analog_In_0_Reg = mc.mcRegGetHandle(inst, "CSMIO-IP/Analog Input 0")
local Analog_In_0_Val = mc.mcRegGetValue(Analog_In_0_Reg)
-- Analog in 0
local Analog_In_1_Reg = mc.mcRegGetHandle(inst, "CSMIO-IP/Analog Input 1")                     
local Analog_In_1_Val = mc.mcRegGetValue(Analog_In_1_Reg)
-- Analog in 1
local Analog_In_2_Reg = mc.mcRegGetHandle(inst, "CSMIO-IP/Analog Input 2")                       
local Analog_In_2_Val = mc.mcRegGetValue(Analog_In_2_Reg)
-- Analog in 2
local Analog_In_3_Reg = mc.mcRegGetHandle(inst, "CSMIO-IP/Analog Input 3")                        
local Analog_In_3_Val = mc.mcRegGetValue(Analog_In_3_Reg)
-- Analog in 3

After executing the above code the variable Analog_In_0_Val, Analog_In_1_Val, Analog_In_2_Val and Analog_In_3_Val will keep the analog inputs voltage values shown in volts.

 

[Source:] The articles were created by CS-Lab’s Technical Support section for CSMIO/IP users. 

×

Hello!

Click one of our contacts below to chat on WhatsApp

× How can I help you?