Wednesday 25 July 2012

VB-6 Code for Input & Output function of 8 Channel GPIO USB Card

(A) Following is the circuit diagram of  8 channel GPIO USB card with Microchip PIC18F14K50 Controller. 

 

(B) Following is the wiring diagram of  8 channel GPIO USB card with 8 On/Off Switch connected as INPUT for testing input function of GPIO USB card.


(C) Following is the wiring diagram of  8 channel GPIO USB card with 8 LED connected as OUTPUT  for testing Output function of GPIO USB card.



(D) VB-6 Code for Input & Output function of 8 Channel GPIO USB Card download from follwing web Links.

INPUT CODE: - (A)

Dim line1 As String, line2 As String

Private Sub Command1_Click()
MSComm1.CommPort = 6
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
'*****************************************
MSComm1.PortOpen = True
Text1.Text = "gpio read "
X = Text1.Text
Y = Text2.Text
Label5.Caption = (X + Y & Chr$(13))
'
MSComm1.Output = Label5.Caption
'
'Print Label1.Caption & vbCrLf  'Chr$(13)
'
Do
DoEvents
Buffer = MSComm1.Input
Loop Until InStr(Buffer, “10”)
'
'Loop Until InStr(Buffer, “”) '& Chr$(13))
'Loop Until InStr(Buffer, “” & vbCrLf)
Label1.Caption = Buffer                                 'This is the INPUT Value on Lavel1
P = (line1 + line2)
P = Label1.Caption
MSComm1.PortOpen = False
Q = Label1.Caption
Open "C:\AEP\AR.txt" For Output As #1       'Save Buffer in the file AR .TXT
Write #1, Q
Close #1
End Sub
'*****************************************
Private Sub Command2_Click()
End
End Sub

Private Sub Command3_Click()
Call Command1_Click
Open "C:\AEP\AR.txt" For Input As #1
Input #1, Q
Close #1
Label10.Caption = Q
End Sub

Private Sub Command4_Click()
MsgBox ("Adeeb" & vbCrLf & "Raza")           ' Checking Function of  vbCrLf
End Sub

Private Sub Timer1_Timer()
'Call Command1_Click
End Sub

Screen Shot of INPUT TESTING OF 8 Channel GPIO USB Card


*************************   TESTED FINAL  ********************************
INPUT CODE: - (B)

Dim X, P

Private Sub Form_Load()
P = 1
Timer1.Enabled = False
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.
End Sub
Private Sub Command1_Click()
Line1 = "gpio read "
Line2 = Text2.Text
Line3 = Chr$(13)
MSComm1.Output = Line1 + Line2 + Line3  'Text1.Text & Chr$(13) + A
Buffer = MSComm1.Input
'http://www.vb6.us/tutorials/vb6-string-functions
'************************************************
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
X = Buffer
Text1.Text = X
'************************************************
If Label1.Caption = "0" Then Label2.Caption = "OFF"
If Label1.Caption = "1" Then Label2.Caption = "ON"
End Sub

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

Private Sub Command3_Click()
MSComm1.PortOpen = False
End
End Sub

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

Private Sub Command5_Click()
P = Text3.Text
MSComm1.PortOpen = False
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 pot.
End Sub

Private Sub Timer1_Timer()
Call Command1_Click
End Sub

Screen Shot of INPUT TESTING OF 8 Channel GPIO USB Card
Thanks
Adeeb Raza