how to receive decimal value from VB
Archiver
Posts: 46,084
Hello All...
I have created this nifty little home automation switcher using the
BS2 and some MAX395 IC's, but I need to interface with it from the PC
and I'm using VB6 to create the app. I've tried every suggestion I
could find from the forum, but can't get VB6 to send a simple decimal
value to the BS2! I just need to receive a one byte value (0-255)
into a byte variable on the Stamp. It works great in HyperTerminal.
What is HyperTerminal doing than MSCOMM isn't? I'm definately a
newbie when it comes to serial communications!
Here's my test code:
VB Side:
Private Sub Form_Load()
MSComm1.DTREnable = False
MSComm1.Settings = "9600,n,8,1"
MSComm1.CommPort = 2
MSComm1.RThreshold = 1 MSComm1.PortOpen = True ' Opens port
MSComm1.Output = "128"
End
End Sub
'I can send an ASCII character "A" and the stamp recieves it OK
as decimal 97.
BS2 Side:
'{$STAMP BS2}
'{$PBASIC 2.5}
'{$PORT COM2}
DIRS = %1111111111111111
TESTDATA VAR byte
MAIN:
SERIN 16,84,[noparse][[/noparse]DEC TESTDATA]
DEBUG DEC TESTDATA
IF TESTDATA = 128 THEN
HIGH 7
ELSE
LOW 7
ENDIF
GOTO MAIN
I know this stamp code works because it works flawlessly from
HyperTerminal, so it has to be my ignorance of MSCOMM. Is there a way
to send a one-byte decimal (not ASCII CHR)value to the Stamp from VB?
Or even binary? MSCOMM seems to want ASCII. I hope this isn't too off
topic. I really appreciate any help I can get with this. Everything
is working great except fot this MSCOMM problem. BTW, I've set the
MSCOMM control send buffer to 1 character instead of the default 512.
Was this a mistake? I'm really over my head here.
Thanks!
I have created this nifty little home automation switcher using the
BS2 and some MAX395 IC's, but I need to interface with it from the PC
and I'm using VB6 to create the app. I've tried every suggestion I
could find from the forum, but can't get VB6 to send a simple decimal
value to the BS2! I just need to receive a one byte value (0-255)
into a byte variable on the Stamp. It works great in HyperTerminal.
What is HyperTerminal doing than MSCOMM isn't? I'm definately a
newbie when it comes to serial communications!
Here's my test code:
VB Side:
Private Sub Form_Load()
MSComm1.DTREnable = False
MSComm1.Settings = "9600,n,8,1"
MSComm1.CommPort = 2
MSComm1.RThreshold = 1 MSComm1.PortOpen = True ' Opens port
MSComm1.Output = "128"
End
End Sub
'I can send an ASCII character "A" and the stamp recieves it OK
as decimal 97.
BS2 Side:
'{$STAMP BS2}
'{$PBASIC 2.5}
'{$PORT COM2}
DIRS = %1111111111111111
TESTDATA VAR byte
MAIN:
SERIN 16,84,[noparse][[/noparse]DEC TESTDATA]
DEBUG DEC TESTDATA
IF TESTDATA = 128 THEN
HIGH 7
ELSE
LOW 7
ENDIF
GOTO MAIN
I know this stamp code works because it works flawlessly from
HyperTerminal, so it has to be my ignorance of MSCOMM. Is there a way
to send a one-byte decimal (not ASCII CHR)value to the Stamp from VB?
Or even binary? MSCOMM seems to want ASCII. I hope this isn't too off
topic. I really appreciate any help I can get with this. Everything
is working great except fot this MSCOMM problem. BTW, I've set the
MSCOMM control send buffer to 1 character instead of the default 512.
Was this a mistake? I'm really over my head here.
Thanks!
Comments
Also make sure handshaking is set to none...
Good luck!
Al Williams
AWC
* NEW: 3 years of Stamp Project of the Month
http://www.al-williams.com/sombook.htm
>
Original Message
> From: Wayne Hutchison [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=F8Ycg4mprMgldhdGy11FZ2GL5EezLE3jOJ5PMS5hRMVRhc7_Pbq8o5UhNBQyUtemUser4ggaG3Ko7f0]voxautomation@c...[/url
> Sent: Saturday, November 15, 2003 7:35 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] how to receive decimal value from VB
>
>
> Hello All...
> I have created this nifty little home automation switcher using the
> BS2 and some MAX395 IC's, but I need to interface with it from the PC
> and I'm using VB6 to create the app. I've tried every suggestion I
> could find from the forum, but can't get VB6 to send a simple decimal
> value to the BS2! I just need to receive a one byte value (0-255)
> into a byte variable on the Stamp. It works great in HyperTerminal.
> What is HyperTerminal doing than MSCOMM isn't? I'm definately a
> newbie when it comes to serial communications!
>
> Here's my test code:
>
> VB Side:
>
> Private Sub Form_Load()
>
> MSComm1.DTREnable = False
> MSComm1.Settings = "9600,n,8,1"
> MSComm1.CommPort = 2
> MSComm1.RThreshold = 1 MSComm1.PortOpen = True ' Opens port
> MSComm1.Output = "128"
> End
> End Sub
>
> 'I can send an ASCII character "A" and the stamp recieves it OK
> as decimal 97.
>
> BS2 Side:
>
> '{$STAMP BS2}
> '{$PBASIC 2.5}
> '{$PORT COM2}
> DIRS = %1111111111111111
> TESTDATA VAR byte
>
> MAIN:
> SERIN 16,84,[noparse][[/noparse]DEC TESTDATA]
> DEBUG DEC TESTDATA
> IF TESTDATA = 128 THEN
> HIGH 7
> ELSE
> LOW 7
> ENDIF
> GOTO MAIN
>
> I know this stamp code works because it works flawlessly from
> HyperTerminal, so it has to be my ignorance of MSCOMM. Is there a way
> to send a one-byte decimal (not ASCII CHR)value to the Stamp from VB?
> Or even binary? MSCOMM seems to want ASCII. I hope this isn't too off
> topic. I really appreciate any help I can get with this. Everything
> is working great except fot this MSCOMM problem. BTW, I've set the
> MSCOMM control send buffer to 1 character instead of the
> default 512. Was this a mistake? I'm really over my head here. Thanks!
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
With it set to 1, the MSCOMM1_OnComm event
will be triggered with each byte recieved.
My theory about what's happening is this:
1. You send the first byte.
2. The BS2 hardware echo's the first byte
back to your PC.
3. The PC's OnComm event is triggered.
I don't know what you are currently doing to
handle this.
If you set the RThreshold to 0, then the
MSCOMM control's receive buffer will just get
the data, and hold it till you have a chance
to remove it with MyStr = MSCOMM1.Input.
Thus:
1. You send all three bytes
2. The BS2 hardware echo's all three bytes
3. the MSCOMM control's receive buffer gets
all three bytes.
Note that "128" is not a one-byte variable,
but when received with the 'DEC' modifier,
it is STORED as a one-byte variable, so this
should do what you wanted.
--- In basicstamps@yahoogroups.com, "Wayne Hutchison"
<voxautomation@c...> wrote:
> Hello All...
> I have created this nifty little home automation switcher using the
> BS2 and some MAX395 IC's, but I need to interface with it from the
PC
> and I'm using VB6 to create the app. I've tried every suggestion I
> could find from the forum, but can't get VB6 to send a simple
decimal
> value to the BS2! I just need to receive a one byte value (0-255)
> into a byte variable on the Stamp. It works great in HyperTerminal.
> What is HyperTerminal doing than MSCOMM isn't? I'm definately a
> newbie when it comes to serial communications!
>
> Here's my test code:
>
> VB Side:
>
> Private Sub Form_Load()
>
> MSComm1.DTREnable = False
> MSComm1.Settings = "9600,n,8,1"
> MSComm1.CommPort = 2
> MSComm1.RThreshold = 1 MSComm1.PortOpen = True ' Opens port
> MSComm1.Output = "128"
> End
> End Sub
>
> 'I can send an ASCII character "A" and the stamp recieves it
OK
> as decimal 97.
>
> BS2 Side:
>
> '{$STAMP BS2}
> '{$PBASIC 2.5}
> '{$PORT COM2}
> DIRS = %1111111111111111
> TESTDATA VAR byte
>
> MAIN:
> SERIN 16,84,[noparse][[/noparse]DEC TESTDATA]
> DEBUG DEC TESTDATA
> IF TESTDATA = 128 THEN
> HIGH 7
> ELSE
> LOW 7
> ENDIF
> GOTO MAIN
>
> I know this stamp code works because it works flawlessly from
> HyperTerminal, so it has to be my ignorance of MSCOMM. Is there a
way
> to send a one-byte decimal (not ASCII CHR)value to the Stamp from
VB?
> Or even binary? MSCOMM seems to want ASCII. I hope this isn't too
off
> topic. I really appreciate any help I can get with this. Everything
> is working great except fot this MSCOMM problem. BTW, I've set the
> MSCOMM control send buffer to 1 character instead of the default
512.
> Was this a mistake? I'm really over my head here.
> Thanks!
If you elect to pass data in ASCII form from your VB program, try
this instead:
MSComm1.Output = "128." End
That way your DEC modifier will see the '.' and know the end of ASCII
numerics has been reached, do the conversion and store the value in
your TESTDATA variable. Any character other than "0" through "9"
would have the same effect, terminating the numeric character string
on the Stamp end.
Regards,
Steve