Le plus simple C # manipulation messagerie GSM SMS chat chat chat 4G exemple
1, d'abord télécharger la DLL dans mes ressources fourni, tout un bon paquet
https://download.csdn.net/download/chscomfaner/12099730
2, un exemple de code:
using GSMMODEM;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace GSM_LTE_MODEM
{
class Program
{
//delegate void SmsReceive;
static GsmModem gm;
static void Main(string[] args)
{
gm = new GsmModem();
listen();
while (true)
{
Thread.Sleep(500);
}
}
static void send(string phone,string sms)
{
try
{
gm.SendMsg(phone, sms);
Console.WriteLine("发送成功");
}
catch
{
Console.WriteLine("发送失败");
return;
}
}
static void listen()
{
gm.ComPort = "COM1";
gm.BaudRate = 115200;
gm.AutoDelMsg = true;
gm.SmsRecieved += gm_SmsRecieved;
gm.Open();
if (gm.IsOpen)
{
Console.WriteLine("连接成功");
}
else
{
Console.WriteLine("设备未连接");
}
}
static void gm_SmsRecieved(object sender, EventArgs e)
{
Console.WriteLine("有新的消息");
if (gm.IsOpen)
{
try
{
DecodedMessage dm = gm.ReadNewMsg();
Console.WriteLine("手机号码:{0}\r\n短信内容:{1}\r\n发送时间:{2}" + dm.SendTime,dm.PhoneNumber,dm.SmsContent,dm.SendTime);
}
catch
{
Console.WriteLine("读取失败");
return;
}
}
}
}
}