BS2 with a VB .NET interface
Sorry if this is a repeat thread but I've been searching for a while about this...
I created a VB .NET interface and want to communicate to the Stamp Basic 2 board.· For example if I push a button in my VB .NET program I want a·LED·to turn on which sits on the stamp board.·I saw a program for VB (http://geocities.com/SiliconValley/Orchard/6633/vb5.html)·but not VB .NET.· Is this possible?· Please any have would be a big help.
Thank you,
Justin ·
I created a VB .NET interface and want to communicate to the Stamp Basic 2 board.· For example if I push a button in my VB .NET program I want a·LED·to turn on which sits on the stamp board.·I saw a program for VB (http://geocities.com/SiliconValley/Orchard/6633/vb5.html)·but not VB .NET.· Is this possible?· Please any have would be a big help.
Thank you,
Justin ·

Comments
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
Personal Links with plenty of BASIC Stamp info
StampPlot - Graphical Data Acquisition and Control
AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
I read your post and figured I'd take a shot at it. Here is a sample project that you can mess around with. It requires .Net 2.0, since I built it with Visual Studio 2005. It should build and run fine with the VB.Net 2005 Express Edition, which you can download free from Microsoft.
Nothing is super polished, since it was a throw together project, but it's fairly straight forward. If you have any questions, just post them, and I'll answer them to the best of my ability (I'm not a VB expert). Also, if you already have .Net 2.0 installed, there's an .exe version in the Debug Bin folder that you can try before building it.
I'm getting an error with "System.IO.Ports.SerialPort" do I need a library or something?
Thanks again for your help...
Post Edited (kuskowski) : 9/28/2006 5:37:33 PM GMT
You need to use the .Net 2.0 SDK. I don't know if Visual Studio 2003 will work with .Net 2.0, so you may need to use Visual Basic 2005, also. You can download the Express Edition of VB 2005 for free from Microsoft, and it will automatically dowload the .Net 2.0 SDK on installation.
Here is the link: msdn.microsoft.com/vstudio/express/vb/default.aspx
I am curious, where did you learn how to do this?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"Imagination is the one weapon in the war against reality."
-Jules de Gaultier
I learned through a lot of reading, working through tutorials, experimenting, and asking questions on some forums. For instance, after doing the VB project, I decided to do a C# and C++.Net version to compare the workflows.
So, for anybody interested, I'm posting a new zip file with all three versions.
Whats your best source for the tutorial.
your file "StampSend" has finally help me understand how to send signal to BS2. Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"Imagination is the one weapon in the war against reality."
-Jules de Gaultier
There are a lot of tutorials on the web, Google will take you a long way with that. If you look around on the Visual Studio Express pages, you'll find some good video tutorials from LearnVisualStudio.net. There are versions for VB & C#. You can also subscribe to LearnVisualStudio.net. Watch the free videos; you'll know after that if you think the subscription is worthwhile. There are also some good webcasts scattered throughout the MS website, as well as on www.learn2asp.net for Asp.Net subjects.
Bluetooth:
I don't have a Bluetooth device, so I can't give specific info. However, if the device is seen as a normal serial device, you can probably read/write to it like a serial port. The underlying concept with the serial port is that it looks like a file to Windows, so you are reading/writing to that particular file. The device you're using should come with some form of information. You could also install and look at MS Robotics Studio, since it would have code samples for Bluetooth communications. I'm using Win2K, and MSRS is incompatible with it, so I haven't looked at MSRS, so I can't give any info on that, either.
Thanks for the link,
speaking of bluetooth, recently I bought bluetooth usb adapter, right now I am trying to get it to communicate with embedded bluetooth appmod. I could get it to connect with your stampsend file (only need to change COM from serial to whatever your bluetooth is assigned, but I need to figure out how to send the data in correct format.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"Imagination is the one weapon in the war against reality."
-Jules de Gaultier
http://www.parallax.com/dl/docs/prod/robo/BluetoothControlledRobot.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"Imagination is the one weapon in the war against reality."
-Jules de Gaultier
For Example: a case within a case with two seperate variables
· SELECT Command
· CASE "1"······························································· 'For variable1
····· SELECT Command1
····· CASE "1"··························································· 'For variable2
········· FOR Counter = 1 TO 5
········· HIGH LED1
········· PAUSE 200
········· LOW LED1
········· PAUSE 200
········· NEXT
········· RETURN
····· RETURN
···· CASE "2"
········· FOR Counter = 1 TO 10
········· HIGH LED1
········· PAUSE 200
········· LOW LED1
········· PAUSE 100
········· NEXT
········· RETURN
···· RETURN
····· CASE "3"
········· FOR Counter = 1 TO 15
········· HIGH LED1
········· PAUSE 200
········· LOW LED1
········· PAUSE 200
········· NEXT
········· RETURN
····· RETURN
····· ENDSELECT
· RETURN
Is this possible??
Thanks,
Justin
Post Edited (kuskowski) : 10/3/2006 2:56:26 AM GMT
You can nest SELECT..CASE statements in PBasic. Howver, large nested structures can be difficult to follow. For something like this, you could try breaking the structures down, and placing the decision blocks closer to the actual results.
I'm attaching some samples that should give you a better idea of what I mean.
As for interfacing the BS2 to PC, you would probably need to set up some form of basic handshaking routine. Something like this:
START
PC --> Waiting to send commands
BS2 --> Waiting to receive commands
PC --> Send request for permission to transmit command sequence
BS2 --> Grant permission to send command sequence, await MainCommand
PC --> Send MainCommand
BS2 --> Acknowledge receiving MainCommand, await SubCommand
PC --> Send SubCommand
BS2 --> Acknowledge receiving SubCommand, process command sequence
GOTO START
The reason for this is to minimize the chances of missing the commands, or sending the wrong sequence.
Would you just make another variable called Subcommand and call it later in the code?
SERIN INPUT_PIN, BAUDMODE, [noparse][[/noparse]Command]
?? SERIN INPUT_PIN, BAUDMODE, [noparse][[/noparse]SubCommand] ??
Sorry, but I'm a little rust on my code... Can you help me with the syntax of your PC to BS2.
And is there any code change from a BS2 to a BS2p or can I copy it directly?· I needed more EEPROM, so I got a BS2p.
I really appreciate all your help...
Post Edited (kuskowski) : 10/3/2006 12:18:38 PM GMT
I think the best way for you to send multiple commands would be to send a command "set" in one handshaking exchange. That way both parameters get set in one exchange, which should make the parsing easier on the BS2.
However, you could still break your PBasic code into several subroutines, and just send one command, instead of 2 commands. The benefit of doing it that way is that you could eliminate the handshaking routine.
To run the examples that I posted, you would need to change the Stamp directive at the beginning of the code. There are no other Stamp specific numbers in the code. The circuit for the examples is just 3 leds and a piezo speaker, nothing fancy.
If you don't mind my asking, what are you ulimately trying to accomplish? Are you building a system, learning VB.Net, etc.?
Im building an automated coffee maker. I have the VB part all done, I just need the interfacing section.
From VB when you choose the strength and flavor of your coffee, the BS2 will know what servo to turn on and for how long to stay open.
Those are the two variables that I'm looking to send over from VB to the BS2.
This is only one issue that im dealing with. Next is to make it wireless. What would be the easiest way to make it wireless (from VB to BS2)?
It would be a much simpler solution to send 1 command, but you'll probably learn more sending 2.
As for wireless, you could use the Parallax Bluetooth Appmod, or Martin Hebel has a ZigBee Appmod available. Both have docs that you can download and look at.
Can I do this? Or with the second one overwrite the first one??
VB:
SerialIO.Write(Flavor)
SerialIO.Write(Strength)
Stamp:
SERIN INPUT_PIN, BAUDMODE, [noparse][[/noparse]Flavor]
GOSUB TakeAction
RETURN
TakeAction:
SELECT Flavor
CASE "Light Roast"
SERIN INPUT_PIN, BAUDMODE, [noparse][[/noparse]Strength]
GOSUB LightRoast
RETURN
CASE "Dark Roast"
SERIN INPUT_PIN, BAUDMODE, [noparse][[/noparse]Strength]
GOSUB DarkRoast
RETURN
ENDSELECT
LightRoast:
Motor = STEP_MOTOR_F1
SELECT Strength
CASE "Weak"
X = 5
RETURN
CASE "Average"
X = 10
RETURN
CASE "Strong"
X = 15
RETURN
ENDSELECT
...... there is also a subroutine for "Dark Roast" but different motor
FOR Counter = 1 TO X
HIGH Motor
PAUSE 200
LOW Motor
PAUSE 200
NEXT
RETURN
IS THIS A GOOD WAY TO APPROCH THIS???· I'm still alittle confussed about the placement of the SERIN and·both SerialIO.Write()...
Post Edited (kuskowski) : 10/3/2006 8:17:25 PM GMT