loading
 
VB Script Module
Steve from United States  [4 posts]
5 year
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 Gentner from United States  [1446 posts] 5 year
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.
Steven from United States  [4 posts] 5 year
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...

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index