在 C# 中访问 GSM 调制解调器

发布于 2024-08-03 20:27:38 字数 139 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

归属感 2024-08-10 20:27:38

在不知道您提到的特定调制解调器的任何详细信息的情况下,与调制解调器通信的一般方法是打开串行端口连接并以纯文本方式与调制解调器通信。通常使用 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.

假扮的天使 2024-08-10 20:27:38

我发现这个问题相当老了,但出于同样的原因与我自己的调制解调器作斗争。我正在使用 C# atm 访问我自己的调制解调器。

我连接到调制解调器的方式如之前提到的System.IO.Ports.SerialPort。您必须告诉它要连接到哪个 COM 端口。

假设您安装了调制解调器的标准驱动程序并且已连接到计算机,您可以使用以下方法获取开放 COM 端口的列表:

string[] com_ports = SerialPort.GetPortNames();

假设您要连接到上面阵列中的第一个 COM 端口。打开端口很简单:

SerialPort port = new SerialPort();
port.portname = com_ports[0];
// ... Insert other port parameters
port.Open();

向调制解调器写入命令也很简单:

port.write("some command");

响应返回:

String response = port.ReadExisting();

.. 只需记住将 "\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:

string[] com_ports = SerialPort.GetPortNames();

Assuming that you want to connect to the first COM port from the array above. Opening a port is a simple as:

SerialPort port = new SerialPort();
port.portname = com_ports[0];
// ... Insert other port parameters
port.Open();

Writing commands to modem is as simples as:

port.write("some command");

And response is comming back on:

String response = port.ReadExisting();

.. 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... :-)

任谁 2024-08-10 20:27:38
    serialPort1 = new EnhancedSerialPort();
    serialPort1.PortName ="COM 11";  // check it in your case
    serialPort1.BaudRate = 115200; //suggested
    recievingBuffer = "";
    serialPort1.ReadTimeout = 400;
    serialPort1.WriteTimeout = 400;

通知来电:

-receivingBuffer +=serialPort1.ReadExisting();

要激活 GSM,请发送以下命令:

-serialPort1.Write("AT\r\n");

    serialPort1 = new EnhancedSerialPort();
    serialPort1.PortName ="COM 11";  // check it in your case
    serialPort1.BaudRate = 115200; //suggested
    recievingBuffer = "";
    serialPort1.ReadTimeout = 400;
    serialPort1.WriteTimeout = 400;

to notice incoming calls:-

recievingBuffer += serialPort1.ReadExisting();

to active your GSM send following Command:-

serialPort1.Write("AT\r\n");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文