Shop OBEX P1 Docs P2 Docs Learn Events
VB to BS2 — Parallax Forums

VB to BS2

ProcessingData...ProcessingData... Posts: 208
edited 2009-01-13 01:47 in BASIC Stamp
How Do i Get VB to Recieve Seirial Output From My Stamp, and act upon it?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Basic Stamp,···· Propeller,·· · SX,·· FUN!


START:·
>Proccessing Data. . . .··
>Task Complete. . .·.
>Saving Data. . . .
>Entering SLEEP Mode. . . .
>Signing OFF




Post Edited (ProcessingData...) : 1/9/2009 7:28:21 PM GMT
«1

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-01-08 01:43
    How do you get VB to receive ANY serial data and act upon it? The stamp works the same as any other serial input.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • $WMc%$WMc% Posts: 1,884
    edited 2009-01-08 01:48
    ProcessingData

    You'll have to download or write a RS232 serial driver!
    something like this

    DEFINT a-z
    $COM 1024
    OPEN "COM1: 9600,N,8,1" AS #1 LEN =1024
    echo =1
    WHILE (1)
    WHILE NOT INSTAT
    IF LOC(1)>0 THEN
    YOUR$ = INPUT$(LOC(1),#1)
    ? YOUR$:
    END IF
    WEND
    WHILE INSTAT
    myinput$ = INKEY$
    ? #1,myinput$:
    if echo then ? myinput$;
    WEND
    WEND


    Some COM ports will need All cap. letters
    This should get You started if Your in to Basic.
    This just opens the COM port, set all data to integers with"DEFINT a-z"This makes Var. smaller and faster.
    $COM is a 1024 bit FIFO buffer
    All thats left is the TX/RX out/in

    ______$WMc%____________

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there·········································· E=$WMc%2

    Post Edited ($WMc%) : 1/8/2009 2:05:36 AM GMT
  • KB3JJGKB3JJG Posts: 95
    edited 2009-01-08 02:29
    I edited this post with a different example, one a bit more clear

    send the data from your bs2 using debug like this

    y VAR Byte
    FOR y = 1 TO 20
    DEBUG DEC y, CR
    PAUSE 500
    NEXT




    Make a form, with a textbox called textbox1

    paste the following code in, you may have to change your com port in the 5th line, when you run your tsamp program you should see the values count up in your VB app.

    [color=#0000ff][color=#0000ff]Imports[/color][/color][color=#000000] System[/color]
    [color=#0000ff][color=#0000ff]Imports[/color][/color][color=#000000] System.IO.Ports[/color]
    [color=#0000ff][color=#0000ff]Public[/color][/color] [color=#0000ff][color=#0000ff]Class[/color][/color][color=#000000] Form1[/color]
    [color=#0000ff][color=#0000ff]Dim[/color][/color] [color=#0000ff][color=#0000ff]WithEvents[/color][/color] port [color=#0000ff][color=#0000ff]As[/color][/color] SerialPort = [color=#0000ff][color=#0000ff]New[/color][/color] _
    System.IO.Ports.SerialPort([color=#a31515][color=#a31515]"COM3"[/color][/color], 9600, Parity.None, 8, StopBits.One)
    [color=#0000ff][color=#0000ff]Private[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color] Form1_Load([color=#0000ff][color=#0000ff]ByVal[/color][/color] sender [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]Object[/color][/color], [color=#0000ff][color=#0000ff]ByVal[/color][/color] e [color=#0000ff][color=#0000ff]As[/color][/color] _
    System.EventArgs) [color=#0000ff][color=#0000ff]Handles[/color][/color] [color=#0000ff][color=#0000ff]Me[/color][/color].Load
    CheckForIllegalCrossThreadCalls = [color=#0000ff][color=#0000ff]False[/color][/color]
    [color=#0000ff][color=#0000ff]If[/color][/color] port.IsOpen = [color=#0000ff][color=#0000ff]False[/color][/color] [color=#0000ff][color=#0000ff]Then[/color][/color] port.Open()
    [color=#0000ff][color=#0000ff]End[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color]
    [color=#0000ff][color=#0000ff]Private[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color] port_DataReceived([color=#0000ff][color=#0000ff]ByVal[/color][/color] sender [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]Object[/color][/color], [color=#0000ff][color=#0000ff]ByVal[/color][/color] e [color=#0000ff][color=#0000ff]As[/color][/color] _
    System.IO.Ports.SerialDataReceivedEventArgs) [color=#0000ff][color=#0000ff]Handles[/color][/color] port.DataReceived
    TextBox1.Text = (port.ReadExisting)
    [color=#0000ff][color=#0000ff]End[/color][/color] [color=#0000ff][color=#0000ff]Sub[/color][/color]
    End [color=#0000ff][color=#0000ff]Class[/color][/color]
    
    




    Thats it in the most simple form, if you are very new to VB I suggest doing some more simple tutorials like a hello world or something more noob friendly. If not check out the MSDN docs and remember google is your friend. Receiving serial data from a stamp is not different that receiving it from any other device, so any example code you can find will generally apply. JUst remember your serial must reveive at 9600,8,n,1 and if you try and send data to·the stamp from an app using the programming port (16), it will reflect back whatever you send to it, so code accordingly.








    Post Edited (KB3JJG) : 1/8/2009 3:07:55 AM GMT
  • sylvie369sylvie369 Posts: 1,622
    edited 2009-01-08 03:01
    Here's what explained it to me:

    www.theabramgroup.com/basicstamp/
  • ProcessingData...ProcessingData... Posts: 208
    edited 2009-01-08 20:46
    OK, I am·Relatively New To VB, and have created some projects, but none involving serial comm.
    Thank you for your help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Basic Stamp,···· Propeller,·· · SX,·· FUN!


    START:·
    >Proccessing Data. . . .··
    >Task Complete. . .·.
    >Saving Data. . . .
    >Entering SLEEP Mode. . . .
    >Signing OFF




    Post Edited (ProcessingData...) : 1/8/2009 9:03:41 PM GMT
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2009-01-08 23:47
    Stephen--

    Are you using VB 6.0 or VB Express? I am a VB 6.0 programmer, but I know nothing about VB Express. Perhaps, the way I have my Stamps talking to VB 6.0 is different from the way one would do it with VB Express.

    By the way, I have been a Visual Basic programmer since the DOS Days and VB for DOS. However, I never handled serial comms. Thus, it was very difficult for me to get the Stamp talking to VB 6.0. Someone finally GAVE me a crude program upon which I built a little more. I still haven't put all the functionality in, but it won't be a big problem now that I know how to make them play nice together.

    I used to write comm programs in 8080 Assembler before BASIC was released, but then I am real old, too.

    --real old Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-08 23:58
    KB,

    I'm trying to learn the same thing. I want BS2 to send a byte and display it in a VB2005 textbox.

    I bought Serial Port Complete 2nd edition. I see how RS232 communication uses -3v to positive 3v as 0 and 1. Basic Stamp just uses near <.8v and +2.5v as it's 0's and 1's. These CMOS voltages will still work for RS232...I think???

    I'm using VB2005 express. It has a builtin function serialport1. What version VB is your code for V6? Or am I missing something???

    Cunfused... I'll try your code tonight. TY Any other pre-K help is welcomed!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com
  • $WMc%$WMc% Posts: 1,884
    edited 2009-01-09 01:08
    I think that You'll find the use of the DCE RS232 com setup "like the one on the BS2Pro.Deveop.Board" Will handle most of the issues with Your Com problems."Voltages, +/- Etc"......

    I would reserve the DB9 Program jack for Programing and DEBUG back to the programing PC. This will leave You with two DB9 jacks, One for programing and One for serial COM."DCE"

    _________________$WMc%____If You really want to do something in BASIC try _PowerBasic 3.5_

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there·········································· E=$WMc%2
  • KB3JJGKB3JJG Posts: 95
    edited 2009-01-09 02:21
    My code was written in VB.NET 2008, but it should work in 2005. I have an old laptop that still has 2005 installed, I wll dig it out when I am in my office in the morning and test it out.

    There is a big difference in serial comms when you switch from VB 6.0 to .NET, in 6.0 is was the mscomm control and was relatively simple to use, .NET made it a little harder as the application no longer has control directly over the serial port and relies on win32 calls to handle the communication.

    Rob, When you are using the programming port the differences in rs232 levels are taken care of for you.· If you were to hook the serial port to one of the 16 stamp·I/O·pins, you would need a line driver circuit to handle the change.

    Additionally, the code I provided as a sample creates the serial control you are talking about programatically instead of dropping it on the form. You could omit the first part and drop the control on the form and set the appropriate parameters if you were so inclined.


    I have attached a zip file with the Studio 2008 files you will need, remember you may need to edit it to reflect your COM port. I use a serial to USB adaptor and my COM port is 3

    Paste the bs2 code in my first post into the bs2 editor, or you can really debug anything and it should show up.

    Post Edited (KB3JJG) : 1/9/2009 2:31:10 AM GMT
  • ProcessingData...ProcessingData... Posts: 208
    edited 2009-01-09 02:40
    I'm using 6.0 for this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Basic Stamp,···· Propeller,·· · SX,·· FUN!


    START:·
    >Proccessing Data. . . .··
    >Task Complete. . .·.
    >Saving Data. . . .
    >Entering SLEEP Mode. . . .
    >Signing OFF


    ·
  • KB3JJGKB3JJG Posts: 95
    edited 2009-01-09 02:44
    ProcessingData,

    I don't have 6.0 on my home computer, I do have it installed on one of my office workstations. I will see about recreating the same example after a morning meeting. Alternatively, you can get VB.Net 2008 express for free, might be worth spending yout time getting up to speed on the modern version of this language.

    DL 2008 here

    http://www.microsoft.com/Express/VB/

    ·
  • ProcessingData...ProcessingData... Posts: 208
    edited 2009-01-09 02:48
    OK. Thank you for your time, KB3JJG.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Basic Stamp,···· Propeller,·· · SX,·· FUN!


    START:·
    >Proccessing Data. . . .··
    >Task Complete. . .·.
    >Saving Data. . . .
    >Entering SLEEP Mode. . . .
    >Signing OFF


    ·
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-09 03:22
    Thank you all for your extended help.· Tomorrow and the weekend I'll be working hard on this.

    KB some great writups my thick head has to read slowly and digest.· I was using IO pins and not the built in com port.· So the CMOS logic levels won't be enough to trigger the RS232 levels?

    Nice weblink Sylvie!

    If any other thoughts come to mind please do write it up!!!· I'm using mostly VB2005exp but also have VB2008exp.

    My Project?· I'm trying to build an interface for tach, temp and other·sensors to create an engine dynometer program.· Likely I'll have to switch to a propeller chip sometime to multitask servo throttle controls and such.· Early stages here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-01-09 03:54
    This is not anything different to what has already been posted but perhaps the information at this link can add some additional insight and help you get started

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

    The thread contains various methods for transmitting and receiving serial data PC to BS2 and a couple of programs near the end of the thread , one for sending direction commands and some code for creating your own dial gauges.

    VB Express is a hobby for me so everything in the above mentioned post can probably be improved on to some degree or another, but the code throughout is kind of progressive and should be relatively easy to understand.

    Jeff T.
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-09 11:49
    Very nice gesture as well Jeff. Well written! I'm at work now but when I get home I have lots of things to try!

    Not sure yet but I may have a stumbling block. I have the BS2 with the USB interface. Might not matter. Just have to hook in ahead of the USB interface. We'll see!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-01-09 19:10
    Communications between the BS2 and PC are treated the same within Visual Basic with both the USB and DB9 interface so you should have no problems there.

    Jeff T.
  • ProcessingData...ProcessingData... Posts: 208
    edited 2009-01-10 20:35
    Hi, i'm back again. It worked with VB '08, thanks a lot for your help.

    I still need help for this project I'm working on though. I'm trying to develop a system that will detect water and, when detected,·send a message back to my computer, listing which stamp detected it. I will have about 20 - 30 stamps·connected to the same·COM Port, and·I also need them·to be able to reset, change their number, and turn off, all from the computer, running a VB Program. Attached is the BS2 code I've come up with. It isn't complete, so feel free to edit it and post it back here. Any help would be greatly appreciated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Basic Stamp,···· Propeller,·· · SX,·· FUN!


    START:·
    >Proccessing Data. . . .··
    >Task Complete. . .·.
    >Saving Data. . . .
    >Entering SLEEP Mode. . . .
    >Signing OFF




    Post Edited (ProcessingData...) : 1/10/2009 9:42:05 PM GMT
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-10 20:45
    I see... I have the basics working!! Thanks all. Alot to learn and progress from here.

    tachcontrol: '*** Tachometer *********************
    COUNT 13, 187, tachcount 'tach input; count (pin13), (msec), (variable)
    wheelRPM = tachcount * 10 'scale = 60/(COUNT:seconds)/number of pickups
    engineRPM = (wheelRPM * gratio) + ((wheelRPM * gratiofrac)/100)
    DEBUG " RPM-"
    DEBUG DEC4 engineRPM
    RETURN

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If SerialPort1.IsOpen = True Then
    TextBox1.Text = SerialPort1.ReadExisting
    End If
    End Sub

    As you can see I have a Tachometer program in the BS2 that Display the RPM in a TextBox using a timer to update the textbox.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-11 16:49
    I've heard you guys mention you run the BS2 DEBUG at 2400 BAUD? Am I correct? I do see at 9600 sometimes the buffer write line must get out of order. Is this why?

    My VB textbox1.text should read

    " RPM-4800 RPM-4780 RPM-4780" and so on...

    But on occasion it appears to clip things to another write session. Like this

    "00 RPM-4780 RPM-4780" and the next line will finish the sequence.

    Not a big deal. I think I can work with it. Maybe just do some sort of a string search for the word RPM to keep things flowing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-01-11 18:17
    Hi Rob, if you can mark the beginning and the end of you serial data it will help you capture the right information at the receiving end. The simplest way in this situation would be to·terminate your RPM data with a newline character and use SerialPort1.ReadLine. ReadLine will read characters upto the newline each time so the repetitive transmission of data and newline·will "bracket" your data. BTW the character code for newline is 10.

    ·RPM-4800 10 RPM-4780 10 RPM-4780 10 RPM-4800 10 RPM-4780 and so on

    Your DEBUG line will now look like this DEBUG "RPM-",DEC4 engineRPM,10

    As an additional note it would be my preference to use SEROUT as opposed to DEBUG when using P16, it gives you a few more options on the way you are able to format your serial string.

    Jeff T.
  • JamesDoughertyJamesDougherty Posts: 48
    edited 2009-01-12 02:24
    I am not sure how I missed this topic... There are a couple of different ways and I would recommend using .NET since it is managed code and a lot easier to program with. However, just so people are aware about it there are two ways of doing it using VB6 and .NET (VB.NET, C#, etc.).

    VB6
    1) There is a control called "MSCOMM" that you can use to interface with the serial port. To use it just select "Microsoft Comm Control 6.0" under the components and then drop the control on your form. However,·I tried it earlier playing around and I couldn't get it to recognize my COM2 port, which is a·COM->USB adapter.
    2) Use more low level like the·good old days via Win32 API. You can·use the CreateFile API to open the port and then use the read/writes to the file to actually communicate with the serial port. It's been a long time since I have done this and it is more complex, but it's low level (which I like).

    .NET (VB, C#, etc.)
    1) Use the serial port control
    2) Use System.IO.Ports namespace (which is what I did here: http://forums.parallax.com/showthread.php?p=774539). You can take a look at that project as it has a class in there for the communication. It should be pretty simple to convert to VB.NET.
    3) Use the Win32 API like above.

    C++
    1) Use the Win32 API like above.
    2) Use inline ASM (no need for that anymore though with current technology).

    USB is a lot more complex as it uses stacks, you can insert/remove USB devices at any time, etc. (notice there is no default control to interface with the USB) I am working on one at the moment on the side for a project I am working on.

    If you want to see another example look at the "StampWorks" book. In experiment #34 they give an example on how to communicate with the serial port in there as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James Dougherty

    Ariel Productions
    http://www.arielproductions.com/
  • JamesDoughertyJamesDougherty Posts: 48
    edited 2009-01-12 02:30
    @Rob - I just noticed in your post you use the Windows timer. Try to avoid this for this type of application because there is no need to waste CPU cycles.·I am not sure if you are using the serial port control or if you are using the System.IO.Ports, but they both should have an event handler for·when Data is received.·When actual data is being received you will be notified of·it as that event·will fire.

    communicationPort.DataReceived += [color=#0000ff][color=#0000ff]new[/color][/color] [color=#2b91af][color=#2b91af]SerialDataReceivedEventHandler[/color][/color](communicationPort_DataReceived);
     
    [color=#0000ff][color=#0000ff]
    private[/color][/color] [color=#0000ff][color=#0000ff]void[/color][/color][color=#000000] communicationPort_DataReceived([/color][color=#0000ff][color=#0000ff]object[/color][/color][color=#000000] sender, [/color][color=#2b91af][color=#2b91af]SerialDataReceivedEventArgs[/color][/color][color=#000000] e)[/color]
    
    {
    
        //--New data is being received from the serial port...
    
        //--Use communicationPort.ReadExisting() to read the data coming in
    
    }
    
    
    

    Hope this helps.

    [noparse]/noparse][b]EDIT[/b

    Just noticed, by the name, that you are using the control. Like I said, there should be an event for that as well for the data received. It may be something like this (I am not 100% sure without looking, but...) serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James Dougherty

    Ariel Productions
    http://www.arielproductions.com/

    Post Edited (JamesDougherty) : 1/12/2009 2:35:50 AM GMT
  • RICoderRICoder Posts: 91
    edited 2009-01-12 04:16
    I have seen a lot of people posting code using the Port component in Visual Studio (VB / C# / et al) and I need to point some things:

    1) You cannot modify a control on the main form from within the DataRecieved event (someone had that in their code). It is a different thread, and will most likely throw an error, and if it tries to work, it will be unreliable at best.

    2) DataReceived MAY or MAY NOT be called by the underlying system, so you may get it called after 2 bytes or 20 or 1...you just never know.
  • JamesDoughertyJamesDougherty Posts: 48
    edited 2009-01-12 13:03
    Yes, it is indeed a different thread. To emphasis you will need to use a delegate and then "invoke" it. For instance, something like the following will work:

    [color=#0000ff][color=#0000ff]//--Define this at the class level
    private[/color][/color] [color=#0000ff][color=#0000ff]delegate[/color][/color] [color=#0000ff][color=#0000ff]void[/color][/color] [color=#2b91af][color=#2b91af]DataReceivedCallback[/color][/color][color=#000000]([/color][color=#0000ff][color=#0000ff]string[/color][/color][color=#000000] data);[/color]
     
     
     
    [color=#000000]//--Then in the data received even use it like this:[/color]
    [color=#0000ff][color=#0000ff]
    this[/color][/color][color=#000000].Invoke([/color][color=#0000ff][color=#0000ff]new[/color][/color] [color=#2b91af][color=#2b91af]DataReceivedCallback[/color][/color][color=#000000](ProcessData), [/color][color=#0000ff][color=#0000ff]new[/color][/color] [color=#0000ff][color=#0000ff]object[/color][/color][color=#000000][noparse][[/noparse]] { SerialPort1.ReadExisting() });[/color]
    
     
    
    [color=#000000]//--This is where you can use controls on the form[/color]
    
    
    [color=#0000ff][color=#0000ff]private[/color][/color] [color=#0000ff][color=#0000ff]void[/color][/color][color=#000000] ProcessData([/color][color=#0000ff][color=#0000ff]string[/color][/color][color=#000000] data)[/color]
    
    {
    
        txtData.Text += data + [color=#a31515][color=#a31515]"\r\n"[/color][/color];
    
    }
    
    



    There is also a RevokeRequired that will tell you if you need to invoke or not, but in this case you will always need to. However, you can use it like this:

    if (InvokeRequired)
    {
        //--Call invoke
    }
    else
    {
        //--Send the data directly to the control
    }
    

    There could be a couple of reason as to why the data is not being received right away and one being that the program sending the data is not allowing enough time for the information to be processed by the receiving program. If you are sending the data from BS2, for example, then have a pause in there to give the program enough time. Other times it just simply happens. However, there is a VB.NET sample, a C# sample, etc. so there should be no reason that they shouldn't be able to figure it out. Thank you for pointing that out though, I was wondering if or when it would come up smilewinkgrin.gif
    RICoder said...
    I have seen a lot of people posting code using the Port component in Visual Studio (VB / C# / et al) and I need to point some things:

    1) You cannot modify a control on the main form from within the DataRecieved event (someone had that in their code). It is a different thread, and will most likely throw an error, and if it tries to work, it will be unreliable at best.

    2) DataReceived MAY or MAY NOT be called by the underlying system, so you may get it called after 2 bytes or 20 or 1...you just never know.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James Dougherty

    Ariel Productions
    http://www.arielproductions.com/
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-12 15:02
    I know I'm not up to speed with VB2005 but as I learn and fail I'll surely reference what you guys are trying to help me with!

    James, On a side note the timer. I see what you mean. I had issues trying to use it as I was. The program would error out if there was no data to recieve (timing too fast) or the program would lag in RPM changes as the buffer got behind. It's all new to me. Here is what I was able to do to get by as I'm learning. The timer will go out the window soon as I learn more about VB.

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If SerialPort1.IsOpen = True Then
    >If SerialPort1.BytesToRead > 1 Then
    TextBox1.Text = SerialPort1.ReadExisting
    End If
    End If
    End Sub

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com

    Post Edited (rob jackson) : 1/12/2009 4:03:17 PM GMT
  • JamesDoughertyJamesDougherty Posts: 48
    edited 2009-01-12 15:29
    That's a good way to learn, but just take your time so you don't get frustrated. I can remember times it would take hours to figure out a bug, but problem solving and logic is the name of the game smilewinkgrin.gif

    As you get the basics of it working and feel comfortable with it you will be able to improve upon it.

    As a tip, use the try/catch to keep your program from crashing. It will "try" to do something and if you get an error because of it the program will "catch" it and handle it safely. Something like this:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            If SerialPort1.IsOpen = True Then
                If SerialPort1.BytesToRead > 1 Then
                    TextBox1.Text = SerialPort1.ReadExisting
                End If
            End If
        Catch ex As exception
            '--You can show a message, dump it to the console, or just ignore it
            '--and your program will continue to run (granted that it is not a critical error)
            MessageBox.Show("Error: " + ex.Message)
        End Try
    End Sub
    



    BTW: Is the two "End Sub" at the end a type?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James Dougherty

    Ariel Productions
    http://www.arielproductions.com/
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-12 15:56
    A little background for you guys on what my intents for learning the BS2 and Com port work to VB2005 or newer.

    I've always been into racing. Many years RC Car racing and as of recently 7 years of go-kart racing. I've built a couple engine dynometers using another guys (OnTrack Digital Dyno)·software from Austrailia. He uses the audio in of a sound card to count the timing of "clicks" as a magnet passes by sensor.

    I hate being dependant on someone elses software for the crude dynometers I've built. I'd like to add some temp and humidity sensors and such to compensate. Therefore I'd like to use the BS2 or Propeller to collect the RPM, Cyl.Head Temp, EGT, Humidity and maybe even servo control the throttle and brake system all in one interface. From this I just want to send the raw serial data to VB and process it Realtime...

    After that I'd love to do maybe an RF, IR or RFID lap counting race managment type software. Mostly to help out our local tracks and be able to record fast laps and display speeds etc....

    I took a community college class using VB6. Very limited exposure. The teacher was learning as we went as well. So that really sucked. I have taken some college classes and programmed the Motorolla HC11 and a PIC. It's been quite awhile. So I'm not a totally lost cause but it will take some time to get up to speed!

    As I go. I'm very grateful for the support you guys have given me so far!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com

    Post Edited (rob jackson) : 1/12/2009 4:04:28 PM GMT
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-12 15:59
    BTW: Is the two "End Sub" at the end a type?

    James, Yeah cut/copy/paste mistake on my end!

    I'll have to look the catch/try stuff up. I'm not familar with it...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com
  • JamesDoughertyJamesDougherty Posts: 48
    edited 2009-01-12 16:26
    I used it a lot when I did game development in good ol' VC++. It very useful and a must have. Your story struck me as kind of funny, because I am the same way. A lot of people use to ask me "why would you reinvent the wheel?" and I would simply say, "Why Not!". I am the type that wants to learn how it works, not just piece a bunch of libraries and whatnot together. Kudos to you!

    Best of luck on your project. If you have any programming questions then please feel free to let me know.
    rob jackson said...
    BTW: Is the two "End Sub" at the end a type?

    James, Yeah cut/copy/paste mistake on my end!

    I'll have to look the catch/try stuff up. I'm not familar with it...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    James Dougherty

    Ariel Productions
    http://www.arielproductions.com/
  • rob jacksonrob jackson Posts: 23
    edited 2009-01-12 16:44
    Here is the control panel and DYNO I built.

    I used the BS2 to control Brake and kill switch and displayed the Tach.· It monitored the flywheel RPM and prevented someone from reving it above 1800RPMs.

    The servo was controlled using a board from Servocity.· The BS2 was too busy to handle the servo also.

    Now I want to control the HP, Torque and sensor data in VB.· With the help of the BS2 or Propeller of coarse!· I have an extra BS2 kicking around is why I'm using it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank You,


    Rob Jackson
    oleancomputers.com

    Post Edited (rob jackson) : 1/12/2009 4:53:41 PM GMT
    1242 x 1656 - 512K
    1656 x 1242 - 588K
    1656 x 1242 - 597K
    1656 x 1242 - 608K
Sign In or Register to comment.