Serial comms with visual basic
realolman
Posts: 65
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
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
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
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
Have you seen what they're charging for DELPHI now!
You'll need a student discount and $150.
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
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.
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.
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.
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.
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.
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
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.
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.
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
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.
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
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.
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