K8090 Disconnects - Urgent help

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.

Please try this Visual Studio solution
velleman.eu/downloads/files/ … 90.NET.zip

It uses purely .NET to communicate with the K8090, so no native dll’s, no wrappers, no assemblies. It will be more suited for what you want to do and more robust. Please let us know if this new approach solves your problem.

Note: Using Sleep is mostly useless since it puts the current thread to sleep, eg. no code can be executed