Shop OBEX P1 Docs P2 Docs Learn Events
serial COM Matlab — Parallax Forums

serial COM Matlab

ArchiverArchiver Posts: 46,084
edited 2002-11-29 11:43 in General Discussion
I've got the Matlab code working.
For future reference to anyone that might find it useful, Matlab R12
has a bug in it. All serial objects must be created and opened from
the matlab installation work directory. Matlab R13 fixes this bug.

Now the problem I have is that I have to send my command on two
separate lines.

fprintf(s1, 'cmd:')
fprintf(s1, '0')
or
fprintf(s1, 'cmd:')
fprintf(s1, '1')

why can't I just do -

fprintf(s1, 'cmd:1')
or
fprintf(s1, 'cmd:0')

Is there someway I can force it to process the data sent at the same
time as the wait string?

thanks for the help Stamp folk!




' {$STAMP BS2 }


PIN_CMD VAR BIT


Again:
TOGGLE 10
SERIN 16, 16468, [noparse][[/noparse]WAIT("cmd:"), DEC PIN_CMD]

IF PIN_CMD = 1 THEN TurnOn
IF PIN_CMD = 0 THEN TurnOff
GOTO Again


TurnOn:
HIGH 0
DEBUG CLS, BIN1 IN0
GOTO Again


TurnOff:
LOW 0
DEBUG CLS, BIN1 IN0
GOTO Again

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-29 11:43
    Hi Nigel

    I believe the reason for you problem ist that the serin modifiers such as
    WAIT and DEC
    consume to much time to sync up with the data stream - you subsequently
    divided your stream in a part
    for the WAIT modifier and a second part for the DEC modifier - the fact that
    this works is a strong
    hint to me that it is a serin modifier timing problem. One way to follow is
    to stick with that solution
    an to devide your data stream that satifies the time demands of the serin
    modifiers. An other way
    is to change the stamp code and avoid serin modifiers. BTW. the stamp manual
    and other resources
    on stamp serial communication disencurrage the deliberate use of serin
    modifiers and recommend
    to reduce it to a single WAIT and subsequent STR. The fastest is a STR only.
    My experience
    is that a (single byte) WAIT, followed by a multibyte STR works well and
    reliable up to 9600bps.
    Of course the situation improves also at lower bitrates.

    Hope this helps.

    Regards
    Adrian

    Original Message
    From: "Nigel" <kailar88@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, November 28, 2002 10:08 PM
    Subject: [noparse][[/noparse]basicstamps] serial COM Matlab


    > Now the problem I have is that I have to send my command on two
    > separate lines.
    >
    > fprintf(s1, 'cmd:')
    > fprintf(s1, '0')
    > or
    > fprintf(s1, 'cmd:')
    > fprintf(s1, '1')
    >
    > why can't I just do -
    >
    > fprintf(s1, 'cmd:1')
    > or
    > fprintf(s1, 'cmd:0')
    >
    > Is there someway I can force it to process the data sent at the same
    > time as the wait string?
    >
    > thanks for the help Stamp folk!
    >
    >
    >
    >
    > ' {$STAMP BS2 }
    >
    >
    > PIN_CMD VAR BIT
    >
    >
    > Again:
    > TOGGLE 10
    > SERIN 16, 16468, [noparse][[/noparse]WAIT("cmd:"), DEC PIN_CMD]
    >
    > IF PIN_CMD = 1 THEN TurnOn
    > IF PIN_CMD = 0 THEN TurnOff
    > GOTO Again
    >
    >
    > TurnOn:
    > HIGH 0
    > DEBUG CLS, BIN1 IN0
    > GOTO Again
    >
    >
    > TurnOff:
    > LOW 0
    > DEBUG CLS, BIN1 IN0
    > GOTO Again
    >
Sign In or Register to comment.