Cari di Blog Ini

Jumat, 10 Februari 2012

programming PC port : difference between serial and parallel port

When I want to use ports in PC for controlling devices and reading sensor's status, there are so many options.
As a new programmer, I choose standard and old type ports like serial and parallel port.

OK, lets see the difference of those ports in programming using Visual Basic.

SERIAL PORT
Visual Basic can directly read and write Serial Port, we can write the code easily without any additional library.

Here are the VB 2008 codes for serial port:
  • SerialPort1.CDHolding
  • SerialPort1.DsrHolding
  • SerialPort1.RtsEnable
the status True if there is positive current signal get into these pins
the status False if there is negative or zero current  signal get into these pins
  • SerialPort1.DtrEnable
  • SerialPort1.CtsHolding
if enabled, the pins status  is set to True and it will have +5Volts to +15Volts current
if disabled, the pins status is set to False and it will have  -5Volts to -15Volts current 

For example :
connect the Pin 1 (CD) to Pin 4 (DTR)
write the code to Enable DTR
      SerialPort1.DtrEnable=TRUE
      SerialPort1.CDHolding = True
write the code to Disable DTR
      SerialPort1.DtrEnable=FALSE
      SerialPort1.CDHolding = False

PARALLEL PORT


The Parallel Port is divided into 3 groups of pins; Data Port, Status Port, and Control Port.

DATA PORT
How to set the bit value 0 or 1 to Data Ports ?

To send various value to Data Ports, use this method:
bit0 x 2^0 = value for D0
bit1 x 2^1 = value for D1
bit2 x 2^2 = value for D2
bit3 x 2^3 = value for D3
bit4 x 2^4 = value for D4
bit5 x 2^5 = value for D5
bit6 x 2^6 = value for D6
bit7 x 2^7 = value for D7

For example :
to set enable Data Ports 2,4, and 5, we have to calculate as follows :
Port 2 = D1
Port 4 = D3
Port 5 = D4

nilai = ( 0 x 2^0 ) + ( 1 x 2^1 ) + ( 0 x 2^2 ) + ( 1 x 2^3 ) + ( 1 x 2^4 ) + ( 0 x 2^5 ) + ( 0 x 2^6 ) + ( 0 x 2^7 )

The value of nilai is = 0 + 2 + 0 + 8 + 16 + 0 + 0 + 0 = 26

STATUS PORT and CONTROL PORT
To read the Status Port, we have to know that the Status and Control Ports value is not logical, but numbers, and the numbers vary depends on variations of active ports.
After doing some experiment, i have the numbers for Status Port as follows :
Note : $ sign is separator between numbers


  • S6 = "$63$191$31$47$55$159$175$183$15$23$39$143$151$167$7$135$"
  • S7 = "$191$255$223$239$247$159$175$183$207$215$231$143$151$167$199$135$"
  • S5 = "$31$223$95$79$87$159$15$23$207$215$71$143$151$7$199$135$"
  • S4 = "$47$239$79$111$103$175$15$39$207$231$71$143$167$7$199$135$"
  • S3 = "$55$247$87$103$119$183$23$39$215$231$71$151$167$7$199$135$"
and for Control Ports as follows:
  • C0 = "$205$207$201$203$"
  • C1 = "$206$207$202$203$"
  • C2 = "$200$201$202$203$"
The values only valid for on board LPT ports, not for additional port, like PCI to LPT port.
PCI to LPT ports only have Data Ports and Status Ports, I don't know why.
Here is the Status value for not onboard LPT port :
  • S6 = "$56$184$24$40$48$152$168$176$8$16$32$136$144$160$0$128$"
  • S7 = "$184$248$216$232$240$152$168$176$200$208$224$136$144$160$192$128$"
  • S5 = "$24$216$88$72$80$152$08$16$200$208$64$136$144$7$192$128$"
  • S4 = "$40$232$72$104$096$168$08$32$200$224$64$136$160$0$192$128$"
  • S3 = "$48$240$80$096$112$176$16$32$208$224$64$144$160$0$192$128$"


(I will attach the sample sooner)

Tidak ada komentar:

Posting Komentar