loading
 
VB Script Module
Steve A from United States  [2 posts]
1 month
We are adding an encoder to our Advantech digital module input.

We are trying to have a Variable "Enc_Pulses" tied to our encoder in and increment a counter "Enc_Cntr" while another digital input "Prod_Sens" is turned on via a sensor.

When the Input "Prod_Sens" Input goes low we want the counter to clear

I know this needs to be a VB Script program but we are struggling with it. If its a couple lines of code withing the module, we would appreciate the help.

Thanks in advance
STeven from United States  [1403 posts] 1 month
Untested and unsure if this is what you need but this might get you a bit further. Just add a VBScript module, stick the following into the text box and press run. Keep in mind that you need to load and save EACH variable as local variables in the VBScript module are always zero on return into the module.

'---------

if GetVariable("Prod_Sens") = 0 then
  SetVariable "Reset_Enc_Pulses", GetVariable("Enc_Pulses")
end if

SetVariable "Enc_Cntr", GetVariable("Enc_Pulses") - GetVariable("Reset_Enc_Pulses")

'---------

STeven.
Steve A from United States  [3 posts] 1 month
Thanks, I'll play around with that. It's a good starting point,. FYI I am intending to increment a counter until a preset is met, so
I will add "+1" to the variables I suspect...

 Reply  New Post   Forum Index