|
发表于 2020-7-31 10:15:01
|
显示全部楼层
Public Function SendHexDataString() As Boolean
Dim SendData As String
Dim buf() As Byte
Dim m, n, p As Long
Dim i, j, k As Long, cs
On Error Resume Next
SendHexDataString = False
SendData = "029c"
'SendData = strSendData 'Trim(Text2.Text) '½«Òª•¢Ë͵ÄÎı¾¿òÄڵĿոñÈ¥³ý£¬²¢ÇÒ¸³¸øSENDDATA
If frmMain.MSComm1.PortOpen = False Then
frmMain.MSComm1.PortOpen = True
'MsgBox "Çë´ò¿ª´®¿Ú", vbOKOnly, "´íÎó"
'Exit Function
End If
If Len(SendData) = 0 Then 'Èç¹ûÎı¾¿òÄÚûÓÐÊý¾Ý
MsgBox "ÇëÊäÈëÊý¾Ý", vbOKOnly, "´íÎó"
Exit Function
End If
'If Check2.Value = 0 Then 'Èç¹ûûÓÐÑ¡ÔñÊÇ•ñÒÔ16½øÖÆ•¢ËÍ
'p = Len(SendData)
'ReDim buf(p - 1) As Byte
'For i = 1 To p
' buf(i - 1) = Asc(Mid(SendData, i, 1)) '½«Ã¿¸ö×Ö•ûÒÔASCÂë•¢ËÍ
'Next i
'Else 'Èç¹ûÑ¡ÔñÒÔ16½øÖÆ•¢ËÍ
SendData = Replace(SendData, " ", "")
SendData = Replace(SendData, vbCrLf, "")
p = Len(SendData) \ 2 - 1
ReDim buf(p) As Byte
For i = 0 To p
buf(i) = CLng("&H" & Mid(SendData, i * 2 + 1, 2)) 'ÒÔ16½øÖÆÊý•¢ËÍ
Next i
'End If
'ͨ¹ý´®¿Ú•¢ËÍÊý¾Ý
frmMain.MSComm1.InputMode = comInputModeBinary
frmMain.MSComm1.Output = buf()
'Sleep (100)
'ProcGetData
SendHexDataString = True
Exit Function
'³ö´í´¦Àí
DoErr:
If Err.Number = 13 Then
MsgBox "Êý¾Ý¸ñʽ²»¶Ô", vbOKOnly, "´íÎó"
Else
MsgBox Err.Description
End If
End Function
|
|