【问题标题】:How to Connect mobile with the pc如何连接手机和电脑
【发布时间】:2012-01-21 02:48:01
【问题描述】:

我正在做一个桌面学术项目,该项目的要求之一是通过短信提醒移动设备上的用户,并且此短信应由与 PC 连接的移动设备发送。我不知道我该怎么做。当我在这里进行谷歌搜索时,我得到了 gsm 调制解调器网关一种通过 pc 发送短信的解决方案。但它们不是免费的。然后诺基亚连接 SDK 是另一种方式,但它与 Visual Studio2010 不兼容。我在一个网站上得到了这个例子,但发件人最后说我的代码有错误。

Option Explicit On

Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports

Public Class form1



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.load


End Sub


Private WithEvents SMSPort As SerialPort

Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)

Public Sub New(ByRef COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
ReadThread = New Thread(AddressOf ReadPort)
End Sub

Public Function SendSMS(ByVal CellNumber As String, ByVal SMSMessage As String) As Boolean
Dim MyMessage As String = Nothing
'Check if Message Length <= 160

If SMSMessage.Length <= 160 Then
MyMessage = SMSMessage
Else
MyMessage = Mid(SMSMessage, 1, 160)
End If
If IsOpen = True Then
SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCr)
_ContSMS = False
SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
_Continue = False
RaiseEvent Sending(False)
End If
End Function

Private Sub ReadPort()
Dim SerialIn As String = Nothing
Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
Dim SMSMessage As String = Nothing
Dim Strpos As Integer = 0
Dim TmpStr As String = Nothing

While SMSPort.IsOpen = True
If (SMSPort.BytesToRead <> 0) And (SMSPort.IsOpen = True) Then
While SMSPort.BytesToRead <> 0
SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize)
SerialIn = SerialIn & System.Text.Encoding.ASCII.GetString(RXBuffer)
If SerialIn.Contains(">") = True Then
_ContSMS = True
End If
If SerialIn.Contains("+CMGS:") = True Then
_Continue = True
RaiseEvent Sending(True)
_Wait = False
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
RaiseEvent DataReceived(SerialIn)
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
End Sub

Public ReadOnly Property IsOpen() As Boolean
Get
If SMSPort.IsOpen = True Then
IsOpen = True
Else
IsOpen = False
End If
End Get
End Property

Public Sub Open()
If IsOpen = False Then
SMSPort.Open()
ReadThread.Start()
End If
End Sub

Public Sub Close()
If IsOpen = True Then
'SMSPort = New SMSCOMMS("COM1")
'SMSEngine.Open()
'SMSEngine.SendSMS("919888888888", "SMS Testing")
'SMSEngine.Close()

SMSPort.Close()
End If
End Sub

End Class

但它在 vb.net 中我没有命令。有用吗?

请给我一些想法,例如我正在使用 c sharp 在 winform 中进行操作。

【问题讨论】:

    标签: c# winforms mobile


    【解决方案1】:

    嘿,我使用了 GSMCOMM 库,它适用于我使用计算机发送和接收短信。从谷歌下载它并查看它的示例以检查它是如何工作的。 这里有一些有帮助的链接 GSMCOMM Send and recieve SMS Using GSM Modem

    from here you can download GSMCOMM library

    【讨论】:

      【解决方案2】:

      我不确定你是否想要一种连接手机的方式或一种从电脑发送短信的方式,所以我会同时提供。

      要连接到手机(如果它有数据和 android 或 IOS 或您可以直接修改代码的东西),您可以创建从 PC 到手机的套接字连接。我以前在android aps中做过这个,效果很好。

      如果您只需要从您的计算机发送短信并且您知道运营商只需使用此列表发送电子邮件http://www.mutube.com/projects/open-email-to-sms/gateway-list/

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-12
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      相关资源
      最近更新 更多