พอร์ตขนานหรือ Parallel Port นั้นเดิมเรียกว่า Printer Port
พอร์ตขนานหรือ Parallel Port นั้นเดิมเรียกว่า Printer Port เพราะการใช้งานส่วนใหญ่กับพอร์ตขนาน เป็นการใช้งาน โดยการต่อกับเครื่องพรินเตอร์เป็นหลัก โดยที่พอร์ตขนานนั้น สามารถให้ความเร็วในการส่งผ่านข้อมูลได้รวดเร็วกว่า พอร์ตอนุกรมราว 8 ถึง 10 เท่า และยังสามารถส่งข้อมูลขนาน 8 บิตออกไปได้โดยตรง
พอร์ตขนานของเครื่องคอมพิวเตอร์ประกอบด้วยสัญญาณทั้งหมด 25 เส้นสัญญาณ โดยสัญญาณจะแบ่งออกได้เป็น 3 กลุ่มใหญ่ๆ ตามลักษณะหน้าที่ของสัญญาณ ประกอบด้วย
1. Data Port จำนวน 8 เส้นสัญญาณ
2. Status Port จำนวน 5 เส้นสัญญาณ
3. Control Port จำนวน 4 เส้นสัญญาณ
งานที่ 1โปรแกรมส่งข้อมูลออกสู่พอร์ตขนาน
Private Declare Sub Out Lib "DllPort.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Command1_Click()
Out &H378&, &H1&
End Sub
Private Sub Command2_Click()
Out &H378&, &H2&
End Sub
Private Sub Command3_Click()
Out &H378&, &H4&
End Sub
Private Sub Command4_Click()
Out &H378, &H8&
End Sub
Private Sub Command5_Click()
Out &H378&, &HCC8&
End Sub
Private Sub Command6_Click()
Out &H378&, &H6&
End Sub
การติดต่อพอ์ตขนานด้วย visual Basic
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนานที่ LED 1
งานที่ 2 โปรแกรมรับ Input จาก Swict
งานที่ 3 โปรแกรมรับข้อมูลจาก parallelport
งานที่ 4 โปรแกรมคิวอัตโนมัติ
งานที่ 5 โปรแกรมตั้งเวลาทำงานของ contrack
งานที่ 6 โปรแกรมสเต็ปมอเตอร์
งานที่4 คิวอัตโนมัติ
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m, o, p As Integer
Private Sub Label1_Click()
Dim n, m, p As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
If p < m Then
Select Case n
Case Is = 255
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ1"
Case Is = 63
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ2"
Case Is = 119
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ3"
End Select
Else
Label4.Caption = p
Label5.Caption = "ËÁ´¤ÔÇ"
End If
End Sub
การติดต่อพอ์ตขนานด้วย visual Basic
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนานที่ LED 1
Private Declare Sub Out Lib "Dllport.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer) (ประกาศใช้ฟังก์ชัน)
Private Sub Command1_Click()
Out &H378&, &H1& (เงื่อนไข เมื่อกดสวิตช์ LED 0 ทำให้LED 0 ติดสว่าง)
End Sub
Private Sub Command2_Click()
Out &H378&, &H2& (เงื่อนไข เมื่อกดสวิตช์ LED 1 ทำให้LED1 ติดสว่าง)
End Sub
Private Sub Command3_Click()
Out &H378&, &H4& (เงื่อนไข เมื่อกดสวิตช์ LED 2 ทำให้LED 2 ติดสว่าง)
End Sub
Private Sub Command4_Click()
Out &H378&, &H8& (เงื่อนไข เมื่อกดสวิตช์ LED3 ทำให้LED1 ติดสว่าง)
End Sub
Private Sub Command5_Click()
Out &H378&, &HC8& (เงื่อนไข เมื่อกดสวิตช์ LED367ทำให้LED367ติดสว่าง)
End Sub
Private Sub Command6_Click()
Out &H378&, &HA4& (เงื่อนไข เมื่อกดสวิตช์ LED257ทำให้LED257 ติดสว่าง)
End Sub
งานที่ 2 โปรแกรมรับ Input จาก Swict
งานที่ 3 โปรแกรมรับข้อมูลจาก parallelport
งานที่ 4 โปรแกรมคิวอัตโนมัติ
งานที่ 5 โปรแกรมตั้งเวลาทำงานของ contrack
งานที่ 6 โปรแกรมสเต็ปมอเตอร์
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนานที่ LED1
Private Declare Sub Out Lib "DllPort.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Command1_Click()
Out &H378&, &H1&
End Sub
Private Sub Command2_Click()
Out &H378&, &H2&
End Sub
Private Sub Command3_Click()
Out &H378&, &H4&
End Sub
Private Sub Command4_Click()
Out &H378, &H8&
End Sub
Private Sub Command5_Click()
Out &H378&, &HCC8&
End Sub
Private Sub Command6_Click()
Out &H378&, &H6&
End Sub
งานที่ 2 รับ Input จาก swict
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Sub Label1_Click()
Dim n As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
End Sub
งานที่ 3 รับข้อมูลจาก parallelport
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m As Integer
Private Sub Label1_Click()
Dim n, m As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
End Sub
งานที่ 4 คิวอัตโนมัติ
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m, o, p As Integer
Private Sub Label1_Click()
Dim n, m, p As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
If p < m Then
Select Case n
Case Is = 255
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ1"
Case Is = 63
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ2"
Case Is = 119
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ3"
End Select
Else
Label4.Caption = p
Label5.Caption = "ËÁ´¤ÔÇ"
End If
End Sub
งานที่ 5 ตั้งเวลาทำงานของ contrack
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)
Public pwrite As Integer
Private Sub Form_Load()
Label1.Caption = "Relay1"
Label2.Caption = "Relay2"
Label3.Caption = "Relay3"
Label4.Caption = "Relay4"
Label5.Caption = "Relay5"
Label6.Caption = "Relay6"
Label7.Caption = "Relay7"
Label8.Caption = "Relay8"
Label10.Caption = "Alarm Time"
Label11.Caption = "Alarm delay (sec)"
Label9.FontBold = True
Text1.Alignment = 2
Text2.Alignment = 2
Text3.Alignment = 2
Text4.Alignment = 2
Text5.Alignment = 2
Text6.Alignment = 2
Text7.Alignment = 2
Text8.Alignment = 2
Text9.Alignment = 2
Text10.Alignment = 2
Text11.Alignment = 2
Text12.Alignment = 2
Text13.Alignment = 2
Text14.Alignment = 2
Text15.Alignment = 2
Text16.Alignment = 2
Text1.Text = "00:00:00"
Text3.Text = "00:00:00"
Text5.Text = "00:00:00"
Text7.Text = "00:00:00"
Text9.Text = "00:00:00"
Text11.Text = "00:00:00"
Text13.Text = "00:00:00"
Text15.Text = "00:00:00"
Text2.Text = "0"
Text4.Text = "0"
Text6.Text = "0"
Text8.Text = "0"
Text10.Text = "0"
Text12.Text = "0"
Text14.Text = "0"
Text16.Text = "0"
Timer1.Interval = 1000
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer4.Interval = 1000
Timer5.Interval = 1000
Timer6.Interval = 1000
Timer7.Interval = 1000
Timer8.Interval = 1000
Timer9.Interval = 1000
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
Timer5.Enabled = False
Timer6.Enabled = False
Timer7.Enabled = False
Timer8.Enabled = False
pwrite = &H378
Out pwrite, &H0
End Sub
Private Sub Timer1_Timer()
Text2.Text = Text2.Text - 1
If Val(Text2.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H1
Text2.Text = "0"
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
Text4.Text = Text4.Text - 1
If Val(Text4.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H2
Text4.Text = "0"
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
Text6.Text = Text6.Text - 1
If Val(Text6.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H4
Text6.Text = "0"
Timer3.Enabled = False
End If
End Sub
Private Sub Timer4_Timer()
Text8.Text = Text8.Text - 1
If Val(Text8.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H8
Text8.Text = "0"
Timer4.Enabled = False
End If
End Sub
Private Sub Timer5_Timer()
Text10.Text = Text10.Text - 1
If Val(Text10.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H10
Text10.Text = "0"
Timer5.Enabled = False
End If
End Sub
Private Sub Timer6_Timer()
Text12.Text = Text12.Text - 1
If Val(Text12.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H20
Text12.Text = "0"
Timer6.Enabled = False
End If
End Sub
Private Sub Timer7_Timer()
Text14.Text = Text14.Text - 1
If Val(Text14.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H40
Text14.Text = "0"
Timer7.Enabled = False
End If
End Sub
Private Sub Timer8_Timer()
Text16.Text = Text16.Text - 1
If Val(Text16.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H80
Text16.Text = "0"
Timer8.Enabled = False
End If
End Sub
Private Sub Timer9_Timer()
Label9.Caption = Time$
If Label9.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H1
Timer1.Enabled = True
End If
If Label9.Caption = Text3.Text Then
Out pwrite, Inp(pwrite) Xor &H2
Timer2.Enabled = True
End If
If Label9.Caption = Text5.Text Then
Out pwrite, Inp(pwrite) Xor &H4
Timer3.Enabled = True
End If
If Label9.Caption = Text7.Text Then
Out pwrite, Inp(pwrite) Xor &H8
Timer4.Enabled = True
End If
If Label9.Caption = Text9.Text Then
Out pwrite, Inp(pwrite) Xor &H10
Timer5.Enabled = True
End If
If Label9.Caption = Text11.Text Then
Out pwrite, Inp(pwrite) Xor &H20
Timer6.Enabled = True
End If
If Label9.Caption = Text13.Text Then
Out pwrite, Inp(pwrite) Xor &H40
Timer7.Enabled = True
End If
If Label9.Caption = Text15.Text Then
Out pwrite, Inp(pwrite) Xor &H80
Timer8.Enabled = True
End If
End Sub
งานที่ 6 ตั้งเวลาทำงานของ contrack
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)
Public pwrite As Integer
Private Sub Form_Load()
Label1.Caption = "Relay1"
Label2.Caption = "Relay2"
Label5.Caption = "Alarm Time"
Label4.Caption = "Alarm delay (sec)"
Label3.FontBold = True
Text1.Alignment = 2
Text2.Alignment = 2
Text3.Alignment = 2
Text4.Alignment = 2
Text1.Text = "00:00:00"
Text3.Text = "00:00:00"
Text2.Text = "0"
Text4.Text = "0"
Timer1.Interval = 1000
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer1.Enabled = False
Timer2.Enabled = False
pwrite = &H378
Out pwrite, &H0
End Sub
Private Sub Timer1_Timer()
Text2.Text = Text2.Text - 1
If Val(Text2.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H1
Text2.Text = "0"
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
Text4.Text = Text4.Text - 1
If Val(Text4.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H2
Text4.Text = "0"
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
Label3.Caption = Time$
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H1
Timer1.Enabled = True
End If
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H2
Timer2.Enabled = True
End If
If Label3.Caption = Text3.Text Then
Out pwrite, Inp(pwrite) Xor &H4
Timer3.Enabled = True
End If
End Sub
งานที่ 7 สเต็ปมอเตอร์
Private Declare Sub Out Lib "DLLPORT.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public pwrite As Integer
Public t As Integer
Private Sub Command1_Click()
Do
DoEvents
Out pwrite, &H8
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H1
Sleep (t)
Loop
End Sub
Private Sub Command2_Click()
Do
DoEvents
Out pwrite, &H1
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H8
Sleep (t)
Loop
End Sub
Private Sub Form_Load()
Command1.Caption = "<- Reverse"
Command2.Caption = "Forward ->"
HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.Value = 50
Timer1.Interval = 1000
pwrite = &H378
End Sub
Private Sub Timer1_Timer()
t = HScroll1.Value
End Sub
งานที่ 6 โปรแกรมสเต็ปมอเตอร์
Private Declare Sub Out Lib "DLLPORT.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public pwrite As Integer
Public t As Integer
Private Sub Command1_Click()
Do
DoEvents
Out pwrite, &H8
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H1
Sleep (t)
Loop
End Sub
Private Sub Command2_Click()
Do
DoEvents
Out pwrite, &H1
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H8
Sleep (t)
Loop
End Sub
Private Sub Form_Load()
Command1.Caption = "<- Reverse"
Command2.Caption = "Forward ->"
HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.Value = 50
Timer1.Interval = 1000
pwrite = &H378
End Sub
Private Sub Timer1_Timer()
t = HScroll1.Value
End Sub
งานที่ 4 โปรแกรมคิวอัตโนมัติ
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m, o, p As Integer
Private Sub Label1_Click()
Dim n, m, p As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
If p < m Then
Select Case n
Case Is = 255
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ1"
Case Is = 63
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ2"
Case Is = 119
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ3"
End Select
Else
Label4.Caption = p
Label5.Caption = "ËÁ´¤ÔÇ"
End If
End Sub
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนานที่ LED1
Private Declare Sub Out Lib "DllPort.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Command1_Click()
Out &H378&, &H1&
End Sub
Private Sub Command2_Click()
Out &H378&, &H2&
End Sub
Private Sub Command3_Click()
Out &H378&, &H4&
End Sub
Private Sub Command4_Click()
Out &H378, &H8&
End Sub
Private Sub Command5_Click()
Out &H378&, &HCC8&
End Sub
Private Sub Command6_Click()
Out &H378&, &H6&
End Sub
งานที่ 2 รับ Input จาก swict
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Sub Label1_Click()
Dim n As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
End Sub
งานที่ 3 รับข้อมูลจาก parallelport
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m As Integer
Private Sub Label1_Click()
Dim n, m As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
End Sub
งานที่ 4 คิวอัตโนมัติ
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m, o, p As Integer
Private Sub Label1_Click()
Dim n, m, p As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
If p < m Then
Select Case n
Case Is = 255
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ1"
Case Is = 63
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ2"
Case Is = 119
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ3"
End Select
Else
Label4.Caption = p
Label5.Caption = "ËÁ´¤ÔÇ"
End If
End Sub
งานที่ 5 ตั้งเวลาทำงานของ contrack
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)
Public pwrite As Integer
Private Sub Form_Load()
Label1.Caption = "Relay1"
Label2.Caption = "Relay2"
Label5.Caption = "Alarm Time"
Label4.Caption = "Alarm delay (sec)"
Label3.FontBold = True
Text1.Alignment = 2
Text2.Alignment = 2
Text3.Alignment = 2
Text4.Alignment = 2
Text1.Text = "00:00:00"
Text3.Text = "00:00:00"
Text2.Text = "0"
Text4.Text = "0"
Timer1.Interval = 1000
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer1.Enabled = False
Timer2.Enabled = False
pwrite = &H378
Out pwrite, &H0
End Sub
Private Sub Timer1_Timer()
Text2.Text = Text2.Text - 1
If Val(Text2.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H1
Text2.Text = "0"
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
Text4.Text = Text4.Text - 1
If Val(Text4.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H2
Text4.Text = "0"
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
Label3.Caption = Time$
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H1
Timer1.Enabled = True
End If
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H2
Timer2.Enabled = True
End If
If Label3.Caption = Text3.Text Then
Out pwrite, Inp(pwrite) Xor &H4
Timer3.Enabled = True
End If
End Sub
งานที่ 6 สเต็ปมอเตอร์
Private Declare Sub Out Lib "DLLPORT.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public pwrite As Integer
Public t As Integer
Private Sub Command1_Click()
Do
DoEvents
Out pwrite, &H8
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H1
Sleep (t)
Loop
End Sub
Private Sub Command2_Click()
Do
DoEvents
Out pwrite, &H1
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H8
Sleep (t)
Loop
End Sub
Private Sub Form_Load()
Command1.Caption = "<- Reverse"
Command2.Caption = "Forward ->"
HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.Value = 50
Timer1.Interval = 1000
pwrite = &H378
End Sub
Private Sub Timer1_Timer()
t = HScroll1.Value
End Sub
งานที่ 3 โปรแกรมรับข้อมูลจาก parallelport
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m As Integer
Private Sub Label1_Click()
Dim n, m As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
End Sub
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนานที่ LED1
Private Declare Sub Out Lib "DllPort.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Command1_Click()
Out &H378&, &H1&
End Sub
Private Sub Command2_Click()
Out &H378&, &H2&
End Sub
Private Sub Command3_Click()
Out &H378&, &H4&
End Sub
Private Sub Command4_Click()
Out &H378, &H8&
End Sub
Private Sub Command5_Click()
Out &H378&, &HCC8&
End Sub
Private Sub Command6_Click()
Out &H378&, &H6&
End Sub
งานที่ 2 รับ Input จาก swict
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Sub Label1_Click()
Dim n As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
End Sub
งานที่ 3 รับข้อมูลจาก parallelport
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m As Integer
Private Sub Label1_Click()
Dim n, m As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
End Sub
งานที่ 4 คิวอัตโนมัติ
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m, o, p As Integer
Private Sub Label1_Click()
Dim n, m, p As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
If p < m Then
Select Case n
Case Is = 255
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ1"
Case Is = 63
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ2"
Case Is = 119
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ3"
End Select
Else
Label4.Caption = p
Label5.Caption = "ËÁ´¤ÔÇ"
End If
End Sub
งานที่ 5 ตั้งเวลาทำงานของ contrack
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)
Public pwrite As Integer
Private Sub Form_Load()
Label1.Caption = "Relay1"
Label2.Caption = "Relay2"
Label5.Caption = "Alarm Time"
Label4.Caption = "Alarm delay (sec)"
Label3.FontBold = True
Text1.Alignment = 2
Text2.Alignment = 2
Text3.Alignment = 2
Text4.Alignment = 2
Text1.Text = "00:00:00"
Text3.Text = "00:00:00"
Text2.Text = "0"
Text4.Text = "0"
Timer1.Interval = 1000
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer1.Enabled = False
Timer2.Enabled = False
pwrite = &H378
Out pwrite, &H0
End Sub
Private Sub Timer1_Timer()
Text2.Text = Text2.Text - 1
If Val(Text2.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H1
Text2.Text = "0"
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
Text4.Text = Text4.Text - 1
If Val(Text4.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H2
Text4.Text = "0"
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
Label3.Caption = Time$
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H1
Timer1.Enabled = True
End If
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H2
Timer2.Enabled = True
End If
If Label3.Caption = Text3.Text Then
Out pwrite, Inp(pwrite) Xor &H4
Timer3.Enabled = True
End If
End Sub
งานที่ 6 สเต็ปมอเตอร์
Private Declare Sub Out Lib "DLLPORT.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public pwrite As Integer
Public t As Integer
Private Sub Command1_Click()
Do
DoEvents
Out pwrite, &H8
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H1
Sleep (t)
Loop
End Sub
Private Sub Command2_Click()
Do
DoEvents
Out pwrite, &H1
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H8
Sleep (t)
Loop
End Sub
Private Sub Form_Load()
Command1.Caption = "<- Reverse"
Command2.Caption = "Forward ->"
HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.Value = 50
Timer1.Interval = 1000
pwrite = &H378
End Sub
Private Sub Timer1_Timer()
t = HScroll1.Value
End Sub
การเขียนโปรแกรมด้วย visual basic
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนานที่ LED 1
Private Declare Sub Out Lib "DllPort.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Sub Command1_Click()
Out &H378&, &H1&
End Sub
Private Sub Command2_Click()
Out &H378&, &H2&
End Sub
Private Sub Command3_Click()
Out &H378&, &H4&
End Sub
Private Sub Command4_Click()
Out &H378, &H8&
End Sub
Private Sub Command5_Click()
Out &H378&, &HCC8&
End Sub
Private Sub Command6_Click()
Out &H378&, &H6&
End Sub
งานที่ 2 โปรแกรมรับ Input จาก Swict
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Private Sub Label1_Click()
Dim n As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
End Sub
งานที่ 3 โปรแกรมรับข้อมูลจาก parallelport
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m As Integer
Private Sub Label1_Click()
Dim n, m As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
End Sub
งานที่ 4 โปรแกรมคิวอัตโนมัติ
Private Declare Function Inp Lib "DllPort.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Dim n, m, o, p As Integer
Private Sub Label1_Click()
Dim n, m, p As Integer
End Sub
Private Sub Timer1_Timer()
n = Inp(&H379&)
Label2.Caption = n
If n = 95 Then
m = m + 1
Label3.Caption = m
End If
If p < m Then
Select Case n
Case Is = 255
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ1"
Case Is = 63
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ2"
Case Is = 119
p = p + 1
Label4.Caption = p
Label5.Caption = "ªèͧºÃÔ¡ÒÃ3"
End Select
Else
Label4.Caption = p
Label5.Caption = "ËÁ´¤ÔÇ"
End If
End Sub
งานที่ 5 โปรแกรมตั้งเวลาทำงานของ contrack
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)
Public pwrite As Integer
Private Sub Form_Load()
Label1.Caption = "Relay1"
Label2.Caption = "Relay2"
Label5.Caption = "Alarm Time"
Label4.Caption = "Alarm delay (sec)"
Label3.FontBold = True
Text1.Alignment = 2
Text2.Alignment = 2
Text3.Alignment = 2
Text4.Alignment = 2
Text1.Text = "00:00:00"
Text3.Text = "00:00:00"
Text2.Text = "0"
Text4.Text = "0"
Timer1.Interval = 1000
Timer2.Interval = 1000
Timer3.Interval = 1000
Timer1.Enabled = False
Timer2.Enabled = False
pwrite = &H378
Out pwrite, &H0
End Sub
Private Sub Timer1_Timer()
Text2.Text = Text2.Text - 1
If Val(Text2.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H1
Text2.Text = "0"
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
Text4.Text = Text4.Text - 1
If Val(Text4.Text) < 0 Then
Out pwrite, Inp(pwrite) Xor &H2
Text4.Text = "0"
Timer2.Enabled = False
End If
End Sub
Private Sub Timer3_Timer()
Label3.Caption = Time$
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H1
Timer1.Enabled = True
End If
If Label3.Caption = Text1.Text Then
Out pwrite, Inp(pwrite) Xor &H2
Timer2.Enabled = True
End If
If Label3.Caption = Text3.Text Then
Out pwrite, Inp(pwrite) Xor &H4
Timer3.Enabled = True
End If
End Sub
งานที่ 6 โปรแกรมสเต็ปมอเตอร์
Private Declare Sub Out Lib "DLLPORT.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public pwrite As Integer
Public t As Integer
Private Sub Command1_Click()
Do
DoEvents
Out pwrite, &H8
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H1
Sleep (t)
Loop
End Sub
Private Sub Command2_Click()
Do
DoEvents
Out pwrite, &H1
Sleep (t)
Out pwrite, &H2
Sleep (t)
Out pwrite, &H4
Sleep (t)
Out pwrite, &H8
Sleep (t)
Loop
End Sub
Private Sub Form_Load()
Command1.Caption = "<- Reverse"
Command2.Caption = "Forward ->"
HScroll1.Min = 1
HScroll1.Max = 100
HScroll1.Value = 50
Timer1.Interval = 1000
pwrite = &H378
End Sub
Private Sub Timer1_Timer()
t = HScroll1.Value
End Sub
การติดต่อพอ์ตขนานด้วย visual Basic
งานที่ 1 โปรแกรมส่งข้อมูลออกพอร์ตขนาน
งานที่ 2 โปรแกรมรับ Input จาก Swict
งานที่ 3 โปรแกรมรับข้อมูลจาก parallelport
งานที่ 4 โปรแกรมคิวอัตโนมัติ
งานที่ 5 โปรแกรมตั้งเวลาทำงานของ contrack
งานที่ 6 โปรแกรมสเต็ปมอเตอร์