Shop OBEX P1 Docs P2 Docs Learn Events
Capture Data with Basic Stamp by RS232 and RS485 Comunications — Parallax Forums

Capture Data with Basic Stamp by RS232 and RS485 Comunications

MasterMaster Posts: 12
edited 2005-12-13 18:29 in BASIC Stamp
· Hi !!!
· I have a problem with a device for to capture a data with my basic stamp· 2p by RS232 and RS485·Comunications.
· I have to send a ASCI command to device and the device send me data in table form.

· I need to capture the data from a Row and Column specify.

How can I do this?????

I need an example.
test.bmp 399.7K

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2005-11-21 13:58
    Well, you need to find out in what order the data is sent from·this device.· It probably sends the data out as a row (my speculation.)· I figure you cannot poll the device for some particular line of data, it's going to give you what it has accumulated.· Your job is to receive the data and store it in a matrix using STR (command) and possibly SKIP, and then make use of it from there.·

    Study SERIN.

    Here is a program that I made to take the data that gets sent out from a GPS and then send it to an LCD (SERIN is related to the data collection, SEROUT is for the LCD activity):

    [size=2][code]
    ' {$STAMP BS2}
    ' {$PBASIC 2.0}
    ' {$PORT COM1}
    
    PA VAR Byte (2)
    PM VAR Byte (2)
    PD VAR Byte (3)
    NS VAR Byte (1)
    MA VAR Byte (3)
    MM VAR Byte (2)
    MD VAR Byte (3)
    EW VAR Byte (1)
    TM VAR Byte (6)
    AV VAR Byte (1)
    Prelims:
       DIRS = $0F        'MSB INs, LSB OUTs
       OUTL = %10000000  'preset OUTs
       INH  = %00000000
    PrepCUR:
       SEROUT 7,188,[noparse][[/noparse]$0c,$19,$00]  'form feed, blank cursor
    Rtrv:
       SERIN 9,188,[noparse][[/noparse]WAIT("GLL,"),STR PA\2,STR PM\2,SKIP 1,STR PD\3,SKIP 2,STR NS\1,SKIP 1,STR MA\3,STR MM\2,SKIP 1,STR MD\3,SKIP 2,STR EW\1,SKIP 1,STR TM\6,SKIP 5,STR AV\1]
    LCD:
       OUTL=%10000001            'LED=ON, gonna printout; serout bit HI for NO NUL
       SEROUT 7,188,[noparse][[/noparse]$02," * GPS BY PJALLEN *",$0A,$0D]
       SEROUT 7,188,[noparse][[/noparse]STR NS\1,"  ",STR PA\2,"deg ",STR PM\2,".",STR PD\3,"min"]
       SEROUT 7,188,[noparse][[/noparse]$0A,$0D]    'LF,CR
       SEROUT 7,188,[noparse][[/noparse]STR EW\1," ",STR MA\3,"deg ",STR MM\2,".",STR MD\3,"min"]
       SEROUT 7,188,[noparse][[/noparse]$0A,$0D]
       SEROUT 7,188,[noparse][[/noparse]"UTC ",STR TM\6]
       SEROUT 7,188,[noparse][[/noparse]"        ",STR AV\1]
       OUTL=%10000000            'LED=OFF, endof printout; serout bit HI for NO NUL
       GOTO Rtrv
    

    [/code][/size]
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2005-11-21 14:18
    Parallax provides a free software that downloads your data into Microsoft Excell.

    Have you considered using that? After it is free. I think it is in with the Insturmentation products.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • MasterMaster Posts: 12
    edited 2005-11-21 22:20
    How can i calcule with my basic stamp 2p for a comunication from 19200 bauds??
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-21 22:32
    No need to calculate -- you can use the attached template and all the grunt work for the most common baud rates has been done for you.· And if you change BS2 modules, no problem -- the conditional compilation statements handle the change automatically.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • MasterMaster Posts: 12
    edited 2005-11-30 16:17
    Greeting Parallax.

    My problem is painted in the document attachmented in·pdf formate.

    I need help with this.
  • MasterMaster Posts: 12
    edited 2005-12-01 13:31
    Dear Parallax,

    A gain i send the documents with the project that i need to do, because i thing that the other i sent with an error.


    Thank you...
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-01 16:54
    At 19200 it may not be possible to do what you want to do -- unless you can get the meter to insert some pacing between the bytes. That said, give it a try. Look in the manual under SERIN and for the WAIT and SKIP modifiers. It will take a bit of experimenting, but you might be able to construct a SERIN line that will capture the wattage value. Be patient -- this will probably take you a few hours of experimenting.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • MasterMaster Posts: 12
    edited 2005-12-02 21:09
    How Can I store a variable with Data command?

    I need an example.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-12-02 21:21
    I don't understand the question.· If your output stream is as shown then you would have to use WAIT and possibly SKIP in your SERIN routine, though these modifiers don't work well above 9600 baud unless there is pacing between the bytes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • MasterMaster Posts: 12
    edited 2005-12-13 16:49
    ·I Actually made my program, but need to convert the values (number ASCI) same to number Decimal for i to make comparisons.

    my program is the follow:

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}

    Msg VAR Byte
    I VAR Nib(12)
    Timeout1 CON 3750
    Timeout CON 3600
    Mando VAR Byte
    P0 VAR Byte
    P1 VAR Byte
    P2 VAR Byte
    P3 VAR Byte
    P4 VAR Byte
    P5 VAR Byte
    P6 VAR Byte
    P7 VAR Byte
    P8 VAR Byte
    P9 VAR Byte
    P10 VAR Byte
    M0 VAR Byte
    M1 VAR Byte
    M2 VAR Byte
    M3 VAR Byte
    M4 VAR Byte
    M5 VAR Byte
    M6 VAR Byte

    Display PIN 0
    Tx PIN 1
    Rx PIN 2
    SEROUT Tx,110,[noparse][[/noparse]"exit",CR]
    MAIN:
    GOSUB Clear
    GOSUB Serial
    GOSUB Clear


    · SERIN Rx,110,Timeout1,MAIN,[noparse][[/noparse]SKIP 2,B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11]
    · SEROUT Display,240,[noparse][[/noparse]B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,CR]
    · DEBUG B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,CR
    · PAUSE 1000
    · GOSUB login
    · GOSUB logged
    · GOSUB Fase
    · GOSUB Diagnostico

    IF P5="k" THEN led
    Normal:
    DEBUG CR, "La demanda es Menor"
    LOW 5
    HIGH 6
    PAUSE 100
    GOTO main

    Led:
    P10="1"
    IF P0>=P10 THEN LED1
    GOTO Normal
    LED1:
    DEBUG CR, "la demanda es Mayor"
    LOW 6
    HIGH 5
    PAUSE 100
    GOTO Main

    Clear:
    SEROUT Display,240,[noparse][[/noparse]12,17]
    DEBUG CLS
    RETURN
    Serial:
    SEROUT Display,240,[noparse][[/noparse]12,"attn -D",CR]
    SEROUT Tx,110,[noparse][[/noparse]"attn -D",CR]
    DEBUG "attn -D",CR
    PAUSE 1
    RETURN
    Login:
    · SEROUT Display,240,[noparse][[/noparse]12,"attn -3Super3 -s",B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,CR]
    · SEROUT Tx,110,[noparse][[/noparse]"attn -3Super3 -s",B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,CR]
    · DEBUG "attn -3Super3 -s",B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B11,CR
    · PAUSE 1
    · RETURN
    Logged:
    · SERIN Rx,110,Timeout,Login,[noparse][[/noparse]WAIT ("CIP"),B0 ]
    · DEBUG B0
    · SEROUT Display,240,[noparse][[/noparse]B0,CR]
    · PAUSE 1000
    · RETURN
    Fase:
    · SEROUT Tx,110,[noparse][[/noparse]"md -p",CR]
    · SEROUT Display,240,[noparse][[/noparse]12,"md -p",CR]
    · DEBUG "md -p",CR
    · PAUSE 1
    · RETURN
    Diagnostico:
    · SEROUT Display,240,[noparse][[/noparse]12]
    · SERIN Rx,110,Timeout,Fase,[noparse][[/noparse]WAIT ("S"),SKIP 29, P0,P1,P2,P3,P4,P5,P6,P7, WAIT ("S"),SKIP 29, M0,M1,M2,M3,M4,M5,M6]
    · SEROUT Display,240,[noparse][[/noparse]P0,P1,P2,P3,P4,P5,P6,P7,CR]
    · SEROUT Display,240,[noparse][[/noparse]M0,M1,M2,M3,M4,M5,M6,CR]
    · DEBUG P0,P1,P2,P3,P4,P5,P6,P7,CR
    · DEBUG M0,M1,M2,M3,M4,M5,M6,CR
    · PAUSE 1000
    · SEROUT Tx,110,[noparse][[/noparse]"exit",CR]
    · PAUSE 100

    · RETURN
  • MasterMaster Posts: 12
    edited 2005-12-13 18:29
    the idea it is, in the varibles P0 to P7 and M0 to M7 stores data, but this data is in ASCII format, and I cant ADD the Ps with Ms because are this in ASCCI format.

    example:

    I get

    P0=5, P1=7, P2=3, P3=4 AND

    M0=3, M1=2, M2=4, M3=1

    THE ADD IS 8975.

    I need to do the follow

    W0=(5*1000)+(7*100)+(3*10)+(4*1)

    W1=(3*1000)+(2*100)+(4*10)+(1*1)

    W2=W0+W1=8975.

    I cant do, because the number in the Ps and Ms are ASCII format, that is to say if P0=5 the number "5" isnt same to "5" in decimal.

    how can I to make that my number in ASCII it will be same to number in decimal.?
Sign In or Register to comment.