Connect from my previous writings, when we set the bit with the previous way to the port that we want, then the state of other bits to be erased. For example, we want to set bit 0, but a fixed situation, but every bit we set using the command above, then the state of other bits will be 0. To handle these circumstances, we will discuss using Port_In function.
How to read data from parallel port is just as easy to send.
[Store_Variable] = port_in (Port_Address)
For example, if we want to get data from the PS (port 889), we can use the command:
Store_Variable = port_in (889)
So Store_Variable will contain the value that represents the state bits of the port 889. If we try to use a command like the above without any connect to the printer port, Store_Variable value is 31 (binary = 11 111) because if the printer port is not connected to any circuit, it will be read as a logic high (1).
Not only PS that can be read, but the DP (888) also can we read the status.
Store_Variable = port_in (888)
The above command will read the current value of port 888. We can prove it by following the program code.
Port_Out 888,88
Store_Variable = Port_In (888)
MsgBox Store_Variable
If the above program is executed, then the value 888 will appear in the message box.
Now that we can use Port_in function, we can solve problems to keep the state of a particular bit while we change the status of the other bits by using the following subroutines.
Sub Set_Bit (Port_Address, Bit_Number)
Dim Value, Port_Status, New_Value as Byte
Select case Bit_Number
Case 0: value = 1
Case 1: value = 2
Case 2: value = 4
Case 3: value = 8
Case 4: value = 16
Case 5: value = 32
Case 6: value = 64
Case 7: value = 128
case else
MsgBox “Bit_Number must be between 0 to 7″
goto Out_Range
end Select
Status_Port = Port_In (port_Address)
Nilai_Baru = Port_Status Or Value
Port_Out Port_Address, New_Value
Out_range
end Sub
With the above subroutines, now we can set a specific bit without changing the other values. Sample command below will set bit 5 of a port 888 without changing the value of the other bits.
Set_Bit 888.5
If the original value of the port 888 is 00001111, then after this command port value of 888 to 00101111.
To clear a specific bit without changing other values, we can use the following subroutines.
Sub Clear_Bit (port_Address, Bit_Number)
Dim Value, Port_Status, New_Value as Byte
Select case Bit_Number
Case 0: Value = 254
Case 1: Value = 253
Case 2: Value = 251
Case 3: Value = 247
Case 4: Value = 239
Case 5: Value = 223
Case 6: Value = 191
Case 7: Value = 127
case else
MsgBox “Bit_Number must be between 0 to 7″
goto Out_Range
end Select
Status_Port = Port_In (port_Address)
New_Value = Port_Status and Value
Port_Out Port_Address, New_Value
Out_Range:
end Sub
Subroutines above, can be used to clear a specific bit without changing the other values. Examples of this command will clear bit 5 of a port 888 without changing the other bits.
Clear_Bit 888.5
If the original value of the port 888 is 11111111, then after this command port value of 888 to 11101111.
Incoming search terms:
- vb6 lpt port tutorial
- vb6 parallel port
- parallel port programming in vb 6 0
- vb parallel port programming
- lpt port with v b
- lpt port programming vb 6 0
- vb6 lpt port programming
- printer port visual basic 6
- vb6 parallel port read
- manual visual basic 6 0 parallel port