Go Down

Topic: arduino+vb6 (Read 9 times) previous topic - next topic

RPCoyle

Woops! got the "<" and ">" backwards on my last post. They are not consistent with my previous code... sorry. turn them around and try it.

Glennmars

wow very awesome RPCoyle..great :smiley-surprise:!. i salute you all guys ;)

now when i run the vb application after running the arduino i can access the switch when i press it, then the LED will flash which i find hard before on how to access it..thank you so much RPCoyle :)...

one more lacking is to fill the color of the circle; i just use the code you posted RPCoyle then i inserted the cases..here is the code, perhaps you can see if what is the lacking of this.

Code: [Select]

Private Sub MSComm1_OnComm()

MSComm1.Settings = "9600,N,8,1"
FoundIt = False
' find USB port
ComFail = False
FailErr = False
For n = 1 To 16
  If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
   On Error Resume Next
   MSComm1.CommPort = n
   On Error Resume Next
   MSComm1.InputLen = 0
   MSComm1.PortOpen = True
   If MSComm1.CommID > 0 Then
     For i = 1 To 100
      Str = ""
      Str = MSComm1.Input
      If InStr(Str, "<") > 0 And InStr(Str, ">") > 0 Then GoTo jump:  ' in this case the output from Your Arduino  would be "< R >" or  "< Y >" of < G > "....
      Sleep 50
     Next i
  End If
Next n
If MSComm1.PortOpen = False Then MsgBox "Controller Not functioning , Please check USB connection", vbCritical, "": ComFail = True: Exit Sub

jump:
     '   your case statement
      Debug.Print Str;
     Select Case (Str) ' set a break point here so you can step through the case statement
   Case "A"
     Call LEDOn(vbRed)
   Case "B"
     Call LEDOn(vbGreen)
   Case "C"
     Call LEDOn(vbBlue)
   Case "D"
     Call LEDOn(vbYellow)
   Case Else
      Call LEDOff
End Sub

Private Sub LEDOn(col As Long)
End Sub
Shape1.FillColor = col
End Sub

Private Sub LEDOff()
End Sub
Shape1.FillColor = vbWhite
End Sub


on my arduino code, i just replace the serial.println< "R5"> into < "A" , < "B" > and so on...as what you noted also.

RPCoyle

too many end subs... did this compile?
Code: [Select]

Private Sub LEDOn(col As Long)
End Sub
Shape1.FillColor = col
End Sub

Private Sub LEDOff()
End Sub
Shape1.FillColor = vbWhite
End Sub 



On the arduino side you need to output

Code: [Select]

    Serial.print("< ");
    Serial.print(ColorStr);       // output to computer USB port
    Serial.println(">");


On the VB side you need to get the vale back out of the string coming in from the Arduino. Then use ColorStr in your case statement
Code: [Select]

  strt = InStr(str, "<") + 1
  fin = InStr(str, ">")
  If (fin - strt) <= 0 Then
     Exit Function
  Else
      ColorStr =  Mid(str, strt, (fin - strt))
  End If


You should be able to piece this together and get it working. Get one piece working at a time. learn to set breakpoints and step through the VB code. It will help a lot also if you use lots of debug statements till you get the thing worked out

Glennmars

hello RPCoyle..sorry for this delay information i just found out when i use to compile the vb application an error message appear which is " Argument not optional" that points on the code
Code: [Select]

Str = ""


1. i can't understand the what does it means..

Code: [Select]

Private Sub LEDOn(col As Long)
End Sub
Shape1.FillColor = col      //in this code the error appears
End Sub

Private Sub LEDOff()
End Sub
Shape1.FillColor = vbWhite
End Sub 


2. also this, when i compile an error appear stating " Only comments may appear after End Sub, End Function, or End Property" which points the above code which i commented.

3.
Quote

learn to set breakpoints and step through the VB code


as what i understand on my research it has something to do with pausing the running mode base on your cursor pointing the code..i don't think if i can really understand it..i was so confuse. :smiley-sad-blue:


4. Finally, i can't find if where on the code the shape appear.. :smiley-sweat:


michael_x

Code: [Select]
Private Sub LEDOn(col As Long)
End Sub                        // this is theoretically correct, but makes no sense
Shape1.FillColor = col      //in this code the error appears   , because VB was told Sub LEDOn has ended already
End Sub


I added a comment as well.
Same for Sub LEDOff below.
This was the reason for RPCoyle's comment "too many End Subs... did this compile?".

Quote
1. i can't understand the what does it means..

It's a feature of VB6 to allow lazy programming. Is
Code: [Select]
Dim Str as String
clearer to you?
the latter declares a variable and its type, RPCoyle's code implicitly declares it by filling data (An empty sring) in, just to determine its data type.

But besides that, you might benefit a lot by learning a bit VB6 usage ( Stepping through code, etc. )

Go Up