Writing Visual Basic 2008 programs that interact with a Propeller
I have been reading through a book on writing Visual Basic programs and was wondering if anyone else had any experiance with writing Visual Basic 2008 programs that interact with a propeller for gathering data, sending data, loading in a SPIN program, etc. Any comments or advice on how to do it allong with a sample program would be nice.
Thanks,
Micro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
SX Spinning light display·
http://designedbymemicros.blogspot.com/
Thanks,
Micro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
SX Spinning light display·
http://designedbymemicros.blogspot.com/
Comments
I created a control program in VB.Net 2008 that gave the user an easy to use front end. I used the build in SerialPort object in VB. It was a pretty simple project and is running as we speak to do unit testing (test power failures) for a larger application I wrote.
It recently ran for 3 weeks interrupting the power to various machines and testing the robustness of the main application software.
One of the things with using the serial Port object in VB is you need to have basic understanding of multi-threading to support the characters coming back from the port. It's not too hard.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim Fouch
FOUCH SOFTWARE
Edit: Rest of post canceled due to lack of interest.
Post Edited (jazzed) : 2/7/2010 8:20:51 PM GMT
I work mostly in VB6 because I have a lot of personal legacy code, much of it coded straight to the API so it doesn't play well with vb.net. I have tools for going to serial ports and TCP/IP without using plugins, which means that my .exe's have only the vbrun600 dll dependency, and that's been present on every PC I've taken delivery of since 2002. That means you can just copy the .exe into a folder and run it, without running an installer. Makes backing up and restoring a hell of a lot simpler.
Your main comm channel will be serial, either through a real serial port or the FTDI usb converters. The trick is to remember all external comms are unreliable and remember to deal gracefully with missing or garbled data. This means making sure your receive buffers don't overrun if you don't get the terminating character you expect and re-trying comms that are timing out. Generally you need to decide that one device, either the PC or the Prop, will drive comms and let it do timeouts and retransmit requests; the other device will be quiet if it's never queried. There are a million ways of doing this with different strengths depending on what kind of data you are sharing; recording the occasional weighment is a lot different from streaming audio.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
SX Spinning light display·
http://designedbymemicros.blogspot.com/
It's everything you need and more.
That said, I think the C# examples make a lot more sense: http://www.ftdichip.com/Projects/CodeExamples/CSharp.htm
The FTDI .NET wrapper is excellent.
FTDI - D2XX Programmer's Guide 1.02 Lists functions available in FTD2XX.DLL
www.ftdichip.com/Documents/ProgramGuides/D2XX_Programmer%27s_Guide%28FT_000071%29.pdf
If you feel really keen you can join the N8VEM group and get access to a more complete program I wrote that has a VT100 terminal, xmodem file transfers.
Start simple though. A few buttons and text boxes, make a loopback cable by joining pins 2 to 3 on a D9 and see if you can send a byte and then read it back again.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Here is a basic program that I have used as a template to talk to the propeller.
http://www.serialporttool.com/NCD/R8X_VB2008.htm
Brian
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"Imagination is more important than knowledge..." Albert Einstein
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
SX Spinning light display·
http://designedbymemicros.blogspot.com/
in 1980, Microsoft BASIC would be the first thing you would see when
you turn on virtually any brand of computer.
In 1990, You had to Boot a disk, then type GWBASIC or QBASIC or just BASIC.
Now, after reading this thread, I apparently missed what you do to get to Visual BASIC or VB.NET
on a PC, which must be black magic, because it is the topic of the thread, and I have not now nor ever
seen the answer, yet someone is satisfied at having received it!
http://VB.NET --- what IS this? --- Seriously!!!
My friend's BSoD'd computer is back, fresh and like new.
Here I have a lot of BASIC computers. Given 5 minutes, I may be able to turn them ALL on,
and type in and RUN a HELLO WORLD program on almost all of them.
I challenge ask anyone to please tell me how to do that on this one freshly fixed PC. (Oops).
15 Minutes, to turn on that PC and write and RUN a BASIC program to send HELLO WORLD to a Propeller!
I am now daydreaming of doing a video documentary about this teeny tiny task,
which has been invisibly answered here, and which I have not groked for the past decade!
Within my arms reach, I have a laptop with 1983 Microsoft BASIC that can be turned on and programmed
to send HELLO WORLD to a Propeller to be displayed on its monitor in 15 Seconds.
After almost 2 or 3 decades,
Why can't I, nor any of my friends, ever figure out how to program Windows PCs?
So, how do you program Visual BASIC... to use the Propeller... or do anything?
How long will it take? 15 seconds, minutes, hours, days, months, years?
Finally ... a thread with an answer! ...but... Where?
Please reply with the nice quick HELLO WORLD demo code in a nice one-line code block,
and what to click on get READY to type it in!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I should be typing in Spin now.
Coming soon. My open Propeller Project Pages and favorite links index.
Post Edited (VIRAND) : 2/10/2010 9:59:24 AM GMT
And if you are going to go to all that bother, why not install c dot net and java dot net as well?
Anyway, I digress. The picaxe example shows how to send a couple of bytes out of a serial port and get a few bytes back. At the propeller end, you are going to need a max232 and a serial port object and some glue code and then it won't work so you need some way of debugging it, but you can't debug using the serial port because you are already using that, so you need a different way of debugging it, so why not add a vga screen and then you may as well add a keyboard, and heck, you probably need an sd card and an operating system...
Sersiouly, it does take a lot of work to make it all come together easily. And I haven't mentioned a more complete IDE environment I've written in vb.net which has a VT100 terminal and can do xmodem file transfers to the propeller but best to do this with baby steps first.
But when it is all working it is very quick and simple. I can fire up a vb.net program on a PC in about 20 seconds, and a propeller dracblade board, and have basic running on that propeller board within a few seconds. Or do that without even needing the PC.
Re "I have a laptop with 1983 Microsoft BASIC that can be turned on and programmed
to send HELLO WORLD to a Propeller to be displayed on its monitor in 15 Seconds."
I just timed that on the propeller dracblade. 23 seconds from bootup to running basic to printing "Hello world". I'm impressed with 15 secs - you must be a fast typist!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
I think my 15 second code would look something like:
(Power on)
READY
10 OPEN COM:9600,8,N,1 FOR OUTPUT AS #1:PRINT #1,"Hello World"
RUN
(done, after preloading a propeller terminal into Propeller)
I'm wasting time, and off topic. OK. So there's 80 megs of stuff to download for Visual Basic.
It sounds like lifetimes wasted on Millions of lines of code, needing lifetimes more to make it work,
before it expires like a carton of milk, and gets replaced by a much bigger one.
Post Edited (VIRAND) : 2/10/2010 11:29:38 AM GMT
"dot net" is a framework not a url. It allows you to write code in a variety of programming languages that will all work the same within the .net frame work. The programmer downloads the IDE (that is the 80mb part) and writes a program. The user runs the program only he must have the .net framework installed on his machine. It is a little like having the java runtime engine running on your machine in order to run java stuff.
Remember that VB lets you create software with GUIs as well as console type apps, that is why it is big, you are downloading an IDE and an interface designer etc. XP is not based on MsDOS so no qbasic though I read you can get it off an Windows Me CD and run it in emulation mode.
It is hard to say if you are actually interested to know the details (you could have just used wikipedia) or if you just want to complain about microsoft and the way things are going. I would not disagree with you really, in my job I was forced into having to write some visual C++ code with MFC, I really hated it, then I looked at the .net framework and decided I wanted out of it all. I'm currently (while I sit here) learning Python and QT and perhaps when I get around to it I will bow out of windows too.
Oh if you have excel it is possible to develop VB code inside it.
Graham
To me .net is a fusion of C#, C++, Basic, and Java and it seems to be heading in a direction that is good for all the languages. It might even end up being a solution to the "my language is better than yours" arguments that have been going for so many decades. Certainly as a Basic Programmer I'm using more and more C (which you can do in vb.net), and there are even code fragments for vb.net and C#.net that end up almost the same.
as for the propeller, my 23 second code is:
A>MBASIC BASIC-80 Rev. 5.21 [noparse][[/noparse]CP/M Version] Copyright 1977-1981 (C) by Microsoft Created: 28-Jul-81 32824 Bytes free Ok 10 PRINT "Hello World" RUN Hello World Ok
And I could cheat and compile that and turn it into HELLO.COM and then put HELLO.COM as a single line in a file called AUTOEXEC.SUB and then reboot and I wouldn't have to type anything and it would be only 12 seconds. (But of course, you could write a Spin program and do it in 2 seconds!)
Maybe vb.net isn't the smallest but it was the program our OP wanted, and it happens to be the program I've used to write practice management software for medical practices, and if you total up the money that has gone through the free installations of that program over the last few years it comes to several million dollars (I gave it away to my local community hospital for free) It may not be the fastest and it certainly is not the smallest to install, but, like spin, it has a vast library of free code and objects already written eg www.planet-source-code.com/ So a lot of coding ends up 'cut and paste'.
So, for Microcontrolled, I'd be more than happy to take you through the steps from outputting a single byte to getting a fully fledged program working that can talk in an interactive way with a propeller. I'm actually coding something similar at the moment with bytes starting off in vb.net and going to a propeller and then being routed wirelessly between other propellers.
As for some real vb.net code
Imports System.IO Public Class frmMain Dim WithEvents SerialPort As New IO.Ports.SerialPort ' serial port declare Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort.ReadTimeout = 100 SerialPort.PortName = "COM1" SerialPort.BaudRate = "38400" ' 38400 SerialPort.Parity = IO.Ports.Parity.None ' no parity SerialPort.DataBits = 8 ' 8 bits SerialPort.StopBits = IO.Ports.StopBits.One ' one stop bit SerialPort.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response SerialPort.Open() ' open the port SerialPort.DiscardInBuffer() ' clear the input buffer SerialPort.Write("Hello World") SerialPort.Close() End Sub
and you would find it a lot easier to draw a simple form on the screen with a button and run this when you push the button, though this code runs automatically when the main form1 is loaded.
There are better ways to do this, eg outputting bytes one at a time from a byte array rather than from strings as vb.net won't send out raw bytes from 128 to 255, but this is a simple demo that prints something to a com port. If that works we can move on to reading some bytes back.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Post Edited (Dr_Acula) : 2/10/2010 12:34:20 PM GMT
From this complex stuff
10 PRINT "Hello World" RUN
To something simple like this
Imports System.IO Public Class frmMain Dim WithEvents SerialPort As New IO.Ports.SerialPort ' serial port declare Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SerialPort.ReadTimeout = 100 SerialPort.PortName = "COM1" SerialPort.BaudRate = "38400" ' 38400 SerialPort.Parity = IO.Ports.Parity.None ' no parity SerialPort.DataBits = 8 ' 8 bits SerialPort.StopBits = IO.Ports.StopBits.One ' one stop bit SerialPort.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response SerialPort.Open() ' open the port SerialPort.DiscardInBuffer() ' clear the input buffer SerialPort.Write("Hello World") SerialPort.Close() End Sub
LOL
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
Program Hello_World; Var Serial : Text; Begin Assign(Serial,'/dev/ttyUSB0'); Rewrite(Serial); Writeln(Serial,'Hello world'); Close(Serial); End.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
I am not the world's biggest fan of .NET, but there are many elements of·current Windows OS that would simply be impossible to address with the older versions of basic.
So the download is 80 megs... are you on a diet?· You've never downloaded or installed a large program before?· Hey - at least it's free.
If all you desire is the ability to produce a simple serial port code, nothing is preventing you from either setting up a·machine dedicated for that purpose.· Or set up a VM.·· You can get QuickBasic here: http://www.qbcafe.net/qbc/english/download/compiler/qbasic_compiler.shtml
·LOL... true.·· But on the other side of the coin, you didn't have event driven code that could fire on a serial port pin change without constant polling.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You've but only try.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
SerialPort.PortName = "COM1" SerialPort.BaudRate = "38400" ' 38400 SerialPort.Open() ' open the port SerialPort.Write("Hello World") SerialPort.Close()
And if you chose to call an object in spin "SerialPort" and you chose to call the subroutines "Baudrate" and "Write" etc then I think the above might end up almost identical to Spin??
I paid hard earned dollars for VB5 and then VB6, so I was pretty pleased when Microsoft decided to give away VB.NET.
The above is a start. Then you can start wrapping "Hello World" in a packet - add a checksum at the end, put a few bytes on the front as a header so you can tell which board it is meant to go to. Maybe add an acknowledge byte and if that byte doesn't come back in a specified time then it flags a 'not communicating' error.
Then there are the cool 'hidden' things vb.net can do - eg as mentioned above by agent420, , have event driven code. Or you can use .doevents where you tell windows to go off and do other things - this means the code doesn't slow down the rest of windows. I use that command liberally in my code, eg when reading in big text files which tends to tie up windows. Also for real world programming, rather than start with code, generally you start with a blank form, put some buttons and text boxes on the form, make it look good, and then start double clicking on the buttons which opens up the code view with the subroutine already pre-written. Then just add the code for the button.
If you are a C programmer you could use the variants of C.NET on the PC side and Catalina on the Propeller and it would make the interface a lot easier as it wouldn't involve switching languages as you debug it.
With Propbasic, maybe the same thing could be done with vb.net and propbasic.
This makes me start thinking about a PC language called Spin.net
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Post Edited (Dr_Acula) : 2/10/2010 10:40:40 PM GMT
Is anything possible with 80MB of mystery and magic that is not possible with 80KB of ASM?
Where's the "Progress"? All I know is that all the awesome stuff stopped working or slowed down shortly after Win95.
Whenever something new comes out for PC, it is always something old from before Y2K.
Like internetphone which was better than Skype in the 1990s.
Scanimate and Lundy had nearly realtime animation in the 1970s and 1980s, so what's wrong with PIXAR?
You need to maintain escape velocity or you can't to space anymore in the future.
Propeller is faster than Windows, unless you can write a VGA driver that needs no video chips in VB dot NET.
At beyond 2GHz clock, what's the problem? I asked the same thing when PCs clocked at 133MHz.
Sinclair ZX80 and ZX81 did it with a Z-80 and glue logic, as did I better with the 8051.
The problem is Bill Gates and I are both getting too old and fat to win any races.
Only the Propeller is fast enough to run my retro-futuristic software before all my original hardware dies.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I should be typing in Spin now.
Coming soon. My open Propeller Project Pages and favorite links index.
Post Edited (VIRAND) : 2/11/2010 10:11:15 AM GMT
I agree with all those statements. I might even add some more, eg
Why does a PC need a 500W power supply to write a letter?
Why can't my son copy files from one drive to another with Vista? (he needs "administrator privileges. Which he has)
Why is my PC now taking over 3 minutes to turn on?
And why, oh irony of ironies, does VB.NET decide to die on the one day I am trying to post to this forum a message saying how good it is??!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
We actually have some legacy apps running at our shop that were coded in QB7...· It is quite the change of mindset when I occasionally have to step through the code to rememebr why something isn't working (typically user input that buggers it up).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
With the prop project now. It has served me well. I make exe files with
VB5 and they are transportable to my customer. I was under the impression
That the (free) .net would not allow you to make exe…?
Bill
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
@VIRAND: PLEASE don't turn this into an opportunity to bash Windows. Yes, Vista is trash. Slow, it freezes, and I need to enter a password just to copy or move a file. But I was never around in the good ol' days of simple computers, and every computer I have ever used has taken at least 2 or 3 minutes to start up, so I don't know any better.
If I want to make something, I should make it so that almost anyone can use it. This is why I am writing in VB.NET. If someone can point me to an OS that isn't too hard to use and boots in a few seconds then I will use it. HOWEVER, I don't want one of VIRANDs infamous Window's woes that he invades so many threads with. If he can offer good advice then good, but unless you are saying something that has to do with the subject on hand then please do not use this thread to complain. There is nothing anyone can do about it, so what is the point?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.
Robots are microcontrolled.
I am microcontrolled.
SX Spinning light display·
http://designedbymemicros.blogspot.com/
>I was under the impression
>That the (free) .net would not allow you to make exe…?
Yes, good news, it can. Maybe the marketing people need to work on explaining it better. It doesn't make a .EXE as such, but rather creates a file called SETUP.EXE and there is an associated folder that goes with that. The end user needs to run SETUP and if .DLL files need to be installed it does all that automatically. On reinstalls, SETUP.EXE takes about 2 seconds to reinstall an update. I tend to bundle up the package as a .ZIP, though vb.net gives you a number of options, including publishing to a hard drive location or to the internet.
@microcontrolleed, have you got a form yet and have you got buttons and text boxes, and are you at the stage of clicking a button and changing text in a text box?
If so, try adding a timer. Set the delay to 1 second, put some code in the timer box and get it to print something different in a text box every second. If you are stuck with that then let me know.
There are lots of ways to get input from a serial port and you can set it up to run code when bytes arrive.
I've gone for one solution where a timer checks the serial port periodically
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' collect bytes from the serial port Timer1.Enabled = False Static TimerCounter As Integer If SerialPortFound = True Then Call ReadSerialPort() EndIf Timer1.Enabled = True End Sub
I turn the timer off while it is doing things in case it takes to long and starts recursively calling itself.
I read the bytes into an array rather than a string, so define an array at the beginning so it is common
Public Class frmMain Dim InPacket(0 To 2000) As Byte ' strings like chr(255) won't go out so define as an array
then read any bytes
Sub ReadSerialPort() Dim BytesToRead As Integer ' may as well get in batches If SerialPortFound = True Then ' in case no port exists Do If SerialPort.BytesToRead = 0 Then Exit Do ' no more bytes BytesToRead = SerialPort.BytesToRead If BytesToRead > 2000 Then BytesToRead = 2000 SerialPort.Read(InPacket, 0, BytesToRead) ' read in a packet Loop End Sub
Any bugs let me know as I'm copying this from bigger code and deleting some bits.
Oh yes, sorry, define
Public SerialPortFound As Boolean = True
in the common at the top as well.
and give the user an error message if there is no serial port - put this code at the beginning when the main form loads
Try ' set the portname and baudrate in the loadini subroutine SerialPort.PortName = "COM1" SerialPort.BaudRate = "38400" ' 38400 SerialPort.Parity = IO.Ports.Parity.None ' no parity SerialPort.DataBits = 8 ' 8 bits SerialPort.StopBits = IO.Ports.StopBits.One ' one stop bit SerialPort.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response SerialPort.Open() ' open the port SerialPort.DiscardInBuffer() ' clear the input buffer Catch ex As Exception MsgBox("Error opening serial port - is another program using the selected COM port?") SerialPortFound = False End Try
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Post Edited (Dr_Acula) : 2/12/2010 2:47:04 AM GMT