Hello Guest it is April 18, 2024, 08:31:00 AM

Author Topic: Trouble using scr Library  (Read 792 times)

0 Members and 1 Guest are viewing this topic.

Trouble using scr Library
« on: March 15, 2021, 05:37:49 PM »
I am trying to use the scr library in an M macro and I am not having success.  There is a toggle button defined on the screen that is working all respects.  When I try to query the state of the button from the macro the returned value is Nil and the rc is -99.  I haven't been able to determine what that code means. The line of code is:

local OhmicButtonState, rc= scr.GetProperty("OhmicEnable", "Button State")

I have copy and pasted the name of the button, so I am sure that is correct  I have spent so much time investigating this and I am having no success. I feel like it is something simple I am missing.  Does anyone have advice or guidance?  Thank you in advance!

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Trouble using scr Library
« Reply #1 on: March 17, 2021, 12:46:12 AM »
You have to require and INIT the scr library.  -99 means IPC not initialized.  :)

Once required:

scr.scIpcInit("127.0.0.1")

The better way of doing this is to create a register (in mcRegFile) for which the toggle button's state will reside.  Use the button's event scripts to write the button button state to this register.  Then read that register from the M code. 

The scr library is meant more for remote control applications.  Using it in a M code macro script is highly discouraged.  The Mach registers are the primary means of sharing data from the screen to the core and plugins.  They registers are fast and efficient vs. the scr library is pushed through the TCP/IP subsystem. 

Steve
Re: Trouble using scr Library
« Reply #2 on: March 19, 2021, 01:08:58 PM »
Thank you for your response. In my initial message I was trying to be a brief as possible, because nobody wants to read long drawn out messages. I am using registers to reflect the state of screen buttons. I have up/down scripts to toggle the the value in the register to reflect the state of the button.  Again, maybe I am missing something fundamental, but when the register value gets changed from within an M code script the state of the button tied to that register no longer in sync.  What is the best or proper method to ensure the state of the button reflects the value in the register? 

I did get the scr calls to work, but having seen your response that the IP stack is used for this communication, I understand why this would not be desirable.  Again thanks for the response. 

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Trouble using scr Library
« Reply #3 on: March 19, 2021, 03:50:10 PM »
I think you will need to put something in the PLC Script.

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Trouble using scr Library
« Reply #4 on: March 19, 2021, 10:58:40 PM »
I think you will need to put something in the PLC Script.

Correct.  And more specifically,
Code: [Select]
--update button state to reflect a register. 
-- "Button State" == 0, the button is up.
-- "Button State" == 1, the button is down.
hReg, rc = mc.mcRegHandle(inst, "/path/to/myButtonStateRegister")
if (rc == mc.MERROR_NOERROR) then
    val = mc.mcRegGetValueLong(hReg);
    bval = scr.GetProperty("myButton", "Button State")
    if (bval != val) then
        scr.SetProperty("myButton", "Button State", val)
    end
end
That is the pseudo code.  Check the syntax such because I just typed that in and was not pasting something from a real script. 

Steve