我已经有了使用 USB 宽带套件在 VB 中向手机发送消息的工作代码。现在我正在做另一种方式,即从宽带 SIM 获取消息,这是代码:
Imports System
Imports System.IO.Ports
Public Class ReadSMS
Dim SerialPort As New System.IO.Ports.SerialPort()
Private Sub ReadNow_Click(sender As Object, e As EventArgs) Handles ReadNow.Click
If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = "COM4"
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.None
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf
SerialPort.ReadTimeout = 10000
SerialPort.Open()
If SerialPort.IsOpen() Then
Try
Debug.Print("START")
Debug.Print(SerialPort.ReadExisting)
Debug.Print("END")
Catch ex As Exception
MsgBox("read " & ex.Message)
End Try
Else
MsgBox("Port not available")
End If
End Sub
End Class
上面的代码不起作用。Debug.Print(SerialPort.ReadExisting)
即使 SIM 卡有未读消息,此行也始终返回空值。如果你能建议我做最好的事情,那可以吗?谢谢,谢谢!