Synchrounous Serial Communication..
Hi,
i'm trying to connect to my GSM Modem on COM1 interface using.Net 2.0 Control "System.IO.Ports.SerialPort".
Now, what I wish to do is send a series of AT Commands to my modem device. But for which I need to wait for a response from modem for recent AT Command.So I want to have synchronization in this.
I havertsEnable=true and i am performingBusyWaiting forctsHoldingas following between two successive commands..
While not myPort.ctsHolding
End While
case:
send AT Command 1
wait for response AT Command 1 response
send AT Command 2
wait for response AT Command 1 response
and vice versa.....
plz let me know how to perform this kind of synchronization..
thanks..
Ruchit Surati.
[883 byte] By [
s_ruchit] at [2007-12-23]
hi nobugz,
thanks for your prompt reply...
but consider these cases..
1.) last charactr of all modem responses need not be same.. it may be "OK" or "ERROR" or something else in diff. modems.
2.) I cant use readline, As i'm suppose to use readExisting.
plz review these points and revert back to me..
i need a flow control technique..
i know it can be done using RequestToSend & ClearToSend mechanism in System.IO.Ports.SerialPort.rtsEnable & System.IO.Ports.SerialPort.ctsHolding, but i need to have proper technique to use it...
thanks, once again..
Ruchit Surati,
The problem with CTS is that a standard 16C550 PC UART do NOT have auto flow control - except for UART's from Texas Instruments. It is crazy, They have implemented a very complicated transmitter FIFO, but forgotten the last AND-gate, which is necessary to make it work!!! No matter the state of CTS, the UART will empty the transmitter FIFO, so if the receiver is not able to receive at least 16 bytes of data at the wanted speed, you must send one character at a time. You may also use a PCI-card or USB adaptor with a 16C650, 16C750, 16C850 or 16C950 UART, which all have auto flow control.
Since a modem - as the name says - is usually only a modulator/demodulator it will usually be able to follow the data stream, so testing the modem control signals may not be that important. After a short power-up period it will be ready to transmit data without CTS going low. Only in case of modems, which receive the data to be transmitted at a higher speed than the transmission speed, it is necessary to take CTS into consideration.
Generally, using busy wait is NOT the way to do things - especially not in an event driven environment like VB.NET. Instead you may declare the serial port "Dim WithEvents ..." and use subroutines to handle a change in the state of the modem control lines and to receive data from the modem. However, you should be aware that the serial port runs on a different thread than the user interface, so it may be necessary to use BeginInvoke or Invoke. In the knowledgebase on our homepage you may find a small program for serial port communication including source code and documentation, which shows how to use BeginInvoke. It also shows how to read the data and the modem control signals event driven.
The URL is: http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm
We regret that we do not have a program for polled communication since this is what you need, but you may use our program for inspiration.
Best regards,
Innovatic, Carsten Kanstrup