Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Parallel Port Data Pin Decoder
Author:
Bob Brandt
E-mail:
Click to e-mail author
Submitted:
12/16/2012
Version:
VB6
Compatibility:
VB6
Category:
Miscellaneous
Views:
6545
Read Parallel Port Data, Status or Control Lines Individually, Instead as just a 0 to 255 Number. Simplifies Decoding. Can Be Rewritten to Use with Vb.net
Declarations:
'none
Code:
Dim Data_From_Port as integer Data_From_Port = 111 ''any number from 0 to 255 call Parallel_Port_Data (Data_From_Port) 'Call from Port Read procedure ''=============================================== Sub Parallel_Port_Data(Data_From_Port As Integer) Dim i As Integer Dim Port_Data As Integer ''This can be modified anyway you like. Dim Binary_Number As String ''use this procedure to read Port,in normal operation Dim Data_line_High As Boolean ''This can also be used to Read Status and Control lines Dim Data_Line_Num As Integer ''Bob Brandt, Hartsburg Missouri Binary_Number = "" Port_Data = Val(Data_From_Port) 'Text1.MaxLength = 3 'Maximum Number = 255 If Port_Data > 255 Then Data_From_Port = "255" Port_Data = 255 End If 'Maximum Number = 255 If Port_Data < 1 Then Data_From_Port = "0" GoTo Ends5:14 PM 12/16/2012 End If If Port_Data > 0 Then For i = 7 To 0 Step -1 If (Port_Data And (2 ^ i)) > 0 Then Binary_Number = Binary_Number & "1" Else Binary_Number = Binary_Number & "0" End If Next i End If If Len(Binary_Number) = 8 Then For i = Len(Binary_Number) To ((Len(Binary_Number) - 7)) Step -1 Data_Line = Mid(Binary_Number, i, 1) & Data_Line Next i Else GoTo Ends End If Data_Line = Format(Data_Line, "00000000") If Len(Data_Line) = 8 Then For i = 1 To 8 If Val(Mid(Data_Line, i, 1)) > 0 Then Data_line_High = True Data_Line_Num = 9 - i Else Data_line_High = False Data_Line_Num = 9 - i End If Next i End If Ends: End Sub 'Below is used to see the Results on a form as Red(High) White(Low) ''=============================================== 'Start new Project add 2 Textboxes, and a Command Button Array 0 to 7, Set Command Buttons Style 'as Graphical,and disable Text2 textbox. then add below to Code Area of Form. Sub Text1_Change() Dim i As Integer Dim Port_Data As Integer Dim Binary_Number As String Binary_Number = "" Port_Data = Val(Text1.Text) Text1.MaxLength = 3 'Maximum Number = 255 If Port_Data > 255 Then Text1.Text = "255" Port_Data = 255 End If 'Maximum Number = 255 If Port_Data < 1 Then Text1.Text = "0" Text2.Text = "00000000" For s = 0 To 7 Form1.Command2(s).BackColor = vbWhite Next s GoTo Ends End If If Port_Data > 0 Then For i = 7 To 0 Step -1 If (Port_Data And (2 ^ i)) > 0 Then Binary_Number = Binary_Number & "1" Else Binary_Number = Binary_Number & "0" End If Next i End If If Len(Binary_Number) = 8 Then For i = Len(Binary_Number) To ((Len(Binary_Number) - 7)) Step -1 Data_Line = Mid(Binary_Number, i, 1) & Data_Line Next i Else GoTo Ends End If Data_Line = Format(Data_Line, "00000000") If Len(Data_Line) = 8 Then For i = 1 To 8 If Val(Mid(Data_Line, i, 1)) > 0 Then Form1.Command2(8 - i).BackColor = vbRed Else Form1.Command2(8 - i).BackColor = vbWhite End If Port_Data = Port_Data Next i End If Text2.Text = Data_Line Ends: End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement