31 st Jan to 1 st Feb 2008 TECHNOLOGY ROBOTICS SOCIETY Indian Institute of Technology, Kharagpur
31st Jan to 1st Feb 2008
TECHNOLOGY ROBOTICS SOCIETYIndian Institute of Technology, Kharagpur
Computer Control
Parallel & Serial Port Communication
PC Parallel Port - Features Commonly known as the printer port 25 pin D-Type connector It has 12 digital output pins, 5 digital input pins Pins operate at the TTL voltage level i.e. 0 – 5V Port identified by a base address in the computer
I/O memory space
PC Parallel Port – Pin Layout
PC Parallel Port – I/O Registers Most PC’s have 378 Hex base address 8 output pins are accessed via the DATA port (Base
address) 4 output pins are accessed via the CONTROL port
(Base address + 2) 5 input pins are accessed via the STATUS port (Base
address + 1)
PC Parallel Port – I/O Registers
- marked bits in register byte are unused
Accessing Parallel Port – VC ++#include <conio.h>
#define Data 0x378 // Base address#define Status 0x379 // Base address + 1#define Control 0x37a // Base address + 2
int main () {unsigned char Bits;Bits = 0b11001010;_outp(Data, Bits); /* output data */Bits = _inp(Status);/* input data */ return (0);}
PC Serial Port - Features Most commonly 9 pin D-Type connector. 25 pin D-
Type is rare Pins operate at -25 to + 25 voltage levels Data transmitted as a bit sequence Known as the EIA RS232C port or simply RS232
EIA RS232C Specifications Logic 0 is between +3 to +25 volts Logic 1 is between -3 to -25 volts -3 to +3 volts region is undefined Maximum data rate of 19,600 bps
Serial Port vs. Parallel Port Serial cables can be much longer that Parallel cables
50V swing compared to 5V swing Null Modem Configuration just needs 3 core cable
compared to 19 core parallel port cable Serial suited for wireless transmission Microcontrollers just need two pins (RXD & TXD) for
communication
Null Modem Configuration Pin 3 Transmit Data Pin 2 Receive Data Pin 5 Signal Ground Pin 4, 6, 1 shorted together Pin 7, 8 shorted together
RS-232 Waveforms
Asynchronous Communication i.e. separate clock at both ends Frame synchronization done by the start / stop bit Line is kept logic 1 when idle. Start bit is logic 0 Bit order from LSB to MSB
RS-232 Level Converters For using the RS232 data,
digital devices need TTL/CMOS voltage levels
Level conversion is done using IC MAX232 / DS232
RS-232 frame decoding The decoding of the bit sequence frame is done by
computer hardware When communicating with robots, decoding done by
onboard microcontroller Microcontroller Serial communication interface is
known as UART (Universal Asynchronous Receiver Transmitter)
Accessing Serial Port - VB MSComm Control 6.0 is used for serial port
communication
MSComm Control Properties
MSComm Control Properties Com Port identification number Settings: Baud Rate, Parity Check, Data Bits, Stop
Bits Hand Shaking Method : Xon/Xoff for null-modem
configuration
MSComm Control Properties
MSComm Control Properties InBufferSize : Input buffer size OutBufferSize : Output buffer size RThreshhold : Receive size for interrupt generation SThreshhold : Min. transmit size InputLen : Number of bytes to be picked up from the
input buffer EOFEnable : Search for EOF character
MSComm Control Properties
MSComm Control Properties ParityReplace : Parity Error replacement character NullDiscard : Null characters sent to the receive
buffer or not RTSEnable : Request to Send enable DTREnable : Data Terminal Ready
Example Code‘ Receive Data
Private Sub CommunicationTerminal_OnComm()
Dim InputBuffer As String
If CommunicationTerminal.CommEvent = comEvReceive Then
InputBuffer = CommunicationTerminal.Input
End If
‘ Use InputBuffer as per requirement
End Sub
‘ Transmit Data
If CommunicationTerminal.PortOpen = True Then
CommunicationTerminal.Output = “Hello”
End If