日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GSM-串口和GPRS-网口通信

發(fā)布時間:2025/3/14 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GSM-串口和GPRS-网口通信 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Option Explicit

'************************************************
'******************COM 端口設(shè)置******************
'************************************************
Public Function COMSet(CommObj As MSComm, ByVal mPort As String, ByVal mSet As String) As Boolean
??? On Error GoTo Err
??? If CommObj.PortOpen = True Then CommObj.PortOpen = False
??? CommObj.InBufferSize = 1024
??? CommObj.OutBufferSize = 512
??? CommObj.CommPort = mPort
??? CommObj.Settings = mSet
??? CommObj.PortOpen = True
??? CommObj.RThreshold = 1
??? CommObj.NullDiscard = False
??? CommObj.InputLen = 0
??? CommObj.SThreshold = 1
??? CommObj.InputMode = comInputModeBinary
??? COMSet = True
??? Exit Function
Err:
??? COMSet = False
End Function

'************************************************
'****************十六進制轉(zhuǎn)十進制****************
'************************************************
Public Function HexToDec(HexValue As Variant) As Variant
??? Dim LowValue, HighValue As String
????
??? If Len(HexValue) = 1 Then
?????? HexValue = "0" & HexValue
??? End If
??? Select Case Left(HexValue, 1)
?????????? Case "A"
??????????????? LowValue = "10"
?????????? Case "B"
??????????????? LowValue = "11"
?????????? Case "C"
??????????????? LowValue = "12"
?????????? Case "D"
??????????????? LowValue = "13"
?????????? Case "E"
??????????????? LowValue = "14"
?????????? Case "F"
??????????????? LowValue = "15"
?????????? Case Else
??????????????? LowValue = Left(HexValue, 1)
??? End Select
??? Select Case Right(HexValue, 1)
?????????? Case "A"
??????????????? HighValue = "10"
?????????? Case "B"
??????????????? HighValue = "11"
?????????? Case "C"
??????????????? HighValue = "12"
?????????? Case "D"
??????????????? HighValue = "13"
?????????? Case "E"
??????????????? HighValue = "14"
?????????? Case "F"
??????????????? HighValue = "15"
?????????? Case Else
??????????????? HighValue = Right(HexValue, 1)
??? End Select
??? HexToDec = Val(LowValue) * 16 + Val(HighValue)
End Function

'************************************************
'***********判斷發(fā)送數(shù)據(jù)是否是十六進制***********
'************************************************
Public Function OpinHEX(strobj As String) As Boolean
??? Dim i As Long
??? If Len(strobj) Mod 2 = 0 Then
??????? OpinHEX = True
??? Else
??????? OpinHEX = False
??????? Exit Function
??? End If
??? For i = 1 To Len(strobj)
??????? If (Asc(Mid(strobj, i, 1)) >= 48 And Asc(Mid(strobj, i, 1)) <= 57) Or (Asc(Mid(strobj, i, 1)) >= 65 And Asc(Mid(strobj, i, 1)) <= 70) Then
??????????? OpinHEX = True
??????? Else
??????????? OpinHEX = False
??????????? Exit Function
??????? End If
??? Next
End Function

'************************************************
'***將接收到的十六進制數(shù)據(jù)轉(zhuǎn)換為中文***
'************************************************
Public Function HexToChinese_RHR(DataStr As String) As String
??? Dim i As Long, j As Long
??? i = Len(DataStr) \ 4
??? For j = 0 To i - 1
??????? HexToChinese_RHR = HexToChinese_RHR & ChrW(HexToDec(Mid(DataStr, 1 + 4 * j, 2)) * 256 + HexToDec(Mid(DataStr, 1 + 2 + 4 * j, 2)))
??? Next
End Function

'************************************************
'****將接收到的十六進制數(shù)據(jù)轉(zhuǎn)換為中文(標(biāo)準(zhǔn))****
'************************************************
Public Function HexToChinese_Stand(DataStr As String) As String
??? Dim i As Long, j As Long
??? i = Len(DataStr) \ 4
??? For j = 0 To i - 1
??????? HexToChinese_Stand = HexToChinese_Stand & Chr(HexToDec(Mid(DataStr, 1 + 4 * j, 2)) * 256 + HexToDec(Mid(DataStr, 1 + 2 + 4 * j, 2)))
??? Next
End Function

'************************************************
'********將接收到的中文轉(zhuǎn)換為十六進制數(shù)據(jù)********
'************************************************
Public Function ChineseToHex(DataStr As String) As String
??? Dim i As Long, j As Long
??? Dim DataStr_Tmp As String
????
??? For i = 0 To Len(DataStr) - 1
??????? DataStr_Tmp = Hex(AscW(Mid(DataStr, i + 1, 1)))
??????? For j = 1 To 4 - Len(DataStr_Tmp)
??????????? DataStr_Tmp = "0" & DataStr_Tmp
??????? Next
??????? ChineseToHex = ChineseToHex & DataStr_Tmp
??? Next
End Function

'************************************************
'**************將數(shù)據(jù)轉(zhuǎn)換為十六進制**************
'************************************************
Public Function HEXData(DataStr As String) As String
??? Dim DataStr_Tmp As String
??? Dim SendData As String
??? Dim i As Long
????
??? '去掉字符串中的空格
??? DataStr_Tmp = DelBlank(DataStr)
??? '轉(zhuǎn)換為十進制
??? For i = 1 To Len(DataStr_Tmp) \ 2
??????? SendData = SendData & Chr(HexToDec(Mid(DataStr_Tmp, 2 * (i - 1) + 1, 2)))
??? Next
??? HEXData = SendData
End Function

'************************************************
'************以GSM按 十六進制發(fā)送數(shù)據(jù)************
'************************************************
Public Function GSM_SendHEX(DataStr As String)
??? Dim DataStr_Tmp As String
??? Dim SendData() As Byte
??? Dim i As Long
????
??? '去掉字符串中的空格
??? DataStr_Tmp = DelBlank(DataStr)
??? '發(fā)送數(shù)據(jù)
??? ReDim SendData(Len(DataStr_Tmp) \ 2 - 1) As Byte
??? For i = 1 To Len(DataStr_Tmp) \ 2
??????? SendData(i - 1) = HexToDec(Mid(DataStr_Tmp, 2 * (i - 1) + 1, 2))
??? Next
????
??? FrmMain.MSComm1.Output = SendData
End Function

'************************************************
'*************以GSM按ASCII碼發(fā)送數(shù)據(jù)*************
'************************************************
Public Function GSM_SendASCII(DataStr As String)
??? Dim DataStr_Tmp As String
??? Dim SendData() As Byte
??? Dim i As Long
????
??? '去掉字符串中的空格
??? DataStr_Tmp = DelBlank(DataStr)
??? '發(fā)送數(shù)據(jù)
??? ReDim SendData(Len(DataStr_Tmp) - 1) As Byte
??? For i = 1 To Len(DataStr_Tmp)
??????? SendData(i - 1) = Asc(Mid(DataStr_Tmp, i, 1))
??? Next
????
??? FrmMain.MSComm1.Output = SendData
End Function

'************************************************
'********以GPRS按十六進制發(fā)送數(shù)據(jù) (TCP)********
'************************************************
Public Function GPRS_SendHEX_TCP(DataStr As String, IDString As String)
??? Dim DataStr_Tmp As String
??? Dim SendData() As Byte
??? Dim i As Long
????
??? '去掉字符串中的空格
??? DataStr_Tmp = DelBlank(DataStr)
??? '發(fā)送數(shù)據(jù)
??? ReDim SendData(Len(DataStr_Tmp) \ 2 - 1) As Byte
??? For i = 1 To Len(DataStr_Tmp) \ 2
??????? SendData(i - 1) = HexToDec(Mid(DataStr_Tmp, 2 * (i - 1) + 1, 2))
??? Next
??? FrmMain.Winsock2(IDString).SendData SendData
End Function

'************************************************
'*********以GPRS按ASCII碼發(fā)送數(shù)據(jù)(TCP)*********
'************************************************
Public Function GPRS_SendASCII_TCP(DataStr As String, IDString As String)
??? Dim DataStr_Tmp As String
??? Dim i As Long
????
??? '轉(zhuǎn)換數(shù)據(jù)
??? DataStr_Tmp = DataStr
????
??? FrmMain.Winsock2(IDString).SendData DataStr_Tmp
End Function

'************************************************
'********以GPRS按十六進制發(fā)送數(shù)據(jù) (UDP)********
'************************************************
Public Function GPRS_SendHEX_UDP(DataStr As String, IDString As String)
??? Dim DataStr_Tmp As String
??? Dim SendData() As Byte
??? Dim i As Long
????
??? '去掉字符串中的空格
??? DataStr_Tmp = DelBlank(DataStr)
??? '發(fā)送數(shù)據(jù)
??? ReDim SendData(Len(DataStr_Tmp) \ 2 - 1) As Byte
??? For i = 1 To Len(DataStr_Tmp) \ 2
??????? SendData(i - 1) = HexToDec(Mid(DataStr_Tmp, 2 * (i - 1) + 1, 2))
??? Next
??? FrmMain.Winsock3(IDString).SendData SendData
End Function

'************************************************
'*********以GPRS按ASCII碼發(fā)送數(shù)據(jù)(UDP)*********
'************************************************
Public Function GPRS_SendASCII_UDP(DataStr As String, IDString As String)
??? Dim DataStr_Tmp As String
??? Dim i As Long
????
??? '轉(zhuǎn)換數(shù)據(jù)
??? DataStr_Tmp = DataStr
????
??? FrmMain.Winsock3(IDString).SendData DataStr_Tmp
End Function

轉(zhuǎn)載于:https://www.cnblogs.com/MMLoveMeMM/articles/3131994.html

總結(jié)

以上是生活随笔為你收集整理的GSM-串口和GPRS-网口通信的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。