網頁

標籤雲

2014年10月30日 星期四

103電腦硬體裝修術科_程式

繼上次的 103電腦硬體裝修術科_元件配置 http://jktt5230qq.blogspot.tw/2014/10/103.html

以下為程式部份

1.對Form1,Button1,Button2,Button3,Timer 點兩下就可以寫程式,上面部分就不用打,自己會產生



2.打入程式後 USBHID 下面會出現毛毛蟲代表尚未把 USBHID.dll加入參考

3.加入步驟專案 >加入參考 >com >USBHID




4.加入後就沒有毛毛蟲了


4.最後按下 開始偵錯 就可以插入板子開始測了





程式如下
Imports Microsoft.VisualBasic.PowerPacks
Imports USBHID

Public Class Form1
    Dim usbHID As New HID
    Dim send(8) As Byte
    Dim A, B(99), c
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        B(0) = 1
        B(1) = 2
        B(2) = 4
        B(3) = 8
        B(4) = 16
        B(5) = 32
        B(6) = 64
        B(7) = 128

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        A = 1
        c = 0

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        A = 2
        c = 0
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        A = 3

    End Sub

    Private Sub display(ByVal no)
        For i = 0 To 7
            If no Mod 2 = 1 And A = 1 Then GLED(i).FillColor = Color.LightGreen
            If no Mod 2 = 1 And A = 2 Then RLED(i).FillColor = Color.Red
            no = no \ 2
        Next i
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        TextBox1.Text = "Current Time:" & TimeOfDay()
        For i = 0 To 7
            GLED(i).FillColor = Color.White
            RLED(i).FillColor = Color.White
        Next
        If usbHID.OpenHIDDevice(&H1234, &H6789) Then
            For i = 0 To 7
                GLED(i).FillColor = Color.DarkGreen
                RLED(i).FillColor = Color.DarkRed

            Next i
            send(0) = 0
            send(1) = 0
            usbHID.HIDSetReport(send)
            send(0) = 0
            send(1) = 16
            usbHID.HIDSetReport(send)
            If A = 2 And c <= 7 Then
                send(0) = 2 ^ c
                send(1) = 32
                usbHID.HIDSetReport(send)
                send(0) = 2 ^ c
                send(1) = 48
                usbHID.HIDSetReport(send)
                display(2 ^ c)
            Else
                display(0)

            End If
            If A = 1 Then
                send(0) = B(c)
                send(1) = 0
                usbHID.HIDSetReport(send)
                display(B(c))
            End If
        End If
        If A = 3 Then usbHID.CloseHIDDevice() : End
        If c > 15 Then c = 15 Else c = c + 1
    End Sub

End Class














沒有留言:

張貼留言