Hi,
I have purchased 20 K8090 relay boards which will connect to 20 terminals (Win 7 OS) which will in turn control 20 conveyors, one conveyor per terminal. The control of the conveyor from the terminal is simple, I just have to send a pulse to start the cycle for .75 of a second. The conveyor is sitting on a scale so I know when there is an item on the scale and when I get a steady weight I register the event and send the signal to the board.
This is working well on the majority of the scales but on some the disconnect command fails to work (randomly) and I can’t reconnect to the board until I exit the application disconnect the USB and reconnect and then restart the application. I have the code to control the relay in a sub routine below
Private Sub StartLine()
If cmbRelayPort.SelectedItem.ToString.ToLower <> "none" Then
K8090.Port = cmbRelayPort.SelectedItem.ToString
If K8090.Connect Then
K8090.SwitchRelayOn(&H1)
btnStartLine.BackColor = System.Drawing.Color.Lime
btnStartLine.Refresh()
Sleep(750)
K8090.SwitchRelayOff(&H1)
btnStartLine.BackColor = System.Drawing.Color.DarkGray
K8090.Disconnect()
Sleep(1000)
Else
btnStartRun.Text = "Start Run"
btnStartRun.BackColor = Color.IndianRed
MsgBox("Failed to connect to relay board")
End If
End If
End Sub
What is happening is that at some point the disconnect will fail and therefore the next time I try the connect it will fail and pop up the message. On my laptop if I put in a breakpoint and then move the program execution to the disconnect command to force a disconnect VB throws a memory violation error because the original connect wasn’t called by this sub routine call, therefore the app thinks the card is still connected by a previious call and because that has completed I can’t disconnect. The is powered by and external 14v DC supply. This seems to be totally random. Some terminals have not given and bother whilst others are failing on a regular basis. Is there any way to ensure that the disconnect command actually works. I put a Sleep(1000) in after the disconnect to see if that would help but it doesn’t. As I said I have 20 instances of this now and need to find a solution urgently.