VB to BS2
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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
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.
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
www.theabramgroup.com/basicstamp/
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
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.
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
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Basic Stamp,···· Propeller,·· · SX,·· FUN!
START:·
>Proccessing Data. . . .··
>Task Complete. . .·.
>Saving Data. . . .
>Entering SLEEP Mode. . . .
>Signing OFF
·
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/
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Basic Stamp,···· Propeller,·· · SX,·· FUN!
START:·
>Proccessing Data. . . .··
>Task Complete. . .·.
>Saving Data. . . .
>Entering SLEEP Mode. . . .
>Signing OFF
·
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
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.
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
Jeff T.
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
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
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
·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.
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/
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
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.
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:
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
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
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:
BTW: Is the two "End Sub" at the end a type?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
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
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
Best of luck on your project. If you have any programming questions then please feel free to let me know.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James Dougherty
Ariel Productions
http://www.arielproductions.com/
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