8 Channel USB GPIO Module Testing INPUT & OUTPUT Coding with VB-6

Hi Every Body

Following is the coding for testing & checking of INPUT & OUTPUT of GPIO 8 Chanel USB card through VB 6. for more details visit http://www.areptone.com/vb6/

************  INPUT  TESTING  ****************

     Code For GPIO INPUT (GPIO read Command)

*******************************************

Option Explicit
Private Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
Dim message As Integer
Dim Buffer$, X

Private Sub Form_Load()
If Dir(“C:\AEP”, vbDirectory) = vbNullString Then Call Aepset    ‘Check AEP Dir
‘*****************************************************************
Open “C:\AEP\GPIO.DAT” For Input As #1
Input #1, X
Close #1
Text1.Text = X
End Sub

Private Sub Aepset()
If Dir(“C:\AEP”, vbDirectory) = vbNullString Then MkDir (“C:\AEP”)  ‘ Creat AEP Dir
X = Text1.Text

Dim InString As String                      ‘Buffer to hold input string
MSComm1.CommPort = X                        ‘Com Port Number
MSComm1.Settings = “9600,N,8,1”             ‘9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.InputLen = 0                        ‘Tell the control to read entire buffer when Input is used.
MSComm1.PortOpen = True                     ‘Port Open
‘****************************************************
Open “C:\AEP\GPIO.DAT” For Output As #1
Write #1, X
Close #1
End Sub

Private Sub Command1_Click()
Call Aepset
MSComm1.Output = “gpio read 0” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label1.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False                   ‘Port Close
End Sub

Private Sub Command2_Click()
Call Aepset
MSComm1.Output = “gpio read 1” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label2.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Command3_Click()
Call Aepset
MSComm1.Output = “gpio read 2” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label3.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Command4_Click()
Call Aepset
MSComm1.Output = “gpio read 3” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label4.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Command5_Click()
Call Aepset
MSComm1.Output = “gpio read 4” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label5.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Command6_Click()
Call Aepset
MSComm1.Output = “gpio read 5” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label6.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Command7_Click()
Call Aepset
MSComm1.Output = “gpio read 6” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label7.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Command8_Click()
Call Aepset
MSComm1.Output = “gpio read 7” & Chr$(13)   ‘Send gpio xxx Command with carriage return
Do
DoEvents
Buffer$ = MSComm1.Input
Label8.Caption = Buffer$                   ‘Input Switch Status 0=ON   1=OFF
Loop Until InStr(Buffer$, “” & Chr$(13))   ‘The Chr(13) is a carriage return”
MSComm1.PortOpen = False
End Sub

Private Sub Timer1_Timer()
Label11.Caption = Format(Date, “dd-mm-yyyy”)
Label12.Caption = Time
Sleep 2000
Call Command1_Click
Sleep 2000
Call Command2_Click
Sleep 2000
Call Command3_Click
Sleep 2000
Call Command4_Click
Sleep 2000
Call Command5_Click
Sleep 2000
Call Command6_Click
Sleep 2000
Call Command7_Click
Sleep 2000
Call Command8_Click
Sleep 2000
End Sub

Private Sub Command9_Click()
End
End Sub

*******************************************

************  OUTPUT  TESTING  ***************

Code For GPIO OUTPUT (GPIO set and clear Command)

*******************************************

Private Sub Form_Load()
If Dir(“C:\AEP”, vbDirectory) = vbNullString Then Call Aepcom    ‘Check AEP Dir
‘*****************************************************************
Open “C:\AEP\GPIO.DAT” For Input As #1
Input #1, X
Close #1
Text1.Text = X
‘**********************
Shape1.Visible = False
Shape3.Visible = False
Shape5.Visible = False
Shape7.Visible = False
Shape9.Visible = False
Shape11.Visible = False
Shape13.Visible = False
Shape15.Visible = False
End Sub

Private Sub Aepcom()
If Dir(“C:\AEP”, vbDirectory) = vbNullString Then MkDir (“C:\AEP”)  ‘ Creat AEP Dir
X = Text1.Text
‘***************************************************
Dim InString As String               ‘Buffer to hold input string
MSComm1.CommPort = X                 ‘Com Port Number
MSComm1.Settings = “9600,N,8,1”      ‘9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.InputLen = 0                 ‘Tell the control to read entire buffer when Input is used.
MSComm1.PortOpen = True              ‘Open the port.
MSComm1.PortOpen = False             ‘Close the port.
‘****************************************************
Open “C:\AEP\GPIO.DAT” For Output As #1
Write #1, X
Close #1
End Sub

‘LED No.1 Connected with IO-0 will ON
‘************************************
Private Sub Command1_Click()
MSComm1.PortOpen = True
Shape1.Visible = True
Shape2.Visible = False
MSComm1.Output = “gpio set 0” & Chr$(13)   ‘The Chr(13) is a carriage return
MSComm1.PortOpen = False
End Sub

‘LED No.1 Connected with IO-0 will OFF
‘************************************
Private Sub Command2_Click()
MSComm1.PortOpen = True
Shape2.Visible = True
Shape1.Visible = False
MSComm1.Output = “gpio clear 0” & Chr$(13)  ‘The Chr(13) is a carriage return
MSComm1.PortOpen = False
End Sub

‘LED No.2 Connected with IO-1 will ON
‘************************************
Private Sub Command3_Click()
MSComm1.PortOpen = True
Shape3.Visible = True
Shape4.Visible = False
MSComm1.Output = “gpio set 1” & Chr$(13)
MSComm1.PortOpen = False
End Sub

‘LED No.2 Connected with IO-1 will OFF
‘************************************
Private Sub Command4_Click()
MSComm1.PortOpen = True
Shape4.Visible = True
Shape3.Visible = False
MSComm1.Output = “gpio clear 1” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command5_Click()
MSComm1.PortOpen = True
Shape5.Visible = True
Shape6.Visible = False
MSComm1.Output = “gpio set 2” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command6_Click()
MSComm1.PortOpen = True
Shape6.Visible = True
Shape5.Visible = False
MSComm1.Output = “gpio clear 2” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command7_Click()
MSComm1.PortOpen = True
Shape7.Visible = True
Shape8.Visible = False
MSComm1.Output = “gpio set 3” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command8_Click()
MSComm1.PortOpen = True
Shape8.Visible = True
Shape7.Visible = False
MSComm1.Output = “gpio clear 3” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command9_Click()
MSComm1.PortOpen = True
Shape9.Visible = True
Shape10.Visible = False
MSComm1.Output = “gpio set 4” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command10_Click()
MSComm1.PortOpen = True
Shape10.Visible = True
Shape9.Visible = False
MSComm1.Output = “gpio clear 4” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command11_Click()
MSComm1.PortOpen = True
Shape11.Visible = True
Shape12.Visible = False
MSComm1.Output = “gpio set 5” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command12_Click()
MSComm1.PortOpen = True
Shape12.Visible = True
Shape11.Visible = False
MSComm1.Output = “gpio clear 5” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command13_Click()
MSComm1.PortOpen = True
Shape13.Visible = True
Shape14.Visible = False
MSComm1.Output = “gpio set 6” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command14_Click()
MSComm1.PortOpen = True
Shape14.Visible = True
Shape13.Visible = False
MSComm1.Output = “gpio clear 6” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command15_Click()
MSComm1.PortOpen = True
Shape15.Visible = True
Shape16.Visible = False
MSComm1.Output = “gpio set 7” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command16_Click()
MSComm1.PortOpen = True
Shape16.Visible = True
Shape15.Visible = False
MSComm1.Output = “gpio clear 7” & Chr$(13)
MSComm1.PortOpen = False
End Sub

Private Sub Command17_Click()
Call Command1_Click
Call Command3_Click
Call Command5_Click
Call Command7_Click
Call Command9_Click
Call Command11_Click
Call Command13_Click
Call Command15_Click
End Sub

Private Sub Command18_Click()
Call Command2_Click
Call Command4_Click
Call Command6_Click
Call Command8_Click
Call Command10_Click
Call Command12_Click
Call Command14_Click
Call Command16_Click
End Sub

Private Sub Command19_Click()
Unload Form1
Load Form2
Form2.Show
End Sub

Private Sub Command20_Click()
Call Command18_Click
End
End Sub

Private Sub Timer1_Timer()
Label11.Caption = Format(Date, “dd-mm-yyyy”)
Label12.Caption = Time
Call Aepcom
End Sub

 Thanks

Adeeb Raza

About adeebraza1236

I am an electronic instrumentation engineer by profession but I am working as a design engineer. I can design electronic hardware interface circuits for computer based security system, Computer based industrial control system for automation and process control Etc. My Interests: Electronics Circuit designing with PCB Designing, Computer software development using VB & C , PC based security system, Designing LED Lights, UPS, Inverter Etc
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s