Shop OBEX P1 Docs P2 Docs Learn Events
problems with values when converting with STR — Parallax Forums

problems with values when converting with STR

AndreasAndreas Posts: 3
edited 2005-07-25 16:09 in BASIC Stamp
I realy need your help. I want to take my value from my SerString1 and put·it in my "SEROUT 15, ServoBaud+$8000,[noparse][[/noparse]"!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,[noparse][[/noparse]" 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, [noparse][[/noparse]"Welcome"]
GOSUB sound_0:
PAUSE 100
Main:
SERIN Port,Baud,Main,2000,Main, [noparse][[/noparse]WAIT ("coord"), STR SerString1\5\"*", STR SerString2\5\"*", STR SerString3\5\"*"]

'PAUSE 100

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

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

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

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-07-23 16:21
    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, [noparse][[/noparse]WAIT ("coord"), STR SerString1\5\"*", STR SerString2\5\"*", STR SerString3\5\"*"]

    'PAUSE 100

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

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

    'Servo1
    SEROUT 15, ServoBaud+$8000,[noparse][[/noparse]"!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
  • AndreasAndreas Posts: 3
    edited 2005-07-23 16:46
    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.
  • YanroyYanroy Posts: 96
    edited 2005-07-25 16:09
    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.
Sign In or Register to comment.