Shop OBEX P1 Docs P2 Docs Learn Events
BS2 with a VB .NET interface — Parallax Forums

BS2 with a VB .NET interface

kuskowskikuskowski Posts: 17
edited 2006-10-03 20:10 in BASIC Stamp
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 ·

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-09-28 12:14
    You need to use the MSComm control to gain access to ther serial port, read the help files on that control.

    -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
  • kuskowskikuskowski Posts: 17
    edited 2006-09-28 13:39
    how to init it i do a "DIM MSComm as mscomm" and it doesn't recognize it... all those examples are for VB 4,5 and 6 I didn't find any for .NET
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-09-28 15:38
    Justin,

    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.
  • kuskowskikuskowski Posts: 17
    edited 2006-09-28 16:15
    I have visual studio .net 2003 and .NET Framework SDK 1.1v.... Do I need 2.0 (x86) version of Framework???
    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
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-09-28 22:54
    Justin,

    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
  • Justin SaneJustin Sane Posts: 35
    edited 2006-09-29 00:06
    Kevin Wood said...
    Justin,

    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 am curious, where did you learn how to do this?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"Imagination is the one weapon in the war against reality."
    -Jules de Gaultier
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-09-29 03:04
    Are there 2 Justins here?!

    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.
  • Justin SaneJustin Sane Posts: 35
    edited 2006-09-29 13:15
    Kevin Wood said...
    Are there 2 Justins here?!

    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
  • kuskowskikuskowski Posts: 17
    edited 2006-09-29 14:10
    Now would this be the same way I would·use a serial bluetooth device to communicate to the BS2??
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-09-29 23:34
    Tutorials:
    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.
  • Justin SaneJustin Sane Posts: 35
    edited 2006-09-29 23:54
    Kevin Wood said...
    Tutorials:
    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
  • Justin SaneJustin Sane Posts: 35
    edited 2006-09-30 00:11
    also, regarding to bluetooth, this manual might will help.

    http://www.parallax.com/dl/docs/prod/robo/BluetoothControlledRobot.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"Imagination is the one weapon in the war against reality."
    -Jules de Gaultier
  • kuskowskikuskowski Posts: 17
    edited 2006-10-03 02:40
    Kevin Wood said...
    Justin,

    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.
    Im tring to bring more that one variable over, ·Im looking to bring 9-10. This one only has one, is there a way to to do so... or an example? Do I do something with the·baudmode???

    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
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-10-03 06:26
    Justin,

    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.
  • kuskowskikuskowski Posts: 17
    edited 2006-10-03 11:41
    COOL... That will make things easier to read too. How would the BS2 know which is the subcommand? Would it be because of the delay in calling of the commands?

    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
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-10-03 13:39
    Yes, you would define 2 variables, and use two SERIN commands. For the examples that I posted I used DEBUG & DEBUGIN, which are tied to the debug terminal, but the idea is the same.

    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.?
  • kuskowskikuskowski Posts: 17
    edited 2006-10-03 16:51
    Im building a school project and I used the stamp board in a earlier class. It looked like it could handle alot and easy to learn...

    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)?
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-10-03 17:02
    You could process the logic for strength and flavor in VB and send one command to the BS2. Then your BS2 could have seperate subroutines for the commands.

    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.
  • kuskowskikuskowski Posts: 17
    edited 2006-10-03 20:10
    Can you recommend a method I can use in VB that will wait until the first command is read/executed before sending the next one??

    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
Sign In or Register to comment.