Shop OBEX P1 Docs P2 Docs Learn Events
Serial comms with visual basic — Parallax Forums

Serial comms with visual basic

realolmanrealolman Posts: 65
edited 2009-03-02 04:40 in Propeller 1
So far, what I have learned about the propeller, I like.

I need to communicate with it from a Visual Basic Express application using System.IO.Ports.SerialPort

·OR

·an app written in Visual Basic.NET 2003·or Visual Basic Version 6.0 using MsComm

I would prefer using· SerialPort simply because it seems to be the most modern ..· I really don't want to use VB6

I always have had a lot of trouble using MsComm with VB6, although I have done it....

I don't understand the System.IO.Ports.SerialPort business at all.

I know this is not a propeller issue , but to me communication with the propeller through a Visual Basic app is essential, ·or the propeller is of little use...· It works fine through the Parallax Serial Terminal, but I want my own app with its own variables and appearence.

I swear Microsoft doesn't really want to explain the stuff at all... I can't find anything that I understand...
It seems all I can ever find is totally basic stuff ... or advanced stuff


Could some one help me out

thanks

Post Edited (realolman) : 1/28/2009 10:12:18 PM GMT

Comments

  • lonesocklonesock Posts: 917
    edited 2009-01-28 22:19
    Just a quick note, and this is strictly IMO: if you are OK moving to VB.NET 2008 Express Edition, I've found it quite a bit easier to do COM work than on 2003 (or 2005 for that matter). Microsoft does have some code examples. (Sorry if you already knew that link).

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lonesock
    Piranha are people too.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2009-01-28 22:26
    http://www.instructables.com/id/Control-real-world-devices-with-your-PC/ is an example I wrote for interfacing to a picaxe. Step 12 has the vb.net 2008 express code to interface to the serial port.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-01-28 22:38
    Hello,

    I haven't worked with any VB. (don't like MS at all)

    How about moving to Delphi ?

    There are a lot of free resources and forums

    best regards

    Stefan
  • Bill DrummondBill Drummond Posts: 54
    edited 2009-01-28 22:50
    "How about moving to Delphi ?"

    Have you seen what they're charging for DELPHI now!

    You'll need a student discount and $150.
  • Alex BellAlex Bell Posts: 17
    edited 2009-01-29 00:05
    Try Liberty Basic at www.libertybasic.com ...There is a terminal application in Liberty Basic i use with Windows XP all the time.
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-01-29 02:25
    I found the same problem with VB Express 2008. However, I though I read somewhere that you can still use the old MSCOMM from VB6, which was a lot easier.

    I dont do a lot of programming in VB anymore, but VB6 was easy whereas VBE (VB.net) seems so difficult to get anything running. A lot of commercial programmers are still refusing to move on and stick to good old VB6. So M$ have to still accept it.

    Just my 2c.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Prop Tools under Development or Completed (Index)
    · Emulators (Micros eg Altair, and Terminals eg VT100) - index
    · Search the Propeller forums (via Google)

    My cruising website is: ·www.bluemagic.biz
  • Steve NelickSteve Nelick Posts: 25
    edited 2009-01-29 02:50
    In Visual Basic, you create a Windows Form Application. You will be looking at your Form on the screen, and on the left is the ToolBox, with Button, TextBox, .....
    One of the objects in the ToolBox is SerialPort. Add a SerialPort to your Form. The name of the SerialPort will be SerialPort1.

    Search in the VB Help for SerialPort, and you will see the members of the SerialPort class.

    Some of the properties that you will be using are PortName, IsOpen, and BytesToRead.

    Some of the methods that you will be using are: Open, ReadByte, Write, and Close.

    You will need to set the property PortName. You can get the PortName from the Propeller Tool. In the Propeller Tool select the menu item Run. Then select Identify Hardware. You will get a message like 'Propeller chip version 1 found on COM11'.

    So you will set your SerialPort1.PortName to COM11.
  • RICoderRICoder Posts: 91
    edited 2009-01-29 03:18
    I attached some code for you [noparse]:)[/noparse]

    The thing with .Net serial port is that it is synchronous, and to support that you really can't be living in a method and waiting for the data to come in. That means you have to use threads, and that...well...its just complicated. The object itself is quite simple once you understand that, and once you understand how to deal with threads within objects within a forms application...which is definitely not non-coder friendly.

    The attached code was written in C#, but the awesomeness of .Net's C# and VB reworking is that they are quite similar. Personally, I'd say make the jump to C# instead of using VB, but that's your call. Either way, the attached code is from a User Control object that I made to simplify exactly what you are talking about. If you can create an empty OCX and port this to VB (should be easy enough) then you'll be fine.

    THE ONLY CAVEAT I have is this: I wrote this to look for MESSAGES over serial, meaning it will pick up the traffic coming over the wire, waiting for start and stop characters (I used a ~). When it has a complete message, it raises an event, which you can trap in your code and do with what you choose.
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-01-29 10:08
    'Unsoundcode' has done quite a bit breaking this down into easy to follow steps .. see attached post

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


    Rgds,
    John Twomey

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    Those who can, do.Those who can’t, teach.
  • realolmanrealolman Posts: 65
    edited 2009-01-29 10:47
    You guys are unbelievable.

    I think this is the friendliest, most helpful forum I have ever seen.


    Thank you.

    I have been using Basic since personal computers were invented, and I was pretty good with VB6. I can't get much outta VisualBasic.NET. 2003 And I seldom seem to be able to get any useful help from help or by searching the web... It's very hard to explain, but it seems you have to know what you're doing to make any sense of the "help"... in which case you wouldn't need any help.

    I will follow up on your suggestions ... again thank you.
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-01-29 10:59
    Realoman ..

    I'd be inclined to steer clear of .net 2003 - lots of issues too many to list here .. use .net 2005 at least - 2008 recommended .. If you need specific help - drop me a PM .... Once you get going with .net you will soon realise the limitations of the VS6 (visual studio 6) and earlier offerings.

    That said I still use PowerBasic for Dos - to implement changes to DOS based machines I built years ago.... native support for multiple Com ports. Beats the pants off QB. They also have a Power Basic for windows offering - which I also use occasionally..
    www.powerbasic.com/

    and of course there is LibertyBasic ... really simple QB style programming for windows ...
    www.libertybasic.com/

    Rgds,
    John Twomey

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    Those who can, do.Those who can’t, teach.
  • Cats92Cats92 Posts: 149
    edited 2009-01-29 11:07
    Hello,
    I have used VB and C# for communications with a Propeller .
    C# is much better.
    With something like:

    using System.IO;
    using System.IO.Ports;

    SerialPort COMPort = new System.IO.Ports.SerialPort("COM12", 9600);
    string message ;
    message= "K0874"

    COMPort.Open();
    COMPort.Write(message);
    COMPort.Close();
    You can send a command to the bot.

    Cats92
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-01-29 11:19
    also have a look at
    http://forums.parallax.com/showthread.php?p=727719

    Chris savage has included his source code for his RFID reader ... serialport example there ..

    Just a quick bit of advice when updating a control with received data - you will have to 'invoke a delegate' .

    Rgds,
    John

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    Those who can, do.Those who can’t, teach.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-01-29 20:00
    Hi realolman, I have used several different Basic software programs and several different versions of Microsofts VB and I find Visual Studio VB 2008 the best and most versatile in a Windows OS. I am not saying Visual Studio VB is better than the others just that I personally have not been able to get the others to perform as well.

    The project may seem overwhelming at first but can be broken down into easily managed sections. As you build each piece you should make provision for testing your ideas with small code snippets for the Propellor and your VB app.

    The obvious starting place is to first be able to open serial communications and the link that John mentioned ( http://forums.parallax.com/showthread.php?p=671804·) contains the Stamp to VB Express template. The template will work for the Prop just as well as the BS2 and I recommend that as your starting place, the template is mainly for·quick start·purposes and is a little rough around the edges. I have something more complete that I will post if you decide to go this route.

    Next you will have to give thought on what type of communications you need, there are three options·send only , receive only or send and receive each one has a different degree of complexity. I think you will find that the SerialPort control of Visual Basic easy to use , for transmitting and receiving the members Write and Read should satisfy everything you want with·the Propeller , either ASCII characters and strings·, sequences of single byte values·or a combination of both with only those two instructions.

    Your GUI can gain in complexity if it is graphically animated or involves additional background data processing so it possibly pays to keep it simple but interesting.

    Jeff T.
  • realolmanrealolman Posts: 65
    edited 2009-01-29 21:09
    By following the links provided, I have found something simple enough that even I can understand it.
    I hope to be able to build on that.
    Maybe as it goes I will come back and follow some of the other links and suggestions.

    I appreciate all your help.

    You are really something... thanks

    smile.gif
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-02-02 19:48
    Hi realoman, by now I would think you are making substantial progress. I have a tool for use with the Propeller , it's one I use with the BS2 with some minor modifications. The small application allows you to transmit ASCII characters , ASCII·strings , byte values or a combination of them all. If you do combine ASCII and single byte values the string is always sent first. String length is unlimited and byte values are limited to a maximum of 9. There is a received data panel that can be toggled between ASCII characters and byte values. The app is designed with Parallax processors in mind and as such is cinch to set up.

    This is a great help in testing Spin code and is good to 115200 baud. I am attaching the program with a sample Spin file. The Spin file uses Extended FDSerial.spin and a method that accepts an adjustable·predefined array of byte values preceded by the header "!VB" ·(which can of course be removed).

    This may not be the route you are headed at the moment but I feel that if you have a program that will operate comfortably with values between 0-255 then the method (RXArray) in the Spin file will work nicely. The method works fine for me but any comments on it's faults are welcome as I am a novice with spin.

    Jeff T.
    625 x 526 - 39K
  • C.RayC.Ray Posts: 6
    edited 2009-03-01 18:17
    Hello all,

    I have used the Visual Basic 2005 to BS2 template provided by Unsoundcode and I am happy to say that it works very well. Thanks Jeff T.

    I want to use it as a building block for more complex applications. I am trying to get the BS2 to send four different text strings (digits actually) to be displayed in four separate RichTextBox(es) in Visual Basic 2005 Express and since I am a beginner with Visual Basic 2005 Express I am not able to do this on my own and I am hoping somebody here can help me with this or point me in the right direction.

    Perhaps I am not in the proper forum for this but I am here because this is the last place that I found it mentioned when I searched for Unsoundcode's template.

    I am able to simulate what I want to do by using a new button with a new "RichTextBox1.Text = SerialPort1.ReadExisting()" statement, changing the "RichTextBox1.Text" to " RichTextBox2.Text" and so on for each new RichTextBox and new button combination. With this setup, I have to push the new button to have the serial port info display in that particular RichTextBox.

    I would like to make this an automatic process, that is, when the BS2 is ready to send, it signals the VB program on its own and then sends the four strings to their respective RichTextBoxes without the buttons. I am able to handle most of the BS2 code (maybe) but I do not know how to make the VB code do this.

    Any help would be appreciated.

    Thank you.

    Carl
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-03-01 23:39
    Hi Carl, the forum you need to be in for questions on the BS2 is the Basi Stamp forum ,·there is a thread in that forum you might find helpful if you haven't come across it yet at this link http://forums.parallax.com/showthread.php?p=671804.

    Read through it and if you have any questions regarding BS2 to VB post them in that thread.

    The VB2Prop application was spawned from an app that works better with the BS2 through its programming port, read through the above link and I can give you more detail on that later.

    Jeff T.
  • C.RayC.Ray Posts: 6
    edited 2009-03-02 04:40
    Thanks for the response Jeff.

    I have read through the other thread which is where I found your template code. I did not try the Twin Servo Control program or the Simple Debug App yet. I will get right to those see if that will help me.

    Thanks again.

    Carl
Sign In or Register to comment.