Shop OBEX P1 Docs P2 Docs Learn Events
Difficulty debugging serin as ascii — Parallax Forums

Difficulty debugging serin as ascii

KennyRKennyR Posts: 15
edited 2008-12-10 15:38 in BASIC Stamp
Im using a camera that receives and echos back ascii commands. Im sending the ascii command ":RF95500" to a camera. This command is to tell the camera to echo something back (which it is). My problem is when i try to debug what it is·echoing back its not in ascii. The camera should echo back something like :RF955xx, where "xx" is 00-FF. It echos back:

cam = "º"
cam = "9"
cam = "3"
cam = "‚"
cam = "ç"
cam = "T"
cam = "S"
cam = "5"
cam = ">"
cam = "‚"
cam = "5"
cam = "Í"
cam = "M"
cam = "5"
cam = ">"
cam = "0"
cam = "Í"
cam = "ó"
cam = "5"
cam = "5"
MY code is as follows:



cam VAR Byte

DO
SEROUT 1, 813, [noparse][[/noparse]":RF95500"]
GOSUB in
GOSUB bug
LOOP

in:
SERIN 2, 813, [noparse][[/noparse] cam ]
RETURN

bug:
DEBUG ASC? cam
RETURN

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-12-08 21:28
    Take a look at the help file for "formatters" in SERIN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-12-08 22:41
    You need to declare

    CAM VAR BYTE(10) -- Declare "CAM" as an array of bytes

    SERIN 2, 813, [noparse][[/noparse]STR Cam] -- Recieve bytes into CAM

    If the camera is sending back a 'string' of bytes, the BS2 will miss some of the bytes if you code it the way you have. The BS2 MUST be 'waiting' in the SERIN statement when the camera starts sending back data. And you MUST capture all the data before trying to do anything with it.

    The 'STR' modifier (see under SERIN) also allows you to 'get' a fixed number of bytes, which looks like what you want.
  • KennyRKennyR Posts: 15
    edited 2008-12-09 18:42
    code is as follows:

    cam VAR Byte(8)

    init:
    SEROUT 1, 813, [noparse][[/noparse]":WF90000",":WFCC800",":WF95001", ":WF95100",":WF95301",":wF9400A05",":wF9420F05", ":WF95101",":WF95310"]

    DO
    SEROUT 1, 813, [noparse][[/noparse]":RF95500"]
    SERIN 2, 813, [noparse]/noparse]STR cam\8[color=white]·[/color
    DEBUG· STR cam\8
    LOOP


    Ive tried alot of things and nothing seems to work. What I'm trying to do is, I have a camera that has motion detection built into it. The user sets parameters of where in the cameras field of view they want to detect movement. So if there is movement in a ceratain part of the viewing screen the camera will detect it. The command :RF95500 is then sent continously to·the camera. This command·continously tells the camera to echo back, to the user, ·the location of its·detection (the location of detection is echoed back in an 8 byte ascii string).·I have all of this working in Visual Basic 6, but·i want the bs2px to do it.

    The initial serout command just set the parameters of the camera, and it works fine. But the do loop is giving me problems.·Its doesnt seem to be continuosly sending whats inside the loop because when the program runs i only have·two 8 byte ascii strings in the debug window.·I thought a do loop runs continously, therefore there debug window should continously have a new 8 byte ascii·string in it depending on where there is detection.

    There·SEROUT 1, 813, [noparse][[/noparse]":RF95500"]·command·is suppose to continously tell the camera to echo back the 8 byte ascii string corresponding to the·location of detection. The SERIN 2, 813, [noparse][[/noparse]STR cam\8· ] command should·be continously taking into the bs2px, ·the echoed back·8 byte ascii string corresponding to the·location of detection.·And the·DEBUG STR cam\8··should continously·display the 8 byte ascii string in the debug window.
    This is what·i get in the debug window:


    :WF95310:RF95500

    Theses two strings are; the last 8 byte string in the initial serout command and the 8 byte string in the·second serout command. I dont always get these·strings, sometimes· bytes are missing and strange characters appear.For example:

    :RF9550
    •Tþ5310:
    þWF95310
    :WF531çRF95500


    LçWF9531‚Ò’}ô955



    I should recieve an 8 byte ascii string like:···· :RF955xx··· where xx continously changes depending on where there is detection.

    Ive tried waits, timeouts, different formaters,pauses, etc...

    Im confused and need some assistance.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-12-09 19:03
    1. How far away is your camera? And are you using a MAX232 to talk to it? And have you run TX, RX, and a good Ground wire to it?

    2. You might need a separate 'recieve buffer' chip to collect the bytes coming back from the camera, which will be able to recieve the data.

    3. You probably should size "Cam" to be a 9-byte array. The BS2 runtime will put a 'zero' byte following the bytes it recieves. This lets you say
    "Debug STR Cam" -- and 'Debug' will know to stop at the zero byte. If you say "DEBUG STR Cam\8", then 'leftover garbage' can be output.

    So the SERIN will put valid bytes in locations 0..7, location 8 will get a 'zero' byte, and DEBUG will know how to output it.
  • KennyRKennyR Posts: 15
    edited 2008-12-10 13:10
    1. the camera is right next to me so its not a communication issue due to long distance. I do have a TX,RX, and good ground.

    The way i have my code set up should be displaying ascii in the DEBUG window correct? Because the camera is outping ascii and im not doing any format changes with the stamp.

    Also do you know why my DO LOOP is not continously running and throwing values into the DEBUG?
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-12-10 13:16
    Oh, sure, that's because the BS2 will wait FOREVER if it has to in the "SERIN" to get the requested data. If the Camera doesn't send anything, the BS2 continues to wait.

    You MIGHT want to add a time-out to the SERIN statement, of like a half-second to a second, so it WILL terminate at some point.

    Oh, you mentioned nothing about any MAX232 chip -- are you using one? Or are you simply doing straight TTL RS-232 signalling?
  • KennyRKennyR Posts: 15
    edited 2008-12-10 15:38
    im not using a MAX232 chip. the BS2 output and recieves TTL and the camera outputs and recieves TTL, so i shouldnt need a MAX232 chip.
Sign In or Register to comment.