Home Parallel Port Serial Port Serial Info Parallel Info USB .NET Webboard I/O Today API Project Directory

 Hardware Interfacing and TCP/IP interfacing in VB programming.

Interfacing Parallel Port with Visual Basic Part 2
Thai Page Clcik Here
   Actually, getting data named "Input" from Printer Port; printer will send its signal to interface with computer in order to show status of printer, verifying for sending data to printer such as Printer Error, out of paper, ready to work, etc.

   All will connect via Printer Status Port that are port for getting input signal that are read only which differ from sending signal out to Printer Port that we will send via Data Port, 8 bit, but getting data like this will be used just 5 bit.

   Actually, Status Port has 8 bit, but the first 3 bit will not be used, 2 reserved bit and IRQ signal will not be good for getting data have 5 bit, from bit 3 - bit7, but they can be used.
   The useful of controlling device that we will use Printer Status Port may be getting signal from many devices such as switch, relay, censor, etc.

    There will be the example of connecting signal like below,

      Function we use for getting data via Printer Status Port from DLL file (Dllport.Dll) needs reference Address Printer Status Port that will be Address from Printer Data Port that is added one position such as
Address LPT1=H378 -->Status Port =H378+1=H379, etc.

       LPT1 Status=H379 (H378+1)
  LPT2 Status=H279 (H278+1)

    The example of using getting data function

Private Declare Function Inp32 Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer

   Dim StatusValue As Integer   

    StatusValue= Inp32 (&H379)

  However, programming by using several form of function, you must change Private to Public, then declare function in module file like the following;

Public  Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer

  Start programming

  First of all, you create New Project by choosing Standard EXE. VB program will create the blank form, after that clicking at Project ---> Add Module in order to create a module file, typed .BAS to declare API Function of Dll in module of visual basic, also for convenience in using with other programming, but if you will use just a form, you must not create module file. You can declare in that form.

     We will create Form, getting value from Printer Status Port in Visual Basic by clicking Control from Control Dialog, Label for showing Label 1- Label 5 and a Command Button to put in Form.
For writing code, going to View-->Code then program like below,

Option Explicit
Private Declare Function Inp Lib "Dllport.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Declare Sub Out Lib "Dllport.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

'Programming for Command button control, named Command1 in Click event.  Click

Private Sub Command1_Click()
' We will find value when there will be signal in port by using And by permanent value in Decimal Number
'like bit 0=1 | bit 1=2 | bit 2=4 | bit 3=8 | bit 4=16 | bit 5=32 | bit 6=64 | bit 7=128
'When input is 1, there will be file is about 5 Vdc to which connector, it will show permanent value as Decimal Number

   Label1.Caption = (Inp(&H379)) And 8 ' 8 ' read value of error signal at bit’s position at 3
   Label2.Caption = (Inp(&H379)) And 16 ' read value of Select signal at bit’s position at 4
   Label3.Caption = (Inp(&H379)) And 32 ' read value of Select Paper Empty at bit’s position at 5
   Label4.Caption = (Inp(&H379)) And 64 ' read value of ACK signal at bit’s position at 6
   Label5.Caption = (Inp(&H379)) And 128 ' read value of Busy signal at bit’s position at 7
' For condition that work in the case of having input signal, sending value out Data Port
   If Label1.Caption = 8 Then Out &H378, 1 ' sending signal out Data Port bit 0
   If Label2.Caption = 16 Then Out &H378, 2 ' sending signal out Data Port bit 1
   If Label3.Caption = 32 Then Out &H378, 4 ' sending signal out Data Port bit 2
   If Label4.Caption = 64 Then Out &H378, 8 ' sending signal out Data Port bit 3
   If Label5.Caption = 128 Then Out &H378, 16 ' sending signal out Data Port bit 4
End Sub

The example of program run

You can copy Source Code below, and then Paste in Notepad, then Save As the type as Form1.FRM, you will get form of this program.


The result
      From experimenting to program that get data through Printer Status Port in bit 7 will active when there will be logic signal "0" at bit 7 because we can’t put logic "1"(+5 Vdc).We must use ground for this.

    In addition, why we must And Decimal Number, from experiment at computer we use when we push the button to read value, value we read will be changed. This is the reason emphasizing on And by permanent value in Decimal Number   

Learning outcome

   1. To know how to program by using Visual Basic to control working of I/O Parallel Port
   2. To know how to apply File DLL to help you for programming due to you can’t directly program to control Visual Basic.
   3. To know how to get value of input data via Status Port of Printer Port.

Copyright (c) 2000-2008 thaiio.com all rights reserved.  Contact webmaster :webmaster@thaiio.com