Tuesday, 1 April 2008

Controlling Parallel port with Visual Basic

Visual Basic နဲ႔ Parallel Port (LPT, Printer) ကို Control (Read, Write) လုပ္တဲ့ ပ႐ိုဂရမ္ေလးပါ။ ေမ့သြားမွာစိုးလို႔ တင္ထားတာ။ သူ႔မွာ VB Control Icon (.OCX) မရွိပါဘူး။ inpout32.dll file တစ္ခုေတာ့လိုပါတယ္။ အဲဒါက သပ္သပ္ရွာၿပီး Windows – System32 folder ထဲကိုထည့္ေပးရပါတယ္။ အင္တာနက္မွာ အမ်ားႀကီးရွိပါတယ္။ ဒီမွာ www.dll-files.com/dllindex/dll-files.shtml?inpout32 ေဒါင္းလုပ္ရင္ရပါတယ္။ သူ႔ကို System32 folder ထဲထည့္ေပးလုိက္ပါ။ ၿပီးရင္ေအာက္က Source code ေတြကို ကူးထည့္လိုက္ပါ။ Screen Design ကိုေတာ့ ေအာက္မွာျပထားတဲ့အတိုင္းလုပ္ေပါ့။ အရမ္းလြယ္ပါတယ္။ အခ်ိန္ေတြတြက္ထားတာက အပိုေတြပါ။ ျဖဳတ္ပစ္လို႔ရတယ္။

ဒါက Form Code မွာကူးထဲ့

Private Sub send_Click()

PortAddress = Val(&H37F)
Out PortAddress, Val(Text1.Text)
End Sub

Private Sub start_click()
Dim speed As Double
Dim fre As Double
Text1.Text = "0"

Dim ino As Integer
Dim GMTime As SYSTEMTIME
Dim TheTime As String
Dim a As Double, b As Double
GetSystemTime GMTime

a = GMTime.wSecond + 0.001 * GMTime.wMilliseconds
For x = 1 To 10000
PortAddress = Val(&H378)

ino = InValue(PortAddress + 1)
Next

GetSystemTime GMTime
Timer1.Interval = 1
b = GMTime.wSecond + 0.001 * GMTime.wMilliseconds
speed = 0.127 / (b - a)

Text1.Text = speed
End Sub

Private Sub stop_click()
Text1.Text = "0"
End Sub

ဒါက Module Code မွာကူးထဲ့

Public Declare Function InValue Lib "inpout32.dll" _
Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" _
Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Public Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Public Declare Function SetSystemTime Lib "kernel32" (lpSystem
Time As SYSTEMTIME) As Long

Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer

wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer

wSecond As Integer
wMilliseconds As Integer

End Type

အဲဒီမွာပါတဲ့ (&H378) က Parallel port ရဲ႕ Address ပါ။ သူက 8 Channels ရွိပါတယ္။ ေအာက္ကပံုကိုၾကည့္ပါ။ 0x378 ကေန 0x37F ဆိုေတာ့ I/O ၈ လုိင္းကို ထိန္းခ်ဳပ္လို႔ရတဲ့သေဘာေပါ့။

No comments:

Post a Comment