Shop OBEX P1 Docs P2 Docs Learn Events
VB Express to Stamp Template - Page 2 — Parallax Forums

VB Express to Stamp Template

24

Comments

  • ceruleanplainsceruleanplains Posts: 11
    edited 2008-08-20 12:55
    Thanks for the great information.· I've just recently completed my first draft of a VB GUI for a compass, indicator lights for a set of relays, thermometer, etc. and your tutorials were an excellent starting point.· The comm template was especially useful for prototyping each of these functions.·

    The trackbar tutorial was a bit vague in details, but I figured it out after a few looks here and there.· I was using the trackbar to test my graphics in the compass as was mentioned in an earlier posting.·

    I had experimented with the MSRS utility using the provided routines (which didn't work out of the box btw), but in the end VB seems to be a much better situation.· You learn how it works from the ground up and with that knowledge you can do an awful lot of things.· My next project is to experiment with multithreading concept to integrate it all together.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-21 03:52
    I'm glad some people are finding it useful, I guess there are several pieces that appear to be vague and lacking explanation, the original post containing the template is really what I think is important in getting started and where I took most time to try and explain.

    Running seperate threads with BackGroundWorker controls·works·fairly·well.

    I have a user control·I keep that can be configured for various dials and would be well suited for a compass. If there is a lot going on or perhaps multiple dials then I will use a backgroundworker to update the dial position and graphics.

    Jeff T.
  • jsliljslil Posts: 11
    edited 2008-08-22 22:56
    Jeff

    I have not even gotten through the first page of posts. But this thread is awesome!!! just what the doctor ordered. I admit that my programming experience is very limited, but you have provided a lot of information in a very nice format.
  • jsliljslil Posts: 11
    edited 2008-08-22 22:57
    Abram

    I enjoyed your link as well!
  • makkiamakkia Posts: 12
    edited 2008-08-24 11:52
    Hi,

    First of all I would like to thank you for this awesome code.
    I have seen many codes that recieve data from serial ports, and most of them are simliar to this one. Which is why I have some questions:

    1- What happens if you don't "Open" the port using the open() function?
    2- What happens if you don't "Close" the port using the close() function?
    3- If the port remains open for like, several days -in the case that the application have been open for several days- is that bad?
    4- Finally, can you recieve data from the port -via the dataRecieved event- if the port was not open?

    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-08-24 14:07
    Hi makkia,

    1. When you "Open" a com port you are·configuring an applications serial driver to read/write from a set path. If you don't·configure the port·the driver code is not used.

    2. If you don't "Close" a port the application has sole control of that port until you either close the port or close the application.

    3. At one time the PC's serial mouse would invariably be connected to Com1, computers would be left switched on for weeks and the mouse software would always work.

    4. If you don't "Open" the port/driver the driver code is not used. The data received event is part of the driver code and to use it the port must be open.

    Jeff T.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-11-16 01:21
    Hi, having a gauge for your accelerometer , temp/humidity , compass module etc. is a nice touch. Heres a quick step by step instruction to "roll your own" .

    For the example I borrowed the Parallax compass graphic.

    The instructions show how to build·a gauge/compass and it should be evident what would be needed to modify it to suit your own sensor application.

    The Stamp code is not shown but should follow the previous examples of serial communication between PC and BS2, the example of a compass would require a word value ranging from 0 to 360 passed to Dial1.value.

    Build this test project to experiment with then add it into the original template when your happy with the way it looks. You can add extra gauges to your form by dragging the control onto the form as many times as needed

    Along with the instructions (Dial.txt) are the required graphics (compass and needle gif) and the required code (DialCode.txt).

    Jeff T.

    EDIT: It is important to preserve the size and format of the images, to download right click and select Save Target As.

    Post Edited (Unsoundcode) : 11/16/2008 1:33:24 AM GMT
    300 x 273 - 15K
    300 x 273 - 812B
  • gaubien2000gaubien2000 Posts: 8
    edited 2008-11-27 07:53
    hi , this is my code, and somehow i can not get the if condition to be true. someone please help me out, i couldnt sleep for so many nights already , thanks so much.



    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'Servo1 connected to pin0 servo2 connected to pin1
    command VAR Byte

    uuu:
    SERIN 16, 16468, [noparse][[/noparse]STR command\1] ' Get 1-byte string
    IF command = 111 THEN

    FREQOUT 15,100,4000
    ELSE
    FREQOUT 15,100,100
    ENDIF

    GOSUB uuu

    vb code


    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If SerialPort1.IsOpen Then

    Dim ben As Byte = 111
    SerialPort1.WriteLine(ben)

    Else

    MsgBox("No connection")

    End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If SerialPort1.IsOpen = False Then
    SerialPort1.Open()
    Button2.Text = "connected"
    Else
    SerialPort1.Close()
    Button2.Text = "disconnected"

    End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Label1.Text = SerialPort1.ReadExisting()
    End Sub
    End Class
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-11-27 15:44
    Hi gaubien2000, the VB line Writeline will send an ASCII string of characters not a byte value so the format at the Stamp should be as follows

    SERIN 16, 16468, [noparse][[/noparse]DEC3 command] ' Get 1-byte string

    Jeff T.
  • ChilesChiles Posts: 15
    edited 2008-12-10 09:06
    Thanks a million Jeff T. and D. Abram, you guys really got me started!

    Chiles Dagger
  • C.RayC.Ray Posts: 6
    edited 2009-03-03 23:24
    Hello,

    I am trying to work my way through the "twin servo control" provided by "Unsoundcode" and I am getting an error message when I try to run the program.

    The message I am getting is "A first chance exception of type 'System.InvalidOperationException' occurred in System.dll".

    The Form1 is showing on the screen but I can not select Form2, however I can move the sliders on the trackbar controls.

    I think that I may have put the Sub "data_in" in the wrong place as I could not determine from the instructions just exactly where it was supposed to go. I put it at the bottom of the Form1.vb code page.

    Any ideas where I am going wrong?

    Carl
  • C.RayC.Ray Posts: 6
    edited 2009-03-04 00:03
    Hello,

    I am trying to work my way through the "twin servo control" provided by "Unsoundcode" and I am getting an error message when I try to run the program.

    The message I am getting is "A first chance exception of type 'System.InvalidOperationException' occurred in System.dll".

    The Form1 is showing on the screen but I can not select Form2, however I can move the sliders on the trackbar controls.

    I think that I may have put the Sub "data_in" in the wrong place as I could not determine from the instructions just exactly where it was supposed to go. I put it at the bottom of the Form1.vb code page.

    Any ideas where I am going wrong?

    Carl
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-03-04 06:05
    Hi Carl, it's quite a while since I last looked at that example so I worked through the template and then through the twin servo sample without a hitch. There was one typo in the twin servo doc where WithEvents was spelt WitheEvents.

    The placement of the Data_In sub is fine.

    If you can't resolve the problem zip and post an attachment of your source.

    Jeff T.
  • C.RayC.Ray Posts: 6
    edited 2009-03-04 22:18
    I rebooted the computer and the program ran fine after that. I continued through the "Simple Debug App" and all of that worked as well except sometimes Form2 freezes when I try to close it with the "Close Form2" button and I have to close it with the Windows Task Manager.

    I played around with the Simple Debug App and managed to get the data to display in a couple of RichTextBoxes by simply adding more "RichTextBox1.Text = RichTextBox1.Text & Chr(text)" statements to the Debug_Out Sub and adding the new RichTextBox(es).

    This gets me a bit closer to my goal of displaying four separate digits in four separate RichTextBox(es) though I still do not have a clue how to do this. I am not sure about the use of "Delegate" or "my_delegate" or the use of "&Chr(text)" just to name a few, so I do not know where to start. How can I get up to speed with the use of all these names and how they apply to each different situation so that I can create this simple display?

    Carl
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-03-06 06:18
    Hi Carl, I am still learning different features of VB Express and some of the things in the previous code sample could have been done better. But as it's description says it is a template which forms a basis for improvement and your own ideas.

    I am glad you got through the Debug app successfully , just to show the versatility of the template I have attached some code that will slot into place in that application and achieves something like what you are wanting to do.

    The things you don't yet understand can all be found in the help files and various web sites, look them up and play around with them until it makes sense.

    You can mess around with the attachment too and get it how you want, it uses a header and a newline to "bracket" the data into 4 seperate pieces , something that is mentioned in several of the samples I posted. There is a sample Stamp code to test with (9600 baud).

    Jeff T.
  • C.RayC.Ray Posts: 6
    edited 2009-03-07 00:34
    Hello Jeff,

    Thank you for helping me out with this. I appreciate it very much.

    You mentioned the book "Visual Basic 2005 Cookbook" from O'Reilly. Does this book get into using the serial port class? Is this book for the express edition of Visual Basic?

    I have purchased many books as of late, some good and some not so good, and it is always a benefit to have a book that is recommended by someone that knows. Since you have a working knowledge of the Visual Basic system, a book recommended by you would be a book that I will purchase.

    I will let you know how I progress.

    Carl
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-03-07 02:06
    Hi Carl, the Cookbook is a good book in my opinion, the section on serial I/O is a little lacking in information so if that is the main reason for purchasing it then I wouldn't bother. What it does have are examples of almost every aspect of VB Express·you would likely use, graphics ,·multimedia , file systems , databases , arrays , printing and much more explained in a way the beginner can understand , I refer to it often.

    The stage you are at now with the original template of this thread is probably the most useful , you have the DataReceived event by which you can debug the input from the Stamp , by playing around with formats , headers and newline you can now see what is happening with your data.

    The drawback with the DataReceived event , if there is one , is that the DataReceived event creates its own separate thread. This is why you need a delegate , a delegate provides a thread safe way to call a sub routine or function created in a different thread.

    If you can figure out the delegate (s) that are being used it will most likely serve for all the applications you build in the near future so study it closely. The delegate consists of declaring the delegate , creating an instance of it , invoking the delegate and finally the sub routine that is called by the invoke.

    When you get to a program that has to not only receive data from a BS2 but is also required to transmit that may·provide·you with a challenge , try to get into the habit of jotting down (flow chart) how you might send and receive and empty buffers etc.

    hope this helps

    Jeff T.
  • texastigertexastiger Posts: 5
    edited 2009-03-16 12:55
    Does the code for the communication template require modification to work in VB Express 2008? I followed the instructions and copy / pasted code. Upon trying to run I get 14 error messages. Many of them seemed to do with the combobox1 not being declared. Still learning VB so I may have overlooked something.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-03-16 13:47
    Hi, I worked through the template doc with VB 2008 today copying and pasting the code as I went and the project built fine.

    To try and figure what was giving you the errors I·deleted the two combo boxes from Form2 and did indeed get 14 error messages saying "not declared" when I tried to build.

    Go back and make sure that you added two combo boxes from the tool box to Form2 and that they are named ComboBox1 and ComboBox2.

    Post back if that does not resolve the issue.

    Jeff T.
  • texastigertexastiger Posts: 5
    edited 2009-03-16 14:44
    Thanks for the reply Jeff. I will try this tonight when I get home.
  • LidemanLideman Posts: 6
    edited 2009-08-11 23:25
    Unsoundcode said...
    Here is a small add in to the template. The app controls two servos with sliders (trackbars). The most valuable thing about it though is the way the Stamp controls when data is sent from the PC and the use of strings to synchronize tx/rx.

    Jeff T.

    Hi, i just wanna ask if you have the full software, not just the codes, because i'm having a serius difficult.
    Thanks for doing a lot for all.
    best regards
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-08-12 05:02
    Hi Lideman , first I saw your·earlier PM and will reply to that.

    Just to clarify here I have to point out that all the previous code snippets are examples to help anyone who has a little knowledge of Pbasic and Visual Basic get up and running with a PC and Stamp.

    None of the examples are truly complete that is left to the individual to tailor to their needs.

    In answer to your question about software because there are so many variations on the theme I probably don't have anything that would be suitable for you.

    What I can do is help you or anyone else that might have a question that is related to Visual Basic interfacing with a piece of Parallax hardware (within the scope of my knowledge )

    I will get in touch a little later and see if I can help you get started .

    Jeff T.
  • jasonpauthementjasonpauthement Posts: 1
    edited 2010-01-05 04:55
    is there a way to receive the data from the pb2 board and send it to Vb(2008), IE pin1 = textbox1.text ,, pin2 = textbox2.text and so on
    i am trying to write a program to monitor the weather just for fun, i can get input using the serialport2.readexsting statement but it gives me all the sensors in one textbox or listbox or whatever. i would like to break it down some more to send a certin output for the board to the textbox of my choice. Can any one help,· O by the way the servo slide controll in cool.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-01-06 01:47
    Hi , this is fairly basic but it may do what you want while you explore other possibilities. The code example assumes you have a Form with 3 text boxes and one button. The code goes inside the button click event.
    [color=#0000ff][color=#0000ff]Dim[/color][/color][color=#000000] string_data [/color][color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color][color=#000000] = [/color][color=#a31515][color=#a31515]"123 88 255"[/color][/color] [color=#008000][color=#008000]'This string is an example of data sent from the Stamp[/color][/color]
    [color=#0000ff][color=#0000ff]Dim[/color][/color] Mystring_arrray() [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]String[/color][/color] [color=#008000][color=#008000]'This array of strings will hold the 3 separated number strings[/color][/color]
    Mystring_arrray = Split(string_data, Space(1)) [color=#008000][color=#008000]'Space(1) uses 1 space as the delimiter , any character can be used as a delimiter.[/color][/color]
    TextBox1.Text = Mystring_arrray(0)
    TextBox2.Text = Mystring_arrray(1)
    TextBox3.Text = Mystring_arrray(2)
    
    

    ·Play with the above on its own to see how it works then try using it with a Stamp to VB app.

    Jeff T.
  • filip911filip911 Posts: 17
    edited 2010-01-07 08:17
    good and easy tutorial but i dont know how to connect bs2 and computer with wires(physically)???
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-01-07 13:18
    Hi , the simplest way is to use the same cable that you would use to program your Stamp .

    Alternatively the following·link describes how to use a MAX 232 to interface a serial connection to any of the Stamps I/O pins.

    http://forums.parallax.com/showthread.php?p=783327

    Jeff T.
  • davejamesdavejames Posts: 4,047
    edited 2010-01-07 16:21
    "Split"?! Really? I haven't seen that array manipulator yet. That's going to come in handy methinks. Really handy.

    Thanks much,

    DJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Jimbo30Jimbo30 Posts: 129
    edited 2010-02-15 00:20
    Thanks, UnsoundCode. This may push me in the right direction also as I am working on a VB6 GUI and BSII interface. My project is at the following link:

    http://forums.parallax.com/forums/default.aspx?f=10&m=426918&g=426979#m426979
  • Possum79Possum79 Posts: 30
    edited 2010-04-24 06:30
    I was trying to use you Compass code in VB '08 and ran into build errors where it says building is necessary. Im interested in trying to monitor some sensors and want to make some gauges in vb. Do you have some other links or anything that I can use to research more on how to do so?


    I really appreciate your help and love the tutorials.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-04-24 13:30
    Hi Possum79 , the compass/dial piece is a favorite of mine . If you care to PM me with what your objective is , what you already have and what errors you are getting I think we could get something up and running . Your feedback could be useful in updating the existing example.

    Jeff T.
Sign In or Register to comment.