如何获取号码、消息和日期时间并显示到网格
how to get the number, message and datetime and display to grid
您好,我正在开发一个接收 SMS 的应用程序,我有通过发送 SMS 使用 AT COMMANDS 的经验。我要如何获取发件人#、消息和文本的日期时间。
port.Write("AT+CNMI=2,1,0,0,1")
Thread.Sleep(1000)
port.Write("AT+CMGF=1")
Thread.Sleep(1000)
port.Write("AT+CMGL=" & "ALL")
Thread.Sleep(1000)
receivedData = port.ReadExisting
我想像下图一样显示我的数据网格中的所有消息,但我不知道该怎么做。
dgv.Rows.Add(New String() {"", "", ""})
假设 receivedData 包含这样一个字符串
GLOBE Your balance is something 8/21/2015 7:20:35 AM
并且name/number不能包含空格,你可以像这样将三个部分分开
Dim startMessage As Integer = receivedData.IndexOf(" ")
Dim endMessage As Integer = receivedData.Substring(0, receivedData.Length - 17).LastIndexOf(" ")
Dim id, message, timestamp As String
If startMessage >=0 AndAlso endMessage > startMessage Then
id = receivedData.Substring(0, startMessage)
message = receivedData.Substring(startMessage + 1, endMessage - startMessage - 1).Trim
timestamp = receivedData.Substring(endMessage + 1)
dgv.Rows.Add({id, message, timestamp})
End If
您好,我正在开发一个接收 SMS 的应用程序,我有通过发送 SMS 使用 AT COMMANDS 的经验。我要如何获取发件人#、消息和文本的日期时间。
port.Write("AT+CNMI=2,1,0,0,1")
Thread.Sleep(1000)
port.Write("AT+CMGF=1")
Thread.Sleep(1000)
port.Write("AT+CMGL=" & "ALL")
Thread.Sleep(1000)
receivedData = port.ReadExisting
我想像下图一样显示我的数据网格中的所有消息,但我不知道该怎么做。
dgv.Rows.Add(New String() {"", "", ""})
假设 receivedData 包含这样一个字符串
GLOBE Your balance is something 8/21/2015 7:20:35 AM
并且name/number不能包含空格,你可以像这样将三个部分分开
Dim startMessage As Integer = receivedData.IndexOf(" ")
Dim endMessage As Integer = receivedData.Substring(0, receivedData.Length - 17).LastIndexOf(" ")
Dim id, message, timestamp As String
If startMessage >=0 AndAlso endMessage > startMessage Then
id = receivedData.Substring(0, startMessage)
message = receivedData.Substring(startMessage + 1, endMessage - startMessage - 1).Trim
timestamp = receivedData.Substring(endMessage + 1)
dgv.Rows.Add({id, message, timestamp})
End If