VB6 to Stamp: Insanity Rapidly Approaching
Bill Chennault
Posts: 1,198
All--
I am going nuts trying to get VB6 to send ONE CHARACTER via USB/USB2SER to my BOE/BS2 (or BS2px). If I could just get a character on the DEBUG screen sent from the laptop I would be happy; overwhelmed with joy, kind to all animals including my wife's cats.
I have read and re-read Jon Williams' excellent code and J. Hoylman's VB6 and BS2 code. Code more simple than Mr. Hoylman's would be hard to find. (Looks like I need it, though.) Nothing works. Nothing seems to get past the SERIN statement. (Which leaves me little to debug.)
Would you please help? If I could turn on a BOE mounted LED I would be in seventh-heaven. I could take that and expand it into my Bluetooth Universal Digital Remote Control Thingy.
Thank you very, very much.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I am going nuts trying to get VB6 to send ONE CHARACTER via USB/USB2SER to my BOE/BS2 (or BS2px). If I could just get a character on the DEBUG screen sent from the laptop I would be happy; overwhelmed with joy, kind to all animals including my wife's cats.
I have read and re-read Jon Williams' excellent code and J. Hoylman's VB6 and BS2 code. Code more simple than Mr. Hoylman's would be hard to find. (Looks like I need it, though.) Nothing works. Nothing seems to get past the SERIN statement. (Which leaves me little to debug.)
Would you please help? If I could turn on a BOE mounted LED I would be in seventh-heaven. I could take that and expand it into my Bluetooth Universal Digital Remote Control Thingy.
Thank you very, very much.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Comments
Having written several VB apps myself I have noted that the most common mistake in trying to get communication between the PC and the BASIC Stamp is synchronization. In a few examples I have seen covered here in the forums the data being sent by the PC was missed by the BASIC Stamp because the BASIC Stamp wasn’t ready to receive it at the same time as the PC was sending it. This may not be your case, just one example, but you should also be clear about what you’re sending and how you’re sending it. Do you have an example of your VB code? Are your baud rate and other serial settings, such as flow control, correct?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
"My" code looks a LOT like·J. Hoylman's code. There is a copyright notice on that site. (I am a retired CIO. One of my departments existed to protect people like Mr. Hoylman--and, now myself--if we should place a copyright on our work.) HOWEVER it is downloadable--and dirt simple--at the link I posted in the first sentence. For my purposes, I simplified Mr. Hoylman's code to send a single character. No joy.
In any event, my code, which is similiar to Mr. Hoylman's work, but a LOT simpler, looks like this . . .
The VB6 app . . .
(Hold on! I have to go down to the lab and change computers! [noparse]:)[/noparse]
Ok. I'm back. Here's the VB code . . .
Private Sub cmdSend_Click()
'Output data--alert flag (255), pin number (0), and pin state; high or low (high in this case)
MSComm1.Output = Chr$(255) & Chr$(0) & Chr$(1)
End Sub
Private Sub Form_Load()
'· Use COM1
MSComm1.CommPort = 1
' 2400 baud, no parity, 8 data bits, 1 stop bit
MSComm1.Settings = "2400,N,8,1"
' Make the DTR line low
MSComm1.DTREnable = False
' Open Comm port
MSComm1.PortOpen = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
And here is the Stamp code . . .
' {$STAMP BS2}
' {$PBASIC 2.5}
' Program Name: Receive from VB.bs2
PinNum···· VAR·· Byte
State····· ·· VAR·· Byte
Main:
' 2400,N,8,1 using the programming port 16
SERIN 16,16780,[noparse][[/noparse]WAIT(255),PinNum,State]
' If State=0 Then go to GoLow
' otherwise go to GoHigh
BRANCH State,[noparse][[/noparse]GoLow,GoHigh]
GOTO Main
' Set The pin low
GoLow:
LOW PinNum
GOTO Main
' Set the pin high
GoHigh:
HIGH PinNum
GOTO Main
Looks simple to me. Wonder why I can't make it work? A DEBUG statement tells me it never gets past the PBasic statement "SERIN 16,16780,[noparse][[/noparse]WAIT(255),PinNum,State]".
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Post Edited (Bill Chennault) : 7/31/2008 9:18:01 PM GMT
It looks like VB6 or earlier code…especially using MSComm…It seems you’re sending 3 bytes, not one, but then your BASIC Stamp routine is expecting 3 bytes. I would try getting and displaying the value of 1 byte without the WAIT modifier to see if anything is being sent. Are you using a laptop for this? Some laptops have issues with FIFO buffers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I've been contolling a robot (using a joystick on a pc) with a VB6 program and linking using a D-Link bluetooth dongle and the eb500. I've attached the Basic Stamp program. The essential steps on the VB program are:
Subroutine to make the connection:
RobotLink.CommPort = CommPort.Text
RobotLink.PortOpen = True
OnLine = True
Where CommPort.Text is the contents of a pull-down menu to select the Serial Port number to use. I have to look up the Outgoing port for the bluetooth on the bluetooth control panel, since it seems to change from power-on to power-on.
I read the joystick controls and feed them into a series of variables on the VB side.
Public Sub JoyStickLoop()
While OnLine = True
··· Motion = " "
··· Pan = " "
··· Tilt = " "
··· Lights = " "
··· Gripper = " "
··· diDev.GetDeviceStateJoystick JoyStick
··· 'Get joystick positions for movement
··· Select Case JoyStick.z
······· Case 0 To 2000
··········· Motion = "F"
······· Case 2001 To 4000
··········· Motion = "f"
······· Case 4001 To 6000
··········· Motion = "S"
······· Case 6001 To 8000
··········· Motion = "b"
······· Case 8001 To 10000
··········· Motion = "B"
··· End Select
··· Select Case JoyStick.rz
······· Case 0 To 1500
··········· Motion = "L"
······· Case 8501 To 10000
··········· Motion = "R"
··· End Select
··· Select Case JoyStick.y
······· Case 0 To 2000
··········· Tilt = "U"
······· Case 2001 To 4000
··········· Tilt = "u"
······· Case 4001 To 6000
··········· Tilt = "C"
······· Case 6001 To 8000
··········· Tilt = "d:"
······· Case 8001 To 10000
··········· Tilt = "D"
··· End Select
··· Select Case JoyStick.x
······· Case 0 To 2000
··········· Pan = "L"
······· Case 2001 To 4000
··········· Pan = "l"
······· Case 4001 To 6000
··········· Pan = "C"
······· Case 6001 To 8000
··········· Pan = "r"
······· Case 8001 To 10000
··········· Pan = "R"
··· End Select
··· 'Get the button status - note the button array is 1 less
··· 'than the numbers on the controller.
··· If JoyStick.Buttons(6) Then
······· Lights = "L"
··· End If
··· If JoyStick.Buttons(7) Then
······· Lights = "R"
··· End If
······· If JoyStick.Buttons(4) Then
······· Gripper = "O"
··· End If
··· If JoyStick.Buttons(5) Then
······· Gripper = "C"
··· End If
··· CommandString = Motion & Pan & Tilt & Lights & Gripper
··· SendCommand
··· DoEvents
Wend
End Sub
The SendCommand Subroutine:
Public Sub SendCommand()
··· RobotLink.Output = "ZZ" & CommandString
End Sub
If you look at the BS2 code, the initialization and Main Program sections contain the code that waits for the PC to make a connection and then starts receiving data. To keep the systems synchronized, the serin command waits for "ZZ" to be received and then inputs the 5 single byte variables.
Post Edited (MSDTech) : 7/31/2008 10:44:17 PM GMT
Yes, I am using a laptop. Are the FIFO issues detectable? (Other than certain stuff doesn't work.) I have always programmed my Stamps with a laptop, but I have the impression the problem does not exist at the programming/debugging level.
Great idea on the WAIT modifier. Who wants to wait, anyway? [noparse]:)[/noparse]
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Is this the code you mentioned which you were going to modify, or is this the modified code?
In either case, I am going to download it!
Thanks!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I also use the wait modifier. It's set to wait for the characters "ZZ", as these are NEVER used in any of the commands I send, or plan to send.
I don't have a camera. My goal is to pirate the essential portions of your code and get SOMETHING working. I will build from there. EVENTUALLY, there will be a camera on the lawnmower.
Got the code! It looks very, very good. I really like your style.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I also wonder, using the appmod, are you still able to use all 16 i/o pins on the stamp, or does the bluetooth take all/some of the pins?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--- -- - -
http://perfectaperture.com/robb
I have used various VB6 programmes to talk to BS2s and have found that putting what needs to be sent into a string then using the MSCOMM command works more reliably.
e.g.
Dim Buffer As String
Buffer = "R*"
SerialSend:
MSComm1(ComPort).Output = Buffer
I'm not sure why but it always seems to work better this way!
Good luck,
Helen
If you are asking ME, so far my range has been ZERO. However, the Class I bluetooth dongle is supposed to be good for something over a 100 meters. My problem though, is with the A7 products. They must work, or people would not continue buying them. So, it must be me.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I will try exactly what you suggested.
Thank you!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
When I was testing the eb500 and D-Link dongle to see what kinds of range I could get from the bluetooth for the weather station I built, I was easily able to get 200 to 300 feet. The laptop with the dongle was in a classroom at the school and I was in the parking lot on the other side of the building and still connected. The gods of radio transmission were looking favorably on me that day. Currently I have an A7 eb501-ser on both the sensor array and web server. They are about 150 feet apart with one in a building and the other out in the weather. The external unit is enclosed in a pvc housing that doesn't seem to affect the range.
As far as the pins used, the listing in the manual will show you the pins available on the appmod header. Since I don't use RTS and CTS, I bought a 20 pin header socket that can plug into the appmod header on the BOE. I cut off the pins for RTS and CTS from the socket, so the will no longer connect. I plug the eb500 into the socket and the socket into the appmod header. This way I know there will be no conflicts with those pins.
Rick
Post Edited (MSDTech) : 8/1/2008 2:29:17 PM GMT
Are you using·either the eb500 or eb501·on a laptop?
Thanks.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I'm using a D-Link bluetooth dongle on the laptop and a second D-Link on my PC. The eb500 is used on my Boe-Bot and my extra BOE. The eb-501-ser units are on my weather station and are connected to Basic Stamp 2 OEM modules.
Rick
Duh on me. I did not phrase the question correctly but you gave me the right answer anyway!
Thanks!
-Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I got some time in yesterday and cleaned up my code a bit. I've included both the VB6 project and the BS2 code as attachments. I modified the code to only send commands about every second or when a change in the positions of the joystick·has occurred. This seems to help with the buffers on both my desktop and laptop. I seems the VB program was sending commands faster than the link could handle and they were stacking up in the comm port buffer. This caused the robot to "get behind" and it would be responding with a significant delay.
I still need to add some error handling routines on the VB side on the communications link, so I don't get fatal errors if the program is run and the robot is not there.
Hope this helps,
Rick
Post Edited (MSDTech) : 8/3/2008 2:36:59 PM GMT
Thanks! I downloaded both. Remember, all I am trying to do is extract enough "how to" from your code to transmit a character from VB to the Stamp's DEBUG screen. I figure if I can do that, then I can expand from there.
I believe my new Dell Latitude has a sub-D connector serial port. If it works, then I am going to quit using USB in this effort.
Thank you, again.
I also have an Elexol Ether I/O-24 and an extra access point. I see some real possibilities there. There is nothing wrong with a "roaming" access point. (It could roam around the yard while cutting my grass!)
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
At least your questions got me going to get the robot ready for school starting back up. Time flies and I realized that I only had about a week to get it ready.
Talking with one of the teachers at school, he wants to learn to build an autonomous robot that will sweep up the floor of the woodworking shop. This should be a very interesting project if we can get it off the ground.
Considering your first post and your code: are you sure your USB2SER is mapped to COM1 (this is a rare case to my experience)?
Adrian
You pretty much nailed the problem: I was very confused concerning the com ports. Here is how it is supposed to work: Discover which com port your LOCAL Bluetooth device grabs (a Zoom Class I dongle, in my case) to communicate with the remote Bluetooth device (an eb500 and an eb501, in my case). Then configure Hyperterminal (and I HOPE VB6!) to use that port. Also, in my case I see no reason to use anything other than EmbeddedBlue's EasyConnect. It is a Bluetooth serial cable replacement and works very well (at least for the all-important "Hello World" application) and is very easy to set up.
Next, crank up the Stamp (and communications code)·and then the remote Bluetooth and then Hyperterminal. Using my eb501 with its external antenna, I can now receive "Hello World" on my laptop from ANYWHERE on my 60 x 90 lot! What could be better? [noparse]:)[/noparse]
Well, getting VB to talk to the Stamp would be better. A LOT better. I am going to analyze MSDTech's code very closely and see which parts are pertinent to my lawnmower application. His code is far more extensive than what I need, but I am sure it will point me in the right vbDirection.
Suggestions welcome.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Don't know how you are making out there on this, but i thought i would suggest this in case. Looking at the eb500 manual, it has some pretty detailed instructions on establishing a connection. A couple of things that were of interest was the parts about the security trust setup (enter passcode ), and the fact 2 different ports are used for send and receive, at least that's the way i read it. Just wondering if you followed all the steps in the manual?
Yes. I read, re-read, and then re-re-read the entire manual. Everything is working the way I want it to now. However, ALL I am doing on both the eb500 and the eb501 are "Hello World" programs. I have yet to tackle getting VB to take the place of Hyperterminal. I am a pretty good VB programmer, but have never done any serious serial work with it.
I must say that when I finally learned how to use A7's tech support--their forum, to which Bryan Hall responds to support questions--my fortunes with the EmbeddedBlue products improved immensely. For me, calling A7, either tech support or customer service was like talking to an answering machine. EXACTLY like talking to an answering machine to which no one ever listened on the A7 end. But, Bryan Hall is highly competent and more than willing to go the extra mile. As far as I can tell, he is the only one that provides technical support on their forum, though.
I will develop with the eb501 and VB using a BOE. Once I get that working properly (beyond "Hello World"!), I will migrate the eb501 to Ugly Buster and do some remote control in the house and in the yard. (Ugly Buster pretty much doesn't care about the surface as long as he can get traction . . . the back and front yards are flat, anyway.) Although he is a tracked device, I believe I can develop everything I need for my next project using Ugly Buster.
Once the code is up and running, or a viable skeleton of it, I will go back to the mill and begin building the lawnmower. The lawnmower will be completely DC powered and use at least one Stamp (either a BS2p40 or·an SX48; I have more experience with the former) plus some HB-25s. The lawnmower will be digitally remote controlled via eb501 Bluetooth with commands interpreted remotely by the Stamp(s). I'll stick an articulated arm on it·holding a wireless web cam, as well.
It should be interesting and a lot of fun and it might even work. Somehow, I have to fit this around all my other hobbies. I retired early so I could do these things: Work was certainly getting in the way of fun. I just couldn't see it any other way.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
Post Edited (Bill Chennault) : 8/9/2008 6:54:24 PM GMT
Don't think i am doubting your knowledge here, i just make suggestions on issues that i figure someone might overlook, as i have done it many times myself. It's like the old saying goes, if you can't find something, it's probably right in front of your nose. I keep tabs on this stuff as future products i may purchase, and i am interested in any issues someone may have with it.
Are you planning to make your own GUI with vbasic?
It will be interesting to see the machining of the lawnmower, so i hope you keep posting some updates. Any plans to automate the mill?
I certainly agree with that old saying you quoted, as well. My problem with the eb500 and eb501 was simply that I had the TX and RX pins crossed!
Yes, after I get the communications working, I will build a simple VB GUI to run Ugly Buster around. Later, I will build something more appropriate to the lawnmower.
I bought the mill to TRY to regain the early skills I had in my very first "real" job working at "Reed Roller Bit", which became "Hughes Tool" while I worked there. There was no CNC at that time. So, I will not attempt to "CNC" this mill. Besides, it is too large to do so economically. It would be fun to get a small one and CNC it, however.
I built a quill clamp for the mill which is part of the DRO assembly for the quill. I added some tapped holes around the periphery of the clamp so I could mount my camera and take stills or videos of the whatever I am doing. There will be pictures of the lawnmower during machining.
I appreciate you thinking about this issue for me.
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
I've been following the thread for the last few days and have to say that i'm really glad to be here.
I am also working in a VB project with bs2sx. Using VisualStudio2008, programming in C#, has the same functionalities that VB6.
I also have read the previous posts here, tried what you've done, but just can't get it work. I also *re-read* the Jon Williams article, still can't make it work.
At first, when declare a var in the bs code, and declare it as a Nib, then i do get the correct values (for values between 0 to 15), if i need to recieve a byte, when i debug the values that i recieve from the windows app. i only get values between 49 and 52, independant of the values that i send. I read about the issues of working with a notebook's serial port. Might that be influencing me? How can i tell?
I am also working with the circuit proposed in the Jon Williams Article. (RS232).
Thanks in advance for your support.
--Gabriel
I am really too inexperienced to help much, but can you post your code for us to see? That would help immensely!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.
SERIN rx,baud,[noparse][[/noparse]DEC sdata]
the same applies to DEBUG
DEBUG DEC sdata
allthough the following link discusses Visual Studio Visual Basic there should be enough to point you in the right direction http://forums.parallax.com/showthread.php?p=671804
Bill... I have been following your thread and VB6 differs from Visual Basic 2008 enough that I don't have much to offer, I'm sure the inclusion of wireless devices only makes things a little trickier. Have you made progress?
Jeff T.
BS code is quite simple.
The windows app just decompose a string into chars and then sends each char, after that sends an EndOfLine char (~).
I have classes now, on my way back i'll make the rest of the code.
hope this can be useful to you.
Progress? Does several million more "Hello World" messages count as progress? [noparse]:)[/noparse]
Actually, I have been tied up in the shop: I·finally found a hydraulic cart that will hold my rotary table and my mill vise. The rotary table weighs 147 pounds and the mill vise weighs 97 pounds. Lifting them on and off the mill table is a bit of chore but not anymore!
This thread won't die because I will be asking questions, soon. I have actually done serial I/O with VB but it has been a very long time and I bet it is not like riding a bicycle.
Thanks!
--Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.