VB-6 Code for 8 Channel GPIO USB Module for Testing Input Switch Status

Following is the Visual Basic 6 Code for testing of input through 8 switches connected with I/O-0 to I/O-7 at 8 Channel GPIO USB Module to know the status of Input switches if the switch is open means OFF=0 or if the switch is close means ON=1 as shown in the wiring diagram. for more information please visit http://www.areptone.in/vb6/

Code:-

Dim X, P, S

Private Sub Form_Load()
Timer1.Enabled = False
Shape1.FillColor = &HC0C0FF
Shape2.FillColor = &HC0C0FF
Shape3.FillColor = &HC0C0FF
Shape4.FillColor = &HC0C0FF
Shape5.FillColor = &HC0C0FF
Shape6.FillColor = &HC0C0FF
Shape7.FillColor = &HC0C0FF
Shape8.FillColor = &HC0C0FF
Label22.Caption = “Type Port Number And Press Enter”
End Sub

Private Sub Command1_Click()
P = Text1.Text
MSComm1.CommPort = P                 ‘Text3.Text 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.
Command1.Enabled = False
Label22.Caption = “Card is Ready for Input Checking”
Label25.Caption = “Click”
End Sub

Private Sub Command2_Click()
Timer1.Enabled = True
End Sub

Private Sub Command3_Click()
Timer1.Enabled = False
End Sub

Private Sub Command4_Click()
End
End Sub

Private Sub Command5_Click()           ‘TEST Switch -1
Label22.Caption = “Checking Input Switch No.1 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 0” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label1.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label1.Caption = “0” Then Shape1.FillColor = &HC0C0FF
If Label1.Caption = “1” Then Shape1.FillColor = vbRed
End Sub

Private Sub Command6_Click()        ‘TES TSwitch -2                                                               Label22.Caption = “Checking Input Switch No.2 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 1” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label2.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label2.Caption = “0” Then Shape2.FillColor = &HC0C0FF
If Label2.Caption = “1” Then Shape2.FillColor = vbRed
End Sub

Private Sub Command7_Click()         ‘TEST
Label22.Caption = “Checking Input Switch No.3 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 2” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label3.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label3.Caption = “0” Then Shape3.FillColor = &HC0C0FF
If Label3.Caption = “1” Then Shape3.FillColor = vbRed
End Sub

Private Sub Command8_Click()        ‘TEST
Label22.Caption = “Checking Input Switch No.4 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 3” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label4.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label4.Caption = “0” Then Shape4.FillColor = &HC0C0FF
If Label4.Caption = “1” Then Shape4.FillColor = vbRed
End Sub

Private Sub Command9_Click()        ‘TEST
Label22.Caption = “Checking Input Switch No.5 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 4” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label5.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label5.Caption = “0” Then Shape5.FillColor = &HC0C0FF
If Label5.Caption = “1” Then Shape5.FillColor = vbRed
End Sub

Private Sub Command10_Click()       ‘TEST
Label22.Caption = “Checking Input Switch No.6 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 5” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label6.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label6.Caption = “0” Then Shape6.FillColor = &HC0C0FF
If Label6.Caption = “1” Then Shape6.FillColor = vbRed
End Sub

Private Sub Command11_Click()       ‘TEST
Label22.Caption = “Checking Input Switch No.7 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 6” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label7.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label7.Caption = “0” Then Shape7.FillColor = &HC0C0FF
If Label7.Caption = “1” Then Shape7.FillColor = vbRed
End Sub

Private Sub Command12_Click()         ‘TEST Switch -8                                                              Label22.Caption = “Checking Input Switch No.8 –> OFF=0 ON=1”
MSComm1.Output = “gpio read 7” + Chr$(13)   ‘Total Command as Used
Buffer = MSComm1.Input                 ‘INPUT Reading for Port — All Data & values in Buffer
X = Buffer
‘Text2.Text = X
strSubstr = Mid$(Buffer, 14, 1)        ‘strSubstr = In Buffer 14 Positision one data Switch ON=1 OFF=0
Label8.Caption = strSubstr             ‘strSubstr = Input Switch ON=1 OFF=0
strSubstr = Mid$(Buffer, 11, 1)        ‘strSubstr = In Buffer 11 Positision one data Port No.
Label9.Caption = strSubstr
If Label8.Caption = “0” Then Shape8.FillColor = &HC0C0FF
If Label8.Caption = “1” Then Shape8.FillColor = vbRed
End Sub

Screen Shot of the above Program

Image

http://www.areptone.in/vb6/GPIOSWIN.exe
http://www.areptone.in/vb6/gpioinsw.zip
http://www.areptone.in/aep/gpioswin.JPG
http://www.areptone.in/aep/gpioin.JPG

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. 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