Hello Guest it is October 23, 2019, 12:20:08 PM

Author Topic: Where should I paste this script?  (Read 535 times)

0 Members and 1 Guest are viewing this topic.

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #10 on: January 11, 2019, 10:43:33 AM »
Thanks Craig!

What do you think about the "check home part" ?
I'm not sure I've catched it correctly in above code.. I think it could be like this instead?
But don't know which one is correct, I'm not a programmer, did some HTML back in the 90's but that doesn't count :D

Code: [Select]
hSigHome, rc = mc.mcSignalGetHandle(inst, mc.mcMotorIsHomed(inst, 8));
HomeState = mc.mcSignalGetState(hSigHome);
if HomeState == 1 then -- The turret motor seem to be homed, lets rotate the turret
Re: Where should I paste this script?
« Reply #11 on: January 11, 2019, 01:12:50 PM »
Hi,
it looks OK to me, I'm no expert however.

I think its time to put the code in the SigLib table (top of the screen load script) and try it out.

Craig
My wife left with my best friend...
     and I miss him!

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #12 on: January 11, 2019, 02:09:40 PM »
Yes, will do that tomorrow!
Will post the outcome here when it's up & running.

Thanks Craig!

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #13 on: January 12, 2019, 01:54:03 PM »
I need some serious help guys!
I tried the script today, and it came out to nothing.

I  took a physical button and wired it to the ESS Port 2, pin 2 with a proper resistor.
I mapped port 2, pin 2 to Mach and ESS INPUT1.
I confirmed that the button is working as intended by looking under the operator tab, the input1 LED lit up when pushing the button.
Also under Diagnostic --> Log, I can see that Mach logs HIGH when pressing the button and LOW when releasing it.
So far so good!

But I can't seem to get the signal script to initiate at all. I tried my script and also simplyfied it alot.
I even made it so simple to just pop up a messagebox or setLastEroor to confirm it's alive, but no it's really dead!

Not sure I'm editing the script in the right way? I did it like this:
Operator --> Edit Screen: Marked WX in top left corner (screen tree manager), then I pressed on the lightning on the bottom left corner (properties) and opened the "screen load script" and simply pasted my script within the {} under siglib. Then just saved the script ans saved the screen.
Is this the correct way? or must I edit the script in other way?

I have also thought about if Input1 (assigned under Mach Configure) automatically is the same as mc.ISIG_INPUT1 ??
Or must they be assigned to eachother in some way so that mc.ISIG_INPUT1 listens to Mach physical input 1?

One thing I noticed but didn't got the time to test was, the Log said button had "SigID 2, INPUT#1", is it perhaps that Input1 actually is mc.ISIG_INPUT2 ?

Back to the Operator --> Edit Screen: There is a column named "Signal script" in the bottem left frame (properties).
That file/script whatever it is only contains:
Code: [Select]
if SigLib[sig] ~= nil then
    SigLib[sig](state);
end

Should I do something in here?


It's really frustrating when I'm not even able to receive a fault code, the code seem to not even be initiated. Running G-code or not, Enabled or not.

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #14 on: January 12, 2019, 04:21:54 PM »
I've tried some other basic scripts but none of return anything.

Code: [Select]
[mc.ISIG_INPUT1] = function(state)
if (state == 1 or state == 0) then
wx.wxMessageBox('ja')
else
wx.wxMessageBox('nej')
end
end,

Code: [Select]
[mc.ISIG_INPUT1] = function(state)
if (state < 3) then
wx.wxMessageBox('ja')
else
wx.wxMessageBox('nej')
end
end,

I've tried with "" and '' in the MessageBox, also tried ending it with a semicolon ;
From what I can tell, the script never initiate, it doesn't react to the designated input.

Must I enable something before signal scipts start to work?

It's really annoying not getting any error to help me forward. :D
Re: Where should I paste this script?
« Reply #15 on: January 12, 2019, 04:48:42 PM »
Hi,
where did you put those code fragments? You do recognize that they are elements of a table....and must be in
the definition section of a table.....in this case the table is called SigLib?

These code fragments DO NOT BELONG in the Signal Script.

I assume that you have assigned the input (ISIG_INPUT1) to an input pin of  your controller?
Note also that the first few general inputs (inputs 0 thru 5) have attached LEDs on the machine diagnostics tab. Does the
appropriate LED light when the signal goes active?

Craig
My wife left with my best friend...
     and I miss him!

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #16 on: January 12, 2019, 04:53:57 PM »
Hi Craig,

I've putted them in the Screen load Script, this is the total:

Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,

[mc.ISIG_INPUT1] = function(state)
if (state == 1) then
wx.wxMessageBox("Ja")
else
wx.wxMessageBox("Nej")
end
end,
}

Correct, only thing I have in the Signal Script, is the default code that came with mach, that goes:
Code: [Select]
if SigLib[sig] ~= nil then
    SigLib[sig](state);
end

I have not assiged ISIG_INPUT1 inn particular, but I have in the Mach Config --> Inputs assigned Input #1 to my motion controller, ESS Port 2 pin 2. (which is mapped as input in the ESS plugin)
Yes, the apropriate LED light when I press the button, until I release it.
Re: Where should I paste this script?
« Reply #17 on: January 12, 2019, 05:06:01 PM »
Hi,
well as far as I can tell I would expect your SigLib entry [mc.ISIG_INPUT1] to be executed at each change of signal.

Can you scan through the rest of the SigLib entries just to make sure that you don't have two function definitions
for the same signal?

Craig
My wife left with my best friend...
     and I miss him!

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #18 on: January 12, 2019, 05:13:09 PM »
To see if ISIG_INPUT1 is present elsewhere in the load screen script? I'll check, but I have also tried to Map the button to Input20 and others just to outrule there is something going on with INPUT1.
Yes, I would have expected it to execute aswell. I haven't modyfied my profile at all, just assigned input/outputs and calibrated the machine so I don't think the profile is screwed up either but if I can't find the problem, then I'll maybe start from a fresh profile

Offline sx3

*
  •  40 40
    • View Profile
Re: Where should I paste this script?
« Reply #19 on: January 12, 2019, 05:24:01 PM »
Hmm, could it be problems if I have two instances of Siglib in my Load Screen script?

Code: [Select]
SigLib = {}

SigLib = {}

I remember I've added a CNC4PC MPG I just copy & pasted the code and I beleive it had a SigLib = {} that I put in the bottom end of the Screen load Script.
Makes me think that the second SigLib will overwrite the first SigLib (where I'm elaborating at the moment) since they share the same name..

Unfortunatly, I don't have access to machine to test this.
« Last Edit: January 12, 2019, 05:32:53 PM by sx3 »