vb code to control parallel port

A

Thread Starter

Anonymous

hi everybody,

i need some vb code to control the parallel port (open, read, close and write port). i would like to request if anybody has the source code of the program in vb to control the parallel port or example. kindly send it to my email (sumieshalu [at] hotmail dot com / sumithra dot devi [at] jusco dot com dot my.

thank you.
 
'Declare functions in the dynamic link library
'Declared functions: Centronic(), Inputbyte(), Write_port() and write_control()
Private Declare Function Centronic Lib "c:\windows\system\w8255dll.dll" (ByVal X As Integer) As Integer
Private Declare Function Write_control Lib "c:\windows\system\w8255dll.dll" (ByVal P_address As Integer, ByVal
Output_data As Integer) As Integer
Private Declare Function Write_port Lib "c:\windows\system\w8255dll.dll" (ByVal P_address As Integer, ByVal
address As Integer, ByVal Output_data As Integer) As Integer
Private Declare Function Inputbyte Lib "c:\windows\system\w8255dll.dll" (ByVal P_address As Integer, ByVal address
As Integer) As Integer
Dim status(30) As Integer
Dim P_address As Integer
Function bit_weight(bitnumber As Integer)
If bitnumber = 1 Then bit_weight = 1
If bitnumber = 2 Then bit_weight = 2
If bitnumber = 3 Then bit_weight = 4
If bitnumber = 4 Then bit_weight = 8
If bitnumber = 5 Then bit_weight = 16
If bitnumber = 6 Then bit_weight = 32
If bitnumber = 7 Then bit_weight = 64
If bitnumber = 8 Then bit_weight = 128
End Function
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = " Get the status of the Status port inputs (4 inputs)"
End Sub
Private Sub Command2_Click(Index As Integer)
'Change status of the outputs of Data port and Control port
status(Index) = 1 - status(Index) 'toggle action
If status(Index) = 1 Then Shape1(Index).BackColor = &HFF& Else Shape1(Index).BackColor = black 'output status
to the virtual LEDs
End Sub
Private Sub Command2_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'show on-line help when mouse pointer movers across the buttons
If Index <= 7 Then
Label3.Caption = " Change status of port A outputs (8 outputs)"
End If
If Index > 7 And Index < 15 Then
Label3.Caption = " Change status of port B outputs (8 outputs)"
End If
End Sub
Private Sub Command3_Click()
'Re-select a Centronic port
dummy = MsgBox(Str(Centronic(0)) - 1 & " Centronic ports (LPTs) are installed on your PC. Their base
addresses are: " & Format$(Centronic(1), "###") & " " & Format$(Centronic(2), "###") & " " &
Format$(Centronic(3), "###") & " " & Format$(Centronic(4), "###") & "Decimal", 48, "Centronic ports (LPT) on
your PC") 'show information on installed LPTs
lpt_number = Val(InputBox$("Input 1, 2, 3 or 4 to select a Centronic port (LPT) for the Mini-Lab Data Logger/
Controller", "Select LPT ports")) 'Select a Centronic port
P_address = Centronic(lpt_number) 'find the base address of the selected LPT port
dummy = Write_control(P_address, 137) 'Configure the 8255, port A and B as outputs, port C as input
Label2(0).Caption = "Selected LPT port : " & Format(lpt_number) 'show the information on the selected
LPT port
Label4(0).Caption = "Base address of LPT: " & Format(P_address) 'show the information of the selected LPT
port
End Sub
Private Sub Command3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'show on-line help when mouse pointer moves across the button
Label3.Caption = "Re-select Centronic port"
End Sub

Private Sub Command4_Click()
'Quit the program
End
End Sub
Private Sub Command4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = " Quit the program"
End Sub
Private Sub Command5_Click()
'Output data to the Data port
Output_byte = 0
For i = 0 To 7
Output_byte = Output_byte + status(i) * bit_weight(i + 1) 'form a byte to be output
Next i
dummy = Write_port(P_address, 0, Output_byte) 'Output the byte to the Data port
'Output data to the Data port
Output_byte = 0
For i = 8 To 15
Output_byte = Output_byte + status(i) * bit_weight(i - 7) 'form a byte to be output
Next i
dummy = Write_port(P_address, 1, Output_byte) 'output the byte to the Control port
input_byte = Inputbyte(P_address, 2)
For i = 16 To 23
status(i) = (input_byte And bit_weight(i - 15)) / bit_weight(i - 15)
If status(i) = 1 Then Shape1(i).BackColor = &HFF& Else Shape1(i).BackColor = black
Next i
End Sub
Private Sub Command5_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = " Output data to Port A and Port B and read data from Port C"
End Sub
Private Sub Form_Load()
'initialize status()
'show Centronic port information and allow user to select an LPT
dummy = MsgBox(Str(Centronic(0) - 1) & " Centronic ports (LPTs) are installed on your PC. Their base
addresses are: " & Format$(Centronic(1), "###") & " " & Format$(Centronic(2), "###") & " " &
Format$(Centronic(3), "###") & " " & Format$(Centronic(4), "###") & "Decimal", 48, "Centronic ports (LPT) on
your PC")
lpt_number = Val(InputBox$("Input 1, 2, 3 or 4 to select a Centronic port (LPT) for the Centronic Experimental
board", "Select LPT ports"))
P_address = Centronic(lpt_number)
For i = 0 To 11
status(i) = 0
Next i
dummy = Write_control(P_address, 137) 'Configure the 8255, port A and B as outputs, port C as input
Label2(0).Caption = "No of installed LPTs: " & Format(lpt_number)
Label4(0).Caption = "Address of LPT: " & Format(P_address)
End Sub
Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = "Select output status of Port A"
End Sub
Private Sub Frame2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = "Select output status of Port B"
End Sub
Private Sub Frame3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label3.Caption = "View status of Port C"
End Sub
 
Top