PDA

View Full Version : problems with values when converting with STR



Andreas
07-23-2005, 11:50 PM
I realy need your help. I want to take my value from my SerString1 and put·it in my "SEROUT 15, ServoBaud+$8000,["!SC", 11, 1, pw.LOWBYTE, pw.HIGHBYTE,CR]" as "pw". How do I make this work? I can see the value correct in "SEROUT Port,Baud,[" NR1: ", STR SerString1]
" but when I try to "convert" it into "pw.LOWBYTE and pw.HIGHBYTE its not working anymore. Can you please help me=



' {$STAMP BS2}
' {$PBASIC 2.5}

pw VAR Word
ServoBaud CON 396
Baud CON 16780
Port CON 16


SerString1 VAR Byte(6)
SerString1(9)=0
SerString2 VAR Byte(6)
SerString2(9)=0
SerString3 VAR Byte(6)
SerString3(9)=0
SEROUT Port, Baud, ["Welcome"]
GOSUB sound_0:
PAUSE 100
Main:
SERIN Port,Baud,Main,2000,Main, [WAIT ("coord"), STR SerString1\5\"*", STR SerString2\5\"*", STR SerString3\5\"*"]

'PAUSE 100

SEROUT Port,Baud,[" NR1: ", STR SerString1]
SEROUT Port,Baud,[" NR2: ", STR SerString2]
SEROUT Port,Baud,[" NR3: ", STR SerString3]
PAUSE 1000

'Servo1
SEROUT 15, ServoBaud+$8000,["!SC", 11, 1, pw.LOWBYTE, pw.HIGHBYTE,CR]
GOTO Main

sound_0:
········ FREQOUT spkr,1000,2000
RETURN

Bruce Bates
07-24-2005, 12:21 AM
Andreas -

It's not quite clear what you want to do, but take a look at this. I may or may not have a picture of what you want to do:

Main:
SERIN Port,Baud,Main,2000,Main, [WAIT ("coord"), STR SerString1\5\"*", STR SerString2\5\"*", STR SerString3\5\"*"]

'PAUSE 100

SEROUT Port,Baud,[" NR1: ", STR SerString1]
SEROUT Port,Baud,[" NR2: ", STR SerString2]
SEROUT Port,Baud,[" NR3: ", STR SerString3]
PAUSE 1000

pw.HIGHBYTE=SerString1(0)
pw.LOWBYTE=SerString1(1)

'Servo1
SEROUT 15, ServoBaud+$8000,["!SC", 11, 1, pw.LOWBYTE, pw.HIGHBYTE,CR]
GOTO Main

Parenthetically, the constant "spkr" is presently undefined in the program you posted.

Regards,

Bruce Bates

Andreas
07-24-2005, 12:46 AM
As you probably already know is that I have a Parallax Servo controller that I want to control from my BS2. I control the BS2 from a small and simple VB6 program that I have been written. Everything works except the servoposition. When I send the command from VB6 program: MSComm1.Output = "start" & "255*" & "400*" & "500*" I want the BS2 to translate the command to the Servo Controller to command the servos to go to pos: 255, 400 and the 3:rd to 500. The problem is that something get lost in the translation from the "SerString". I dont think the whole value is translated from the "SerString" to the "pw.LOWBYTE" I tried your example but I wasnt able to get it working now either. Maybe I have been working with this too long.

Yanroy
07-26-2005, 12:09 AM
Have you tried sending binary data out the serial port instead of ASCII?· I don't know how to do this in VB, but it will make the stamp code much easier (and faster).· It should eliminate the need for STR in the serial commands.