Monday, 26 September 2011

SERIAL PORT COMMUNICATION

I, in my childhood days, remained quite fascinated about how does the click or touch of a device make changes in what we see on the screen..Whenever, I started my desktop, it seemed quite amusing to hear the windows signature tune..Thus,as a child's curious brain (as mine no doubt was a very curious one) , I always used to search an answer for how do the instructions we give, are taught to the non-living parts of the computer..Now, that I learned about some interaction between the user and a hardware component via softwares, I would certainly wish to share it with you...The hardware component here is, SERIAL PORT, which is just perfect for learning purpose..And so was preferred by me even after knowing that its obsolete...But ,before understanding the serial port communication ,let us first understand:
WHAT IS A SERIAL PORT?

There are many types of I/O devices..i.e.,serial ports and parallel ports, universal serial buses (USB), graphic cards,etc..Hence, serial port is an I/O device which in return is just an interface to let the data in and out.
The special property of this device is that it transfers only one bit data at a time (contrary to what parallel ports do).Each of such a port has a 9-pin connector (in recent days) has a receive pin for receiving data and a transmit pin. The other pins are for control processes and ground. But serial port is not just a connector.I will now move forward to explain why ?
Data bits in computers flow in parallel (using many wires at a time). It converts the data from parallel to serial which is the flow of bits over a single wire.This is required for interfaces like ethernet, fireWire, USB ,etc. The flow speed of data bits is very slow in serial port connection.Therefore we connect devices like keyboard and mouse to the serial port which do not require that fast an access.

Most of the electronics of a serial port can be found on a chip called UART(Universal Asynchronous Receiver/Transmitter).UARTs are hardwares that convert parallel data to serial.
Serial ports are mainly called as RS-232 because of the standard preferred and that older PCs had this 25-pin D-type connector which was later replaced because they could not withstand high voltage levels and there was no need for 25-pins as only 9 pins were used.

Now that we have gained some information about what a serial port is, lets move on to comprehend how do they work in linux as well as in windows:

In LINUX:

Linux uses the format ttySx for naming its serial port.Identification of the serial ports present can be done by the following simple programs or commands:

display detected system's serial ports:
simply run this command on the terminal.


dmesg | grep tty


the 'setserial' wizard:

It is a program that gives us the information about the configuration of a serial port (including what I/O port the computer is using).To use this firstly install setserial by the following command:

sudo apt-get install setserial

this will then ask for your password.After authenticating, the program will be successfully installed and ready for use.Note that your PC's network connection must be enabled.


And then just type this command on the terminal:

setserial -g /dev/ttyS[0123]

(setserial command with -g option tells us which serial ports our linux box has.)

We can just view the output in the following form on the terminal which shares all information about I/O port and IRQ a serial port is using and what type of UART is it.



Now as we know the hardware part(how the system communicates to serial ports), lets get to some softwares(how can we communicate to the serial port).


The software/program which I prefer is MINICOM because its highly user-friendly and somewhat resembles TELIX in windows.Secondly,it is free with source code and runs under all unices. The version which I used is minicom-2.5.tar.gz.Firstly, we need to download this version. After downloading and saving this, we can move with the following commands:
We need to write this command on the terminal in order to install minicom:

sudo apt-get install minicom


Then to find out what our serial port connection is,do the simple command :
dmesg | grep tty


The serial ports we got are /dev/tty0.
Now ,in order to configure the minicom to establish a connection between the serial port and a cisco device ,we require to do some settings:


Type:


minicom -s

Move on to choose the serial port set-up ,further choose the device as /dev/tty0.
Change the Baud Rate to 9600(or anything which your external device supports) ,Bit Size to 8, Parity to N and the number of stop bits to 1(you can change it accordingly, only that these were the basic settings I tried out :) ).
Give a name (whatever you wish), lets say here cisco save the changes made and exit the minicom.
To use the currently set-up configuration, use this on the terminal:


minicom cisco

Thus, our serial port now matches the configuration of our cisco external device and so, the serial port connection is established.
To move about with convenience in minicom, view the many commands present to support the use via this link:
http://linux.about.com/od/commands/l/blcmdl1_minicom.htm


Moving on to windows..


In WINDOWS:


Serial ports are named after format COMx.


To check which serial port an external device is connected to in windows ,just go to "device manager" . Next, view the devices and printer, you will hence find the devices connected at that time to your system. Click on the device name and view which serial port is it connected to.


Discovering to which serial port is an external device connected:
Firstly ,right click on my computer and then select properties. Now click on the hardware tab and then click on device manager.


Click on the '+' sign on the left of "Ports(COM&LPT)" to expand it.The list of printers and serial ports available will be shown.
Communicating with some external device connected over serial port in windows and its management:


  • Firstly,find your serial port by the process of discovery of serial port as discussed above..

  • Open up Hyperterminal
Hyperterminal is a communication program that comes along with Windows.To open Hyperterminal, click on "all programs",moving on to "accessories","communications" and there you have it.The latest versions of windows may not have hyperterminal in it....It's so because it has been replaced by other functionalities...for example...you can now use phone and modem options instead..You can also use TERATERM as an alternative..To download click on the link below:



http://ttssh2.sourceforge.jp/





If you are opening it for the first time, you will be prompted to fill in informations about country and region.Fill it accordingly and go ahead.


  • Entering the serial port information

You may select the serial port to use for connecting. Set up a serial connection by specifying the name and selecting an icon.
Now, select the serial port you intend to use.In case you are not sure, try each in turn until you get the right one.

Setting connection parameters

Now we will have to set the connection speed,number of bits, parity and stop bit settings.

These are dependent on what is on the receiving end of the link. Same settings have to be used at both ends, otherwise link will not work.As an example, I have set up the connection for a speed of 9600 bits per second(Baud Rate), 8 data bits, no parity and 1 stop bit.



wwwhhhiizzzzzzz....!!!

START TYPING:

After setting up the hyperterminal correctly, click inside the hyperterminal window and press a few random keys from your keyboard...:)

Whatever you type, should get shown on the hyperterminal.





If nothing shows up, there might have been some problem during the set-up process. In that case, go back and select a different port and then follow the same process as described above.


I hope that I have been quite successful in grasping and sharing with you the idea of serial port communication..


Though obsolete, but it well serves the purpose of still hosting a large band of devices..:)

posted by:
Aparna Bharati
Jyotsana Bhardwaj

No comments:

Post a Comment