Monday 3 October 2011

SERIAL PORT COMMUNICATION

Serial communication is a popular means of transmitting data between a computer and a peripheral device such as a programmable instrument or even another computer. All computer operating systems in use today support serial ports, because serial ports have been around for decades. Parallel ports are a more recent invention and are much faster than serial ports. USB ports are only a few years old, and will likely replace both serial and parallel ports completely over the next several years.

The name "serial" comes from the fact that a serial port "serializes" data. That is, it takes a byte of data and transmits the 8 bits in the byte one at a time. The advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port needs 8). The disadvantage is that it takes 8 times longer to transmit the data than it would if there were 8 wires. Serial ports lower cable costs and make cables smaller.

Before each byte of data, a serial port sends a start bit, which is a single bit with a value of 0. After each byte of data, it sends a stop bit to signal that the byte is complete. It may also send a parity bit.

Serial ports, also called communication (COM) ports, are bi-directional. Bi-directional communication allows each device to receive data as well as transmit it. Serial devices use different pins to receive and transmit data -- using the same pins would limit communication to half-duplex, meaning that information could only travel in one direction at a time. Using different pins allows for full-duplex communication, in which information can travel in both directions at once.

Figure 1: 1: RS-232 Instrument,2: RS-232 Cable, 3:Serial Port

Serial communication requires that you specify the following four parameters:

  • The baud rate of the transmission
  • The number of data bits encoding a character
  • The sense of the optional parity bit
  • The number of stop bits

Each transmitted character is packaged in a character frame that consists of a single start bit followed by the data bits, the optional parity bit, and the stop bit or bits. The figure below shows a typical character frame encoding the letter m.




Serial ports rely on a special controller chip, the Universal Asynchronous Receiver/Transmitter (UART), to function properly.

The external connector for a serial port can be either 9 pins or 25 pins. Originally, the primary use of a serial port was to connect a modem to your computer. The pin assignments reflect that. Let's take a closer look at what happens at each pin when a modem is connected.


9-pin connector:

1. Carrier Detect - Determines if the modem is connected to a working phone line.

2. Receive Data - Computer receives information sent from the modem.

3. Transmit Data - Computer sends information to the modem.

4. Data Terminal Ready - Computer tells the modem that it is ready to talk.

5. Signal Ground - Pin is grounded.

6. Data Set Ready - Modem tells the computer that it is ready to talk.

7. Request To Send - Computer asks the modem if it can send information.

8. Clear To Send - Modem tells the computer that it can send information.

9. Ring Indicator - Once a call has been placed, computer acknowledges signal (sent from modem) that a ring is detected.

25-pin connector:

1. Not Used

2. Transmit Data - Computer sends information to the modem.

3. Receive Data - Computer receives information sent from the modem.

4. Request To Send - Computer asks the modem if it can send information.

5. Clear To Send - Modem tells the computer that it can send information.

6. Data Set Ready - Modem tells the computer that it is ready to talk.

7. Signal Ground - Pin is grounded.

8. Received Line Signal Detector - Determines if the modem is connected to a working phone line.

9. Not Used: Transmit Current Loop Return (+)

10. Not Used

11. Not Used: Transmit Current Loop Data (-)

12. Not Used

13. Not Used

14. Not Used

15. Not Used

16. Not Used

17. Not Used

18. Not Used: Receive Current Loop Data (+)

19. Not Used

20. Data Terminal Ready - Computer tells the modem that it is ready to talk.

21. Not Used

22. Ring Indicator - Once a call has been placed, computer acknowledges signal (sent from modem) that a ring is detected.

23. Not Used

24. Not Used

25. Not Used: Receive Current Loop Return (-)

Voltage sent over the pins can be in one of two states, On or Off. On (binary value "1") means that the pin is transmitting a signal between -3 and -25 volts, while Off (binary value "0") means that it is transmitting a signal between +3 and +25 volts...

Managing Serial Ports in Windows

USB Cables and Connectors

Connecting a USB device to a computer is simple -- you find the USB connector on the back of your machine and plug the USB connector into it.

If it's a new device, the operator system auto-detects it and asks for the driver disk. If the device has already been installed, the computer activates it and starts talking to it. USB devices can be connected and disconnected at any time.






Discovering External Serial Ports

To check which all serial ports are connected to the computer, go to Start Menu


Then click on Devices and Printers and then select any one and view its properties.


Now to discover an External Serial Port, go to Control Panel and then select DEVICE MANAGER.

You will find a list which will have information about interfaces, biometrics, Disk Drives and COM & LPT ports as well.


Expand COM Ports option and right click on any of the serial port connections and view its properties.

In my case I have joined my SAMSUNG android phone to my computer.




You can also fiddle with its parameters in port settings by changing its Baud Rate, Data Bits, Parity and Stop Bit which will change the device’s behaviour or performance.


Click on Advanced and it will show Receive and Transmit buffer and also to which COM port it is joined to. You can also change its COM number.

LINUX

Linux offers various tools. Linux uses ttySx for a serial port device name. For example, COM1(DOS/Windows) is ttuS0, COM2 is ttyS1 and so on ...

Finding serial ports

Serial ports appear in Linux as device files, which means you can access them

conviniently with same command as e.g. text files.

1. Normal serial ports appear as /dev/ttyS#, so first is /dev/ttyS0, second

/dev/ttyS1 and so on.

2. USB to serial adapters should work out of the box (from kernel 2.4 on I think)

without any extra drivers and they appear as /dev/ttyUSB# ie. /dev/ttyUSB0

2 Serial port settings

Serial port settings can be changed using stty command. (See ”man stty”)

Example: Set serial port /dev/ttyS0 baud rate to 57600 and odd parity

stty -F /dev/ttyS0 57600 parodd

3 Reading from and writing to serial port

You can send commands to serial port using command echo:

echo "command" > /dev/ttyUSB0

And read data from serial port using cat :

cat /dev/ttyUSB0

redirect output to a file:

cat /dev/ttyUSB0 > file.txt

Task: Display Detected System's Serial Support

Simple run dmesg command
$ dmesg | grep tty




setserial command

setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on. Just type the following command:
$ setserial -g /dev/ttyS[0123]

setserial with -g option help to find out what physical serial ports your Linux box has




If Setserial is not installed then one can type

$ Sudo apt-get install setserial

Get it installed and then can further perform functions

Linux serial console programs

Once serial ports identified you can configure Linux box using various utilities:

1. minicom- The best friendly serial communication program for controlling modems and connecting to dump devices

2. wvidial or other GUI dial up networking program - a PPP dialer with built-in intelligence.

3. getty / agetty - agetty opens a tty port, prompts for a login name and invokes the /bin/login command.

4. grub / lilo configuration - To configure serial port as the system console

The following are further few commands to search whether ur ports are empty or not:



$Cd /dev

$ls

$cd bus

$ls

$usb

$ls

at last type $cd XX (your port number)


By

Aakash

Ankit Kumar

We hope it was easy to understand .

No comments:

Post a Comment