Hello Guest it is May 16, 2024, 05:54:32 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.


Topics - revolut

Pages: 1
1
Mach4 General Discussion / Mach 4 Lua Scripting modbus
« on: February 01, 2016, 03:52:49 PM »
Hello,
  Firstly I'd like to thank everyone here on the board for the wealth of information that is out here in the forums.  Secondly I apologize as I am quite sure this is something that I am doing wrong in writing my scripts.   I have communication established currently between a PLC and Mach4; the bit that I am looking to examine in my LUA script is shown in the modbus diagnostic and shows the correct value when I toggle the bit.  Where I am having a bit of trouble is in actually getting the status of that bit in the script.  When you look at the code below you will probably spot the issue right away.  

If I change the local variable valmb = 1 -- mc.mcRegGetValue(mbhnd).   The script behaves like I expect.  I really think my problem is how I'm trying to examine the bit.

Any assistance anyone can offer would be greatly appreciated.



Modbus instance = 1200test *Capitalization is correct found that mistake already.



////////////// LUA SCRIPT ///////////////

local inst = mc.mcGetInstance()
local mbhnd = mc.mcRegGetHandle(inst, "1200test/Bit_Test")
local valmb = mc.mcRegGetValue(mbhnd)
scr.SetProperty('mbReg2dro', 'Value', tostring(valmb))

if valmb == 1 then
    scr.SetProperty("testled", "Value", "1")
else
    scr.SetProperty("testled", "Value", "0")
end

/////////////////////////////////////////////



Thank you in advance!

Alex

Pages: 1