GSM modem access in C #
Without knowing the details of the particular modem you are talking about, the general approach to communicating with modems is to open a serial port connection and talk to the modem in plain text. Typically some variant of the Hayes command set is used . For .NET, you can refer to System.IO.Ports.SerialPort
(see MSDN ). Connection parameters (baud rate, data bit, stop bits, parity, flow control) are modem dependent, but a good start is to try 57600, 8 data bits, 1 stop bit, parity and hardware flow; these are typical parameters. The port name depends a lot on how it relates to your system, but a good place to look if you don't know is Windows Device Manager in COM ports.
source to share
I see this question is quite old, but it is still struggling with my modem. I am using C # atm to access my modem.
The way I connected to the modem was as above System.IO.Ports.SerialPort
. You have to tell which COM port to connect to.
Assuming you have the standard drivers for the installed modem installed and it is connected to your computer, you can get a list of open COM ports using:
string[] com_ports = SerialPort.GetPortNames();
Assuming you want to connect to the first COM port from the above array. Port opening is simple as:
SerialPort port = new SerialPort();
port.portname = com_ports[0];
// ... Insert other port parameters
port.Open();
Writing commands to the modem is done in the same way as:
port.write("some command");
And the answer comes back:
String response = port.ReadExisting();
.. Do not forget to add "\r"
to the end of all commands to the modem. Took me a day to find out for some reason why my modem didn't respond to my command ... :-)
source to share
serialPort1 = new EnhancedSerialPort();
serialPort1.PortName ="COM 11"; // check it in your case
serialPort1.BaudRate = 115200; //suggested
recievingBuffer = "";
serialPort1.ReadTimeout = 400;
serialPort1.WriteTimeout = 400;
to notify about incoming calls: -
recievingBuffer + = serialPort1.ReadExisting ();
to activate your GSM sending of the following command: -
serialPort1.Write ("AT \ r \ n");
source to share