karthik
karthik

Reputation:

Accessing GSM Modem in C#

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

Upvotes: 1

Views: 5030

Answers (3)

vipul kapoor
vipul kapoor

Reputation: 1

    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");

Upvotes: 0

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

Upvotes: 1

user116587
user116587

Reputation:

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.

Upvotes: 1

Related Questions