Counting every 4th signal - Excel VBA | LabJack

Counting every 4th signal - Excel VBA

3 posts / 0 new
Last post
RoEng's picture
Counting every 4th signal - Excel VBA

Hello guys,

I've inherited a project from a colleague that left the company. Basically we're using an Excel VBA to count the manufacturing time between two parts produced on a machine, and we're using the return home signal to count when each part is completed (it's an automated welding equipment).

Due to changes in our manufacturing process, now we're producing the same part on a different equipment (semi automatic welding equipment), which requires a human operator to move the part four times in different positions before the part is completed. My problem is that now, after each handling, the return home signal is sent by the equipment and there's no other signal I can hook on to.

Is there any way to take into account only the fourth signal sent by the equipment? I am pretty new to this, and my Excel VBA skills are limited.


Here's a snippet of the code in question:


Declare PtrSafe Function AOUpdate Lib "ljackuw.dll" (ByRef idnum As Long, ByVal demo As Long, ByVal trisD As Long, ByVal trisIO As Long, ByRef stateD As Long, ByRef stateIO As Long, ByVal updateDigital As Long, ByVal resetCounter As Long, ByRef count As Long, ByVal analogOut0 As Single, ByVal analogOut1 As Single) As Long

Sub setoutput()
lngidnum = -1
analogOut0 = Sheets("Data_table").Range("N1").Value
Sheets("Data_table").Range("O2").Value = lngError
lngError = AOUpdate(lngidnum, lngDemo, lngTrisD, lngTrisIO, lngStateD, lngStateIO, lngUpdateDigital, lngResetCounter, lngCount, analogOut0, analogOut1)
End Sub

And the second one is: 

Declare PtrSafe Function EAnalogIn Lib "ljackuw.dll" (ByRef idnum As Long, ByVal demo As Long, ByVal channel As Long, ByVal gain As Long, ByRef overVoltage As Long, ByRef voltage As Single) As Long

Sub lookinput()
lngidnum = -1  ' First found U12
lngChannel = 1  ' AI1 single-ended
lngError = EAnalogIn(lngidnum, lngDemo, lngChannel, lngGain, lngOverVoltage, voltage)
Sheets("Data_table").Range("Q1").Value = voltage
Sheets("Data_table").Range("P2").Value = lngError
End Sub


LabJack Support
LabJack Support's picture
If I am understanding

If I am understanding correctly, the subprocess setoutput() is being called to generate your return home signal using the U12 DAC output. Is that correct? If that is the case, then you could probably add a new static variable called something like "counter" and increment it at the start of the subprocess, add a conditional where you only do the AOUpdate call if counter >=4, then reset the counter to 0 after the AOUpdate call.

The suggestion above is dependent on your setoutput subprocess being called 4 times every time the equipment is used. Additional consideration might be needed to ensure that is always true or to come up with an alternative way to control your signal output. This is outside of the scope of our support.

These pages have some relevant resources in case you are not familiar with if statements or static variables in VBA:

RoEng's picture
Hey! Yeah, you're right about

Hey! Yeah, you're right about the returning home signal. I'll give the static variable thing a try (may fail, never did this but I'll try nonetheless - thanks for the links). I'll post the code when I get something going, maybe it'll help someone else out there :)

About the part processed, on simple terms it's a metal crate-like object with a cover on top. The box itself is made out of a cross-shaped metal sheet, which after bending is turned into the basic shape of the box. After this is done, we're using the welding process I talked about in the first post to weld the 4 remaining sides (so it's always 4, not more, not less).

Thanks a lot!