This should look familiar.
Per your advice, on FormLoad I set all the values of OnOffBit(j) to 0. Still the same result. I've attached the code, hoping that you could spot my error. Thanks for your help
Code:
Dim FlipFlop As Boolean = True 'Keep-alive for brain
Dim OutChunks(64) As Byte 'Bytes for 64bit data chunk being sent to brain
Dim OnOffBit(12) As Integer 'Bit to turn on or off an output
Dim Uint0 As UInt32 = Convert.ToUInt32(0) 'Uint representing zero
Dim VIDPID As String = "USB\VID_04D8&PID_000C\5&2C65B59D&0&1"
Code:
Public Sub SendDataBlock()
If Uint0 = 0 Then 'only Init once
If USBIO.FUSB_Initialize(Uint0, VIDPID, Uint0) Then 'Initialize Device
Debug.WriteLine("Initialized: " & Convert.ToString(Uint0))
Else
Debug.WriteLine("Error Initializing: " & Convert.ToString(Uint0))
End If
Else
Debug.WriteLine("Already Initializing: " & Convert.ToString(Uint0))
End If
'Clear ByteBlock
Dim cnt As Integer
For cnt = 0 To 63
OutChunks(cnt) = 0
Next
'Convert FlipFlop Boolean to an integer
Dim KeepAlive As Integer = Convert.ToInt32(FlipFlop)
Dim i As Integer
For i = 0 To 11
OutChunks(i) = Convert.ToByte(0 & KeepAlive & OnOffBit(i))
Next
OutChunks(61) = Convert.ToByte(255) 'wake up PIC
USBIO.FUSB_Send(Uint0, OutChunks)
FlipFlop = Not FlipFlop 'Flip keepalive bit
End Sub
Private Sub btn0on_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0on.Click
OnOffBit(0) = 1 'Turn Output on
SendDataBlock()
End Sub
Private Sub btn0off_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0off.Click
OnOffBit(0) = 0 'Turn Output off
SendDataBlock()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim j As Integer
For j = 0 To 11 'need to fill a value for all dig outs
OnOffBit(j) = 0
Next
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
USBIO.FUSB_Free(Uint0)
End Sub
Bookmarks