1,451
社区成员
发帖
与我相关
我的任务
分享
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub btnClose_Click()
Dim bolP As Boolean
On Error GoTo errSub
bolP = funLEDComm(mscLED, CInt(txtLEDNo.Text), "L")
Exit Sub
errSub:
End Sub
'打开LED
Private Sub btnOpen_Click()
Dim bolP As Boolean
On Error GoTo errSub
bolP = funLEDComm(mscLED, CInt(txtLEDNo.Text), "H")
Exit Sub
errSub:
End Sub
Private Sub Form_Load()
With mscLED
.CommPort = 1
.Settings = "9600,n,8,1"
.RThreshold = 0
.InBufferSize = 1024
.OutBufferSize = 100
.OutBufferCount = 0
.InputLen = 0
.InputMode = comInputModeBinary
End With
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If mscLED.PortOpen Then mscLED.PortOpen = False
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'串口通信函数
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Private Function funLEDComm(mscP As MSComm, intLEDAdd As Integer, strLEDStatus As String) As Boolean
Dim strP As String
Dim lngP As Long
On Error GoTo errSub
strP = strLEDStatus & Right("000" & CStr(intLEDAdd), 3)
strP = strP & funCheck(strP)
If Not mscP.PortOpen Then mscP.PortOpen = True
lngP = GetTickCount
mscP.Output = strP
Exit Function
errSub:
End Function
Private Function funCheck(ByVal strP As String) As String
Dim intP As Integer
Dim lngP As Long
On Error GoTo errSub
For intP = 1 To Len(strP)
lngP = lngP + Asc(Mid(strP, intP, 1))
Next intP
funCheck = Right("00" & Hex$(lngP Mod 256), 2)
Exit Function
errSub:
End Function