Hello Guest it is March 28, 2024, 10:23:36 PM

Author Topic: Mach 4 Lua Scripting modbus  (Read 3608 times)

0 Members and 1 Guest are viewing this topic.

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

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Mach 4 Lua Scripting modbus
« Reply #1 on: February 24, 2016, 12:29:58 AM »
Just tell the DRO to use the modbus exported register via the "Register" property in the screen editor.  No code needed.

Steve
Re: Mach 4 Lua Scripting modbus
« Reply #2 on: March 01, 2016, 07:39:43 PM »
The use of the DRO and the LED were for test.  I was at the time looking for a way to bring in a bit to test or set.  I thank you for the feedback as to the being able to use the Register Value for the DRO; but I was looking more for a way to correct what I did not have working and find out why it wasn't working.     I'm really scratching my head at the minute to remember why I was trying to do this.  Give me a day or two and I probably still won't remember.

Thank you again for the response,
Alex

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Mach 4 Lua Scripting modbus
« Reply #3 on: March 01, 2016, 08:14:14 PM »
LOL!!!  Yeah...  I forget a lot of stuff too.  You pretty much have to in order to start trying to forget new stuff.  :)

Steve