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

VB Express to Stamp Template

13

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-04-27 22:46
    Unsoundcode said...
    This short sub routine will reset a Stamp from within a VB application. This is a really nice feature you might use immediately after opening the serial port ensuring that both programs initialize at the same time or you may assign it to a button for debugging purposes

    Jeff,

    Just getting around to playing with some of your code here and on this one I am curious...why invoke the break state?· That is usually done for an Identify or Program sequence, but to just reset toggling the DTR line should suffice.· Thought I'd ask in case you thought of something I missed.· =)




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-04-27 23:31
    Hi Chris, I have wondered for a while why no one has ever brought that up , I think it was probably a cryptic entry on my part at that time.

    That particular reset is the pre condition for actually writing a program (transmitting a tokenized program) to the Basic stamps EEPROM memory , which can be done with Visual Basic.

    Jeff

    EDIT : of course you were right but I would expect no less [noparse]:o[/noparse]p
    Chris Savage said...
    That is usually done for an Identify or Program sequence



    Post Edited (Unsoundcode) : 4/28/2010 12:53:09 AM GMT
  • logan996logan996 Posts: 281
    edited 2010-04-28 01:34
    does anyone have a C# template/ templates? i would really appreciate those

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When the government is afraid of the people there is liberty, when the people are afraid of the government, there is tryanny"

    · Thomas Jefferson
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-05-04 17:45
    Jeff,

    As a note, I also tried the Twin Servo Control and found that if I close the port after running the program, I generate an exception. It seems I need to add some IF PORT OPEN code to the handlers for incoming and outgoing serial streams.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-05-05 01:37
    Hi Chris , I think I said early on that the examples are not complete , the main point was to show different techniques and methods of communicating with the Stamp and other Parallax devices. Disconnection from the serial port is something I tended to let people deal with themselves , and true it requires more attention than one might think

    I am glad you mention it though it gives me the opportunity to expand on something else I have said in the past.

    I posted most of the examples well over two years ago when I first started using Visual Studio with BS2's , I am still no expert but maybe well into intermediate in a certain areas . What I have said is that if anyone has questions or needs further help (specific to VB & Parallax products) to·ask here or to PM me·. I have had quite a few responses to that offer and although I get busy at times I would say we are at 100% success rate and having fun putting together some neat little apps.

    Jeff T.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-05-05 21:16
    Jeff,

    No complaints here...I wasn't sure if that was intended or not in the code since I did notice that when I created the RFID Reader application the results on my machine were often quite different from other users in the way that I did things. It was you and QuattroRS that helped me fix the issue. As I have said before...I miss VB3! Things were much simpler then. In every version since then so many things have changed that I often find myself stuck on what are otherwise simple issues.

    Count me in as one of the people who completely appreciate all the work and time you have put into this, and if you or QuattroRS ever need anything, I owe ya one, that's for sure. I am, as I said, just now getting back to the examples (gives you an idea of just how slow wheels sometimes turn) so I can try and come up with an official application interface, or at least something that we can build a standardized code template off from.

    I also wanted to send you some kudos for the way your Twin Servo Control object works. Many discard the BASIC Stamp as too slow for many things and the fact that it cannot catch an incoming serial string and keep going at the same time has stumbled many a user. Obviously we at Parallax know how to get around this and Jeff Martin has tried to describe this concept in the GUI Bot application code before. However it's worth mentioning here that your approach puts the BASIC Stamp Module in control and lets the PC wait for updates. This also works well with VB's event driven architecture and means that if you time things right, you can generate an update for every pass through the program loop. That is what sells that example in my book.

    After this weekend I may get back to you with some follow up questions, but for now I am quite impressed. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-05-06 01:19
    Thanks for the comments Chris , since the first post in this thread I have learnt a lot . The most pleasing was overcoming the 4800 baud barrier with a BS2 , that does not sound difficult until you try and run graphics on a GUI while transmitting and receiving several bytes of data at 9600.

    Using serial events is considerably faster than polling as is·transmitting byte arrays rather than ASCII character codes.

    User controls are just one of the greatest features of VB , switches , dials , VU meters , LED arrays etc. etc. cut down on code and development time tremendously.

    I·would love to compact every example in this thread into one document using what I have learnt in the past two years··, one day I might have time to do that.

    An official application interface sounds interesting if it had enough features for the majority ,·to have just a small piece of input on that project would make my day.

    I'm not sure whether I ever used VB3 , I do have a copy of VB6 on my laptop. From my point of view Visual Basic 2008 has a lot more flexibilty which makes it easier to use once you've played with it a while.

    Jeff T.
  • Possum79Possum79 Posts: 30
    edited 2010-05-06 03:57
    Unsoundcode said...

    (Thanks for the comments Chris , since the first post in this thread I have learnt a lot . )

    Well apparently not grammar. JK· I can't spell so I cannot talk. I loved playing with the code and am still working on getting·a RCtime system going with our dial we made. The I will be working on getting a temperature sensor linked to it. I love the help I just still don't get most of the math. To many things to understand. HA
    Thanks again
    ~Ryan
  • davejamesdavejames Posts: 4,047
    edited 2010-05-06 16:04
    @Possum,

    "learnt" is legal in the Queen's English
    "learned" is legal in American English

    Not saying Unsound is British - just that language is flexible and frequently changes. When I was a kid, we'd NEVER use "got", "gotten", "I've got" as is heavily used now. Things change.


    @Unsound,

    "...having fun putting together some neat little apps" - here, here!


    @Mr. Savage,

    Jeff was instrumental in my current project. His approach to serial communication with the VB Received Event was foundational in the ability of the VB GUI and BS2 to pass data reliably.


    Regards,

    DJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-05-06 18:00
    DJ,

    No doubt, Jeff and QuattroRS were able to help me debug issue that seemed to affect several people but which I could not reproduce. It's hard to find a bug in code when it works for you reliably, but others have problems. Alternate suggestions were made on how to accomplish things I was doing and it turned out those options made no difference to my functionality, but seemed to fix most of the problems others were having. I think a lot of it was related to the .NET architecture, but I was happy to have the forum help me for a change.

    With Jeff's example code tutorials he was kind of reminding me of when we first released the Propeller and Dave Scanlan was posting little examples and building off from them. I think he made it to about 20 examples before he stopped. Took many people from dead stop to at least inspired if not practical application. Anyway, I see that happening here which is why I am taking interest in it again. It used to be I'd only launch Visual Studio if I had to. Now I want to. =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • WildatheartWildatheart Posts: 195
    edited 2010-05-12 12:34
    Chris said...
    As a note, I also tried the Twin Servo Control and found that if I close the port after running the program, I generate an exception. It seems I need to add some IF PORT OPEN code to the handlers for incoming and outgoing serial streams.

    Chris, if you resolved the exception issue would you share the revised code?

    And, thanks Jeff for all the time you've taken to help and encourage us with VB

    Post Edited (Wildatheart) : 5/12/2010 12:39:02 PM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-05-12 16:41
    Hi , when you close the serial port you have to make sure there are no serial port instructions trying to read·or write·or any other kind of operation or it will throw an exception , the serial port should be given time to close.

    A·Try ... Catch instruction can handle some but basically what you need to do is click the close port button·then in the button click event you will need a small pause while serial instructions are stopped , you can achieve this with a boolean variable that stops program flow through certain pieces of code. Any code in separate threads should also be given time to complete. When the program is finally halted issue the port close instruction followed by port dispose.

    Jeff T.



    ·
  • davejamesdavejames Posts: 4,047
    edited 2010-05-12 16:52
    Hey Jeff,

    When you say "...serial port should be given time to close", is there any suggested amount for this?

    Thanks,

    DJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-05-12 19:09
    Hi Dave , it depends on whats going on in the code , if there is an instruction in the DataReceived event ,·for example , that has a 50 mS read timeout waiting for a string then you would want to at least give·it the time to time out plus some.

    Using the DataReceived event creates a new thread so your program will have at least two threads working independant of each other , so you must stop usage in the secondary thread before closing the serial port in the main thread.

    hope that helps Dave

    Jeff
  • davejamesdavejames Posts: 4,047
    edited 2010-05-12 19:18
    Jeff - as always, "yes".

    Thanks man,

    DJ

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-05-13 05:25
    Jeff,

    Did you get my reply to your e-mail? I haven't heard back from you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • fsbfsb Posts: 24
    edited 2010-07-20 21:17
    The communications template works great. I have successfully connected it to an IR thermometer and can pass temp readings to the PC in vb 2008.

    One questions though. The data repeats endlessly (new data added after old) in the rich text box with the line

    richtextbox1.text = richtextbox.text & chr(text)

    If I use the line

    richtextbox1.text = (text), it overwrites the data with the new data (which I want) but only one character at a time.

    Any way to have it overwrite the appropriate temp data continously?

    thanks
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-07-21 01:30
    Hi fsb , thats great , not the fact the template worked but the fact that you figured out a solution for your own application.

    There are too many scenarios to cover every possibility so the examples tend to revolve around key points in achieving an objective , the rest is up to the user as you demonstrated.

    An alternative for your temperature display , and I think this is what you are asking , is to transmit the temperature value from the Stamp and append a NewLine character. At the VB end instead of reading single bytes read your value as a string of bytes. The addition of the·NewLine character ( 10 ) allows the use of _port.ReadLine .

    I'm kind of guessing what your code is but I think your at the Simple Debug app from what you describe. I have edited Form 1 code to work as above ,·in the edits I have got rid·of the RichTextbox and replaced it with a Label , I think this will look better··but it's whatever you prefer.

    this would be the serial instruction from the Stamp·

    SEROUT 16,16468,[noparse][[/noparse]DEC x,10]
    I have not tried this , if you have problems let me know
    Jeff T.
  • fsbfsb Posts: 24
    edited 2010-07-22 05:07
    Jeff,

    Awesome work! The code is exactly what i needed. I did try to figure it out myself, but couldn't. Glad I asked.

    The next step is to add data from two additional sensors to two additional text boxes.

    Given this stuff is what keeps my middle age to old brain active, I'm gonna try to figure it out myself.

    If I get stuck, I probably will be asking for help again (although a hint or two in the right direction wouldn't be bad).

    Again, thanks alot. I will keep you posted as the project progresses.

    Frank
  • andrewbenimaruandrewbenimaru Posts: 6
    edited 2010-08-03 04:05
    hi jeft this is my code that i try to receive the value it send but it didn't work
    i have download the template but how to make it works?
    can you give me some of the sample?
    below is the code i have try but i don't get what is "x" mean in the program.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    main:
    SEROUT 16,16468,[noparse][[/noparse]"#"]
    SERIN 16,16468,25,timeout ,[noparse][[/noparse]DEC1 x]
    timeout:
    ON x GOSUB Halt,Forward,Back,Right,Left
    GOTO main
    END


    Halt:
    DEBUG "1"
    RETURN

    Forward:
    DEBUG "2"
    RETURN

    Back:
    DEBUG "3"
    RETURN

    Right:
    DEBUG "4"
    RETURN

    Left:
    DEBUG "5"
    RETURN
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-08-04 01:32
    Hi Andrew , do you have the Com Template installed , you should have a VB app that looks similar to the image I have attached.

    The Stamp code and Visual Basic program use the programming port (P16) to communicate , that means you cannot use the DEBUG instruction in the Stamp code. To test you are communicating try switching an output that has an LED connected.

    Jeff T.
    375 x 389 - 24K
  • benimarubenimaru Posts: 3
    edited 2010-08-08 19:06
    hi jeff

    i have try another ways of connection from vb to basic stamp it's works,but the result is not i want, i sure the message have send in the boe-bot car.
    VB program
    Imports System.IO.Ports
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    btnOpenPort.Text = "open"
    btnReceive.Text = "receive"
    Label1.Text = "comunicate"
    Label2.Text = "data send"
    Label3.Text = "data received"
    cmbPort.Items.Clear()
    For Each PortName As String In SerialPort.GetPortNames
    cmbPort.Items.Add(PortName)
    Next
    cmbPort.SelectedIndex = 0
    End Sub
    Private Sub btnOpenPort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenPort.Click
    If SerialPort1.IsOpen Then
    SerialPort1.Close()
    btnOpenPort.Text = "open"
    txtReceive.Text = " "
    up.Enabled = False
    down.Enabled = False
    right.Enabled = False
    left.Enabled = False
    pause.Enabled = False
    btnReceive.Enabled = False
    Else
    SerialPort1.PortName = cmbPort.SelectedItem.ToString
    SerialPort1.BaudRate = 9600
    SerialPort1.Parity = Parity.None
    SerialPort1.DataBits = 8
    SerialPort1.StopBits = StopBits.One
    SerialPort1.Open()
    btnOpenPort.Text = "close"
    up.Enabled = True
    down.Enabled = True
    right.Enabled = True
    left.Enabled = True
    pause.Enabled = True
    btnReceive.Enabled = True
    End If
    End Sub
    Private Sub up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles up.Click
    SerialPort1.Write(up.Text)
    End Sub

    Private Sub right_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles right.Click
    SerialPort1.Write(right.Text)
    End Sub

    Private Sub left_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles left.Click
    SerialPort1.Write(left.Text)
    End Sub

    Private Sub down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles down.Click
    SerialPort1.Write(down.Text)
    End Sub

    Private Sub pause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pause.Click
    SerialPort1.Write(pause.Text)
    End Sub
    Private Sub btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click
    txtReceive.Text = SerialPort1.ReadExisting()
    End Sub
    End Class
    Basic stamp
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    dat VAR Word
    DO
    SERIN 6,84,[dat]
    'DEBUG ? dat,CR
    IF dat>0 THEN
    SEROUT 6,84,[dat]
    ENDIF
    LOOP
    END
    i sure it receive the message and send me the data i want , but it doesn't really send a data to boebot truelly receive and send it back it seen like send data to basic stamp and data send back is from vb.
    i was confused about it.
    i like to test the motor using vb to basic stamp how it works?
    how it get the data i send?

    ~andrew
  • benimarubenimaru Posts: 3
    edited 2010-08-11 22:41
    hi jeft


    i have found the solution about the transfer anyone want to know can ask me
    about it.

    now i have new problem i need a connection from form A to form B how can i do about this.can anyone teach me please:D
  • DooballDooball Posts: 4
    edited 2010-10-18 08:00
    Hi, I am new to VB and the BS2. I wanted to know does the VB communication template work with the usb BOE or is the serial version required?
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-10-18 08:17
    It will work just fine with a USB bot. The USB interface just comes up as a COM port, and that's all that VB needs.
  • lwcyblwcyb Posts: 13
    edited 2011-12-15 08:07
    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

    I've been playing around with this and successfully made a circular temperature gauge using this code, really neat stuff. What I've been trying to do recently is add another needle to the gauge, but I'm having a bit of trouble with it. I added a new property (the value for the second needle) but it doesn't seem to show up. I assumed you could just use the code from the property for the first needle and copy it to the property for the second needle, but the second needle does not show and changing the second needle property's value does not affect anything. Any tips or tricks for this?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-15 08:48
    Hi, I have two or three different methods for creating a dial/gauge. The original problem that I had was finding good examples on the Internet and until recently that was the best that I could find. Earlier this year I did a little reading up on graphics and came up with what I consider to be a much better way of doing things. I don't have the code on this PC so I will post it later.It's faster and more versatile allowing for easier adjustment of needle length and placement on the dial face. I have thought about using two needles on the same dial but as yet not tried it, I think this new method should do it ok.

    Jeff T.
  • stamptrolstamptrol Posts: 1,731
    edited 2011-12-15 10:34
    Hi Jeff,

    And by all means, if it can help, the Quiktrol software is still available and appearing regularly in training sessions!

    See it in action: http://youtu.be/JvG6TBVrh8c


    Regards,

    Tom
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-15 16:49
    @Tom, an excellent video, I believe I mentioned once before I think its great that your using it as part of an educational excersise.

    @ lwcyb Ok here are two text files that contain code for a VB Net Usercontrol named Gauge. The first file is the basic code used in both instances and is used to create a dial or gauge with one needle. The second file is a gauge or dial with two indepedently controlled needles. The needle rotation is achieved using the Graphics.RotateTransform.

    File one has an integer "angle" property that will spin the dial through 360 degrees and file two has two properties, one for each needle, "angle" and "angle2". This code is much easier to work with than the previous code I have posted .

    Here is a list of tips for guidance

    1./ When creating the user control be sure to make DoubleBuffered=True
    2./ Make the face of the dial the user controls background image (centered)
    3./ Size the user control to a square with the dimensions you want the final control.
    4./ Create your needle graphic in a square of odd numbered pixels, pivot in the center, transparent background.
    5./ Place the needle graphic(s) in application Resources.

    The needle can be sized if it needs tweaking and the pivot does not have to be central, if you wanted you could place two needles in opposite corners of the user control each operating independently. The code has comments on where to make these adjustments. Please give feedback of your opinion, or ask if these instructions are not complete.

    Jeff T.
  • lwcyblwcyb Posts: 13
    edited 2011-12-19 08:21
    Jeff,

    The code works great. Just a note about positioning the needle graphic, and as an example:

    I have a 200x200 pixel size gauge face image, to center the needle on the gauge face I set the rectangle positions to

    Dim _rect As New Rectangle(-80, -2, 1, 1)
    Dim _rect1 As New Rectangle(-80, -2, 1, 1)

    The needle image I am using is 120x3 pixels, with the pivot point set at 60 pixels.

    Like in the previous example, to test this you can set up a trackbar, and set the gauge value equal to the trackbar value:

    Private Sub TrackBar1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
    Samplegauge1.angle = TrackBar1.Value
    End Sub
Sign In or Register to comment.