日期:2014-05-17 浏览次数:20755 次
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPortforLampDriver.DiscardOutBuffer()
MessageBox.Show(SendCMDtoDriver("70"))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPortforLampDriver.DiscardOutBuffer()
MessageBox.Show(SendCMDtoDriver("f0"))
End Sub
Public Function SendCMDtoDriver(ByVal strCMDSend As String)
Dim bytHex() As Byte
Dim indata As String
Dim byteToRead As Int16 = frmMain.SerialPortforLampDriver.BytesToRead
Dim ch(byteToRead) As Byte
Dim bytesRead As Int16 = 0
ReDim bytHex((Len(strCMDSend) \ 2) - 1)
Dim i As Integer
indata = ""
For i = 1 To Len(strCMDSend) Step 2
bytHex((i - 1) / 2) = Val("&H" & Mid(strCMDSend, i, 2))
Next
frmMain.SerialPortforLampDriver.Write(bytHex, 0, bytHex.Length)
frmMain.SerialPortforLampDriver.DiscardOutBuffer()
Sleep(200)
bytesRead = frmMain.SerialPortforLampDriver.Read(ch, 0, byteToRead)