VB.net to Prop communication
Shawna
Posts: 508
Does anyone have any good links for VB.net tutorials? I want to write a quick debugging program to receive data from a Prop. I am using PST right now and I would like to arrange the data into a little more user friendly format for viewing. I am working on a quadcopter control board and the PST is not getting it done. I took 2 semesters of VB6 back in school but I am pretty rusty I found. Is there an easier language to play with? I found a tutorial on you tube for serial com ports that I followed and it works, but I am not sure how to break up the received data on the vb.net side. I need to start with the basics I think. VB for dummies maybe in my future, ha ha. I wouldn't mind playing with C a little since that can be used to program all kinds of micro controllers. Is C easier to learn than VB?
Thanks
Shawn
Thanks
Shawn
Comments
Shawn
DrAcula probably has done this. VB6 would be much easier for you I think and it has been done here somewhere. If not, I can dig out a VB6 program that uses the serial port from my backups.
Please don't start the C vs VB debate
What sort of data, and what does 'arrange' mean ?
Depending on exactly what that statement means, you could look along the lines of the basics that come with Open Office Spreadsheets etc.
A quick google gives this
[Solved] Macro to read serial port and write to OOo Calc
http://forum.openoffice.org/en/forum/viewtopic.php?t=30999
Another pathway, for long-graph multi-line style Data is to stream into a formatted .RAW file, which is the format used by LTSpice et al.
Then you load that file, using LTSpice as the Graphical viewer.
Thanks
Shawn
I could also help to integrate the Propellent Dll into your application which you might find to be useful.
Jeff T.
What is the Propellent Dll?
Shawn
Shawn
Yes it sure is whether your using C# or Vb .Net. This link has the Dll and documentation regarding the Propellent Library http://www.parallax.com/tabid/832/Default.aspx
If you are using the Proptool then you already have the DLL
Jeff T.
Read down to the very end of this and find PST.PX() and PST.PY()
A screen for 20 variables shouldn't be a problem.
Richard
PST.Methods:
The following are some of the more useful methods found in the Propeller Serial Terminal File (PST for short?)
[h=2]START[/h]The start method will be found in most objects as it is used to launch the object in a different cog. It is also used to pass I/O or configuration.
PST.start(9600) ‘ start serial terminal at 9600 baud
PST.start(12)
PST.start(my_variable,my_variable2)
[h=2]STOP[/h]The stop method stops the object and frees the cog.
[h=2] [/h][h=2]INIT[/h]The init method sets up variables for objects that don’t use their own cog. It is used instead of start in those instances.
(Some objects may require a call to init before calling start. Any necessary set-up calls will be clearly described in the object’s source file).
[h=2]STR [/h][h=2]The str method displays text or the contents of a variable or array.[/h]PST.str(string(“Display a line of text”))
PST.str(string(“Display a line of text with a carriage return”,13))
PST.str(my_multibyte_variable)
PST.str(@my_variable_array)
PST.str(@my_variable_array[X])
[h=2]
DEC [/h][h=2]The dec method display variables as a decimal numbers.[/h]PST.dec(my_variable)
[h=2]
HEX [/h][h=2]The hex method displays a variable in hexadecimal. [/h]The second item (2 in this example) tells how many places to display.
PST.hex(my_variable,2)
[h=2]
BIN [/h]The bin method displays a variable in binary.
The second item is the number of digits to
PST.bin ( some_variable, 8 )
[h=2]OUT (or TX)[/h]The PST.out (sometimes called .tx) method will be found in various display and communication objects to handle serial communications.
For video drivers out( ) should interpret the variable instead of displaying the character itself. For example: out ( $08 ) would cause a backspace, instead of displaying the box corner character.
[h=2]NEWLINE[/h]The PST.newline method sends a carriage return.
Same function as pst.out ( 13 ) or out ( $0D ).
As you can see there are a lot of useful methods in the Serial Terminal program. And, as your programs become more involved you will find this tool to be a life saver.
For control of the screen layout ASCII control codes can be defined and used with the Parallax Serial Terminal.
Define these in the CON section
HM = 1 'HM: HoMe cursor
PC = 2 'PC: Position Cursor in x,y
ML = 3 'ML: Move cursor Left
MR = 4 'MR: Move cursor Right
MU = 5 'MU: Move cursor Up
MD = 6 'MD: Move cursor Down
BP = 7 'BP: BeeP speaker
BS = 8 'BS: BackSpace
TB = 9 'TB: TaB
LF = 10 'LF: Line Feed
CE = 11 'CE: Clear to End of line
CB = 12 'CB: Clear lines Below
NL = 13 'NL: New Line
PX = 14 'PX: Position cursor in X
PY = 15 'PY: Position cursor in Y
CS = 16 'CS: Clear Screen
To use, simply add a line to your code like…
PST.CS clear the screen
PST.NL move to the next line
PST.PX(10) move the cursor to column 10
PST.PY(10) move the cursor to line 10
PST.TB move cursor to the next tab stop
Click the "Prefs..." button in Parallax Serial Terminal and then click the "Function" tab in the Preferences dialog box, you can view/select the ASCII control characters it recognizes.
I am still struggling with this guys and I thank you all for your input so far. I am way off on a tangent here, and off coarse from my original project which is the quadcopter. But everything is a learning process so I am going to continue on this vb.net thing. I have written a basic spin program to send 2 longs out the serial port any time an "a" is received on the Props Serial Port. This works well enough for now. Here is the code, it is very simple.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
MHZ = 80
obj
PST : "Parallax Serial Terminal"
var
long IN
PUB Debug
PST.Start(115_200)
repeat
IN:=PST.CharIn
If In == "a"
PST.Bin(1,32)
PST.NewLine
PST.Bin(2,32)
Now, I realize that this is not a VB forum but you guys are very helpful. This is the code I have for VB and it works but it throws everything into 1 rich text box and for the life of me I can not figure out how to separate the data.
I can't even figure out how to manipulate this code to display it as integer instead of a string. I do not understand delegates and it seems like I have to do that in order to read the serial input buffer. I even added a button so that when it is pressed vb sends an "a" to the prop which tells the prop to send its data, and it works. How ever it still just dumps it into a rich text box. The rich text box is all I have on the form, but I tried to dump the receive buffer into a array and from there I was going to add more text boxes. I failed at the array and I am stuck. I posted a question on one of the VB forums and my lack of terminology and knowledge of VB sank me. I have attached my VB file if anyone is board and would be willing to look at it.
Thanks Shawn
Serial Com1 Test1 VB.zip
1) at the beginning
2) In the main form declare the serial port and also a couple of global arrays and also the sleep statement and a few global parameters for the serial port. (You can declare some of these in the object on the screen or in code)
3) When the form first loads, set some of these values
4) A useful routine to reset the propeller if you happen to be using the same port for downloading
Add a timer, and the code from the form1 load will set it to check for port updates every n milliseconds (I set it at 150 milliseconds) and then call this routine to collect any bytes. This is for a simple terminal program - I think you have something similar already working adding things to a richtext box. Further down we can input the data into the array and feed it into other things such as a string, or convert it to data. (try typing "strings." and you can see all the things the strings class can do, like convert strings to numbers and vice versa)
This is an example of reading in some bytes. Borrowed from the catalina driver. Discard the bits you don't need. This "runs" a program on the propeller and so it is useful to see this happening. I've left in bits you won't need as it shows a method of collecting text that may not arrive in the time you expect it to, and moving that text from the input buffer into a string and then into a label on the screen. I think these are some of the processes you are looking to use. There are little tricks like "doevents" that force an update of the label as sometimes the data is actually in a textbox or a label but it isn't being refreshed.
Sometimes you might want to clear the input buffer
Routine to test a port is actually available
Routine to display ports you actually have
Warts and all, this is a routine to send a file to a propeller chip running Kyedos (a simple operating system). It uses the xmodem protocol and illustrates all the error checking and timing hacks needed to get reliable data comms. Maybe there are some bits of code you can use for other things?
and this is the routine to receive a file
That is a lot of info Dr_ Acula, that will take some time to process.
Thank You
Shawn
Note the baud rate is 38400 and the serial Object is Extended_FDSerial although you can change that to your preference.
VB code