在 C# 中访问 GSM 调制解调器
我有一个 GSM 调制解调器,它有一个与其关联的特定命令集。我想使用我的 C# 代码调用这些命令。可以这样做吗?
GSM 调制解调器型号:MOD 9001 BENQ GSM/GPRS 调制解调器
我没有任何库可以与此调制解调器交互
I have a GSM modem which has a specific command set associated with it. I want to invoke those commands using my c# code. Is it possible to do this?
GSM modem model: MOD 9001 BENQ GSM/GPRS Modem
I dont have any library to interact with this modem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在不知道您提到的特定调制解调器的任何详细信息的情况下,与调制解调器通信的一般方法是打开串行端口连接并以纯文本方式与调制解调器通信。通常使用 Hayes 命令集的某些变体。对于 .NET,您可能需要参考 System.IO.Ports.SerialPort(请参阅 MSDN)。连接参数(波特率、数据位、停止位、奇偶校验、流量控制)取决于调制解调器,但一个好的开始是尝试 57600、8 个数据位、1 个停止位、无奇偶校验和硬件流量控制;这些是典型参数。端口的名称很大程度上取决于它与系统的连接方式,但如果您不知道,最好查看 COM 端口下的 Windows 设备管理器。
Without knowing any details for the specific modem you mention, the general approach to communicating with modems is to open a serial port connection and talk to the modem in plain text. Generally using some variant of the Hayes command set. For .NET, you might want to refer to
System.IO.Ports.SerialPort
(see MSDN). The connection parameters (baud rate, data bits, stop bits, parity, flow control) depends on the modem but a good start is to try 57600, 8 databits, 1 stop bit, no parity and hardware flow control; those are typical parameters. The name of the port is highly dependent on how its connected to your system, but a good place to look if you don't know is the Windows Device Manager under COM ports.我发现这个问题相当老了,但出于同样的原因与我自己的调制解调器作斗争。我正在使用 C# atm 访问我自己的调制解调器。
我连接到调制解调器的方式如之前提到的
System.IO.Ports.SerialPort
。您必须告诉它要连接到哪个 COM 端口。假设您安装了调制解调器的标准驱动程序并且已连接到计算机,您可以使用以下方法获取开放 COM 端口的列表:
假设您要连接到上面阵列中的第一个 COM 端口。打开端口很简单:
向调制解调器写入命令也很简单:
响应返回:
.. 只需记住将
"\r"
添加到调制解调器的所有命令的末尾。我花了一天时间才发现,为什么我的调制解调器没有响应我的命令......:-)I see this question is rather old, but fighting with my own modem with same reasons. I am using C# atm to access my own modem.
They way I connected to the modem was as mentioned before
System.IO.Ports.SerialPort
. You have to tell it which COM port to connect to.Assuming you have standard drivers for the modem installed and it is connected to computer you can get a list back of open COM ports by using:
Assuming that you want to connect to the first COM port from the array above. Opening a port is a simple as:
Writing commands to modem is as simples as:
And response is comming back on:
.. Just remember to add
"\r"
to the end of all commands to modem. Took me a day for me to find out, why-o-why my modem wasn't responding to my command... :-)通知来电:
-receivingBuffer +=serialPort1.ReadExisting();
要激活 GSM,请发送以下命令:
-serialPort1.Write("AT\r\n");
to notice incoming calls:-
recievingBuffer += serialPort1.ReadExisting();
to active your GSM send following Command:-
serialPort1.Write("AT\r\n");