想要使用GSM mobile接收msg / read msg [英] Want to recieve a msg/read msg using GSM mobile
本文介绍了想要使用GSM mobile接收msg / read msg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是发送消息的代码,但我想接收或读取来自SIM卡的消息。发送消息代码如下:
Here is code for sending msgs, but i want to recieve or read msgs from sim card. Sending msgs code is given below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
loadPorts();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void loadPorts()
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
cboPorts.Items.Add(port);
}
}
private void cboPorts_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SmsClass sm = new SmsClass(cboPorts.Text);
sm.Opens();
sm.sendSms(txtPhone.Text, txtMessage.Text);
sm.Closes();
MessageBox.Show("Message Sent!");
}
private void AddMobNo_Click(object sender, EventArgs e)
{
ListBoxNumbers.Items.Add(tbGMobNo.Text);
tbGMobNo.Text = "";
}
private void btnSendGrouped_Click(object sender, EventArgs e)
{
SmsClass sm = new SmsClass(cboPorts.Text);
for (int a = 0; a <= ListBoxNumbers.Items.Count - 1; a++)
{
//SmsClass sm = new SmsClass(cboPorts.Text);
//sm.Opens();
//sm.sendSms(ListBoxNumbers.Items[a].ToString(), GtxtMessage.Text);
//sm.Closes();
//MessageBox.Show("Message Sent Successfully");
sm.Opens();
sm.sendSms(ListBoxNumbers.Items[a].ToString(), GtxtMessage.Text);
sm.Closes();
Thread.Sleep(10000);
MessageBox.Show("Message Sent Successfully");
}
sm = null;
}
}
}
这是SmsClass
here is the SmsClass
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO.Ports;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class SmsClass
{
SerialPort serialPort;
public SmsClass(string comPort)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = comPort;
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;// Databits are the number of bits in the stream which can be 8 for binary transfer or 7 for text transfer
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;// Handshake is a protocol between the sender and receiver for determining the data transfer correctness
this.serialPort.DtrEnable = true;//Gets or sets a value that enables the Data Terminal Ready
this.serialPort.RtsEnable = true;//Gets or sets a value indicating whether the Request to Send
this.serialPort.NewLine = System.Environment.NewLine;
}
public bool sendSms(string cellNo, string sms)
{
string messages = null;
messages = sms;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT" + (char)(13));
Thread.Sleep(4);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(5);
this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
Thread.Sleep(10);
this.serialPort.WriteLine(">" + messages + (char)(26));
}
catch (Exception ex)
{
MessageBox.Show(ex.Source);
}
return true;
}
else
return false;
}
public void Opens()
{
if (this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
public void Closes()
{
if (this.serialPort.IsOpen == true)
{
this.serialPort.Close();
}
}
}
}
已添加代码块[/编辑]
Code block added[/Edit]
推荐答案
需要注意的是,您可以通过任何支持AT命令的手机发送消息。您可以通过蓝牙,有线电视等任何与PC连接的手机发送。
大部分手机都不支持接收。你需要一个GSM调制解调器(我重复一个GSM调制解调器设备)这样做。
如果你想用手机做,这是我成功测试接收的唯一电缆是 CA-42电缆和少数诺基亚型号。
我已经完成了GSM调制解调器的一些广泛工作,包括将其与CRM解决方案集成。所以你可以接受我的话。
Point to be noted that, you can send message via any phone that supports AT command. You can send it through a phone which is connected with PC via bluetooth, cable, anything.
Receiving is not supported by most of the phones. You need a GSM modem ( I repeat a GSM Modem device) for doing this.
If you want to do it with phones, the only cable that i successfully tested receiving is CA-42 cable and few models of Nokia.
I have done some extensive works with GSM modem including, integrating it with CRM solutions. so you can take my words on this.
这篇关于想要使用GSM mobile接收msg / read msg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文