Hello Guest it is March 28, 2024, 08:52:33 PM

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.


Messages - revolut

Pages: 1
1
Mach4 General Discussion / Re: Mach 4 Lua Scripting modbus
« 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

2
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