One click - two data transmission from VB to Basic Stamp 2
R0y4L
Posts: 23
Hi everyone
So, I have finally managed my VB application to send data to BS 2. It's all working and fine. The VB app suppose to send two digits through serial port to BS 2, and the BS 2 suppose to insert those digits into different memory location in the EEPROM. I am trying to achieve all of this with one button click, however I have been unsuccessfull, so I thought to ask for some help. How can I make my "thing" to send two pieces of data with one click?
This is my VB code. As you can see I have no SerialPort connection on this form, but don't worry it is linked to a form that has SerialPort connection and its working fine.
This is my PBASIC code:
I have added the FREQOUT statement so, I know if the second SERIN worked.
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit: www.vbnoobs.co.uk
So, I have finally managed my VB application to send data to BS 2. It's all working and fine. The VB app suppose to send two digits through serial port to BS 2, and the BS 2 suppose to insert those digits into different memory location in the EEPROM. I am trying to achieve all of this with one button click, however I have been unsuccessfull, so I thought to ask for some help. How can I make my "thing" to send two pieces of data with one click?
This is my VB code. As you can see I have no SerialPort connection on this form, but don't worry it is linked to a form that has SerialPort connection and its working fine.
Private Sub cmdSet_Clock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSetClock.Click If txtClockHours.Text = "" Or txtClockMinutes.Text = "" Then MsgBox("Please check time entered!", MsgBoxStyle.OkOnly, "Clock Time") txtClockHours.Select() Else Dim hours As Byte = txtClockHours.Text frmMainGUI.SerialPort1.WriteLine(hours) Dim mins As Byte = txtClockMinutes.Text frmMainGUI.SerialPort1.WriteLine(mins) lblClock_Status.Text = "Clock Has Been Successfully Updated" End If End Sub
This is my PBASIC code:
mins VAR Byte hours VAR Byte speaker CON 9 start: SERIN 16, 16468,[noparse][[/noparse]DEC hours] WRITE 101, hours SERIN 16, 16468, [noparse][[/noparse]DEC mins] WRITE 100, mins FREQOUT speaker, 100,2000 GOSUB start
I have added the FREQOUT statement so, I know if the second SERIN worked.
Thanks
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit: www.vbnoobs.co.uk
Comments
When you say you were unsuccessful, what does that mean? No data in 100 or 101? Incorrect data in 100 or 101?
DJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Instead of:
"Those who can, do.· Those who can't, teach." (Shaw)
I prefer:
"Those who know, do.· Those who understand, teach." (Aristotle)
·
Your question is a little confusing.... are you saying that SERIN 16, 16468,[noparse][[/noparse]DEC hours] picks up hours, but SERIN 16, 16468, [noparse][[/noparse]DEC mins] does not receive the mins? If so, it could be that you need to throttle the data that you are sending from the PC. In other words pause for a little bit from the PC side. Remember that the BS2 does not have a serial receive buffer and can only receive data as it is available.
Hard to tell without more of your code, but that's my guess.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
davejames:
When I say unsuccessful, I mean no data in the 100. Basically if I press a button on my VB app value for hours is sent to the BS, but no mins value.If I press the same button again, the mins value does get sent.
Beau:
Yes, you are correct: hours does get picked up but not the mins. I will try to work out how I could pause in VB. What do you mean by "serial receive buffer"?
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit: www.vbnoobs.co.uk
VB
Stamp (partial code)
Note a baud of 4800
Although the Stamp will accept upto 3 characters for each value the "Writeline" of VB will terminate the string at 1 , 2 or 3 characters , whatever you send
Jeff T.
EDIT I decided to make a small change , should work ok.
Investigate the VB Sleep() command. I use it in between serial port operations to the Stamp.
I've recently found that serial communication, VB to/from Stamp, is not a trivial thing...
DJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Instead of:
"Those who can, do.· Those who can't, teach." (Shaw)
I prefer:
"Those who know, do.· Those who understand, teach." (Aristotle)
·
(smiles)
DJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Instead of:
"Those who can, do.· Those who can't, teach." (Shaw)
I prefer:
"Those who know, do.· Those who understand, teach." (Aristotle)
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit: www.vbnoobs.co.uk
I would even say that this particular qualifier is the often-stated as missing “serial buffer” of Stamp.
On ather subject – mixing variable definitions (your Dim statements in your VB code) with code flow is not very good practice. Unfortunately VB is too forgiving.
Keep coding Vaclav
SERIN 16, 16468,[noparse][[/noparse]DEC hours, DEC mins]
that should work better. What was happening is the delay while the BS2 wrote to the eeprom (which DOES take a while, like a millisecond or so) it would miss the beginning of the 'mins' serial stream. The BS2 can't recieve serial unless it's waiting in a SERIN command.
This does assume you 'terminate' the 'hours' value with a '\n' (vbCrLF).· Which I assume the "WriteLine" does.
The idea of using a header such as the exclamation to synch up the data is always a good idea·. It prevents a situation where the SERIN misses the first byte and loads the minutes value into the hour variable , SERIN would just sit there then waiting for the next byte which would be the hour value at the next button click , that value would get loaded into the minute variable
Thats why sometimes you might see the correct values in the wrong slot.
Jeff T.
You got me interested with the STR bit. Any tips where i could find more info about it or how i could implemented in my code that i have provided above. I have Basic Stamp book, but i could not find any reference to STR.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit: www.vbnoobs.co.uk
The "character string" term ·is litlle· missleading. It should say "bytes into byte array".
One click and I can set the time, and date on a DS 1340
VB code:
and some corresponding basic stamp code
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike2545
This message sent to you on 100% recycled electrons.
Post Edited (Mike2545) : 9/16/2009 10:18:11 PM GMT