Shop OBEX P1 Docs P2 Docs Learn Events
Reading RS232 scale — Parallax Forums

Reading RS232 scale

ArchiverArchiver Posts: 46,084
edited 2003-05-12 04:19 in General Discussion
I have a digital scale with RS232 but cannot understand how to use
the data in the scale's manual to write the code for my BS2. The
manual states the followig:

Speed: 2400 bps
word length; 8 bits
parity: non
stop bits: 1

Data format: (LF)(sign)xxxx.xxx(unit)(LF)hh(ETX)
LF = is ASCI line feed
ETX = ASCII end-of-text
unit = can be "kg", "lb", or "oz"
sign = can be "+" or "-"
xxxx.xx is the weight read by the scale
hh is a two-byte scale status:
high-byte:
bit 0 high = scale in motion
low = scale stable
bit 1 high = scale at zero
low = scale not zero
bit 2 Not used
bit 3 Not used

Low-Byte:
bit 0 high = scale under capacity
low = scale not under capacity
bit 1 high = scale over capacity
low = scale not over capacity
bit 2 Not used
bit 3 Not used

I used 16780 for baud rate after checking with the version 2.0
manual and then tried all kind of different variation of the Serin
command with no luck. I just get rubbish.

Any help as to how to structure the Serin command to receive the
above sequence of information?

many thanks in advance...


AL

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-05-12 04:17
    How about:

    SERIN ... [noparse][[/noparse] byte1,byte2,dec4 word1, ".", dec3 word2, byte3, byte4,
    byte5, hex4 word3, byte6]

    Now:
    Byte1= 10 (sanity check)
    Byte2= +/-
    Word1=integer part of weight
    Word2=fractional part of weight
    Byte3=k,l, or o
    Byte4=g,b, or z
    Byte5=10
    Word3=status word (I'm assuming hh is 4 hex digits?)
    Byte6=ETX (sanity check)

    You can check Byte1,5, and 6 to make sure you have a good frame. You
    can't really sync reliably on the LF because it occurs twice. However,
    if you see a bad frame you could start reading bytes until you get an
    ETX and then discard it all and go back to waiting for a frame.

    This is all off the top of my head and may not be exactly right, but it
    ought to be close.

    Al Williams
    AWC
    * Easy RS-232 Prototyping
    http://www.al-williams.com/awce/rs1.htm



    >
    Original Message
    > From: brownstamp [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=7gEB7kXrU4Pjrx_oWKR5F_GA2-UHBaLk5BhDDi7oeWus-2Fvo-Y6ZwcaTPIaHtYLqzVWRlZMz5cVPPFsmA]brownstamp@y...[/url
    > Sent: Sunday, May 11, 2003 4:58 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Reading RS232 scale
    >
    >
    > I have a digital scale with RS232 but cannot understand how to use
    > the data in the scale's manual to write the code for my BS2. The
    > manual states the followig:
    >
    > Speed: 2400 bps
    > word length; 8 bits
    > parity: non
    > stop bits: 1
    >
    > Data format: (LF)(sign)xxxx.xxx(unit)(LF)hh(ETX)
    > LF = is ASCI line feed
    > ETX = ASCII end-of-text
    > unit = can be "kg", "lb", or "oz"
    > sign = can be "+" or "-"
    > xxxx.xx is the weight read by the scale
    > hh is a two-byte scale status:
    > high-byte:
    > bit 0 high = scale in motion
    > low = scale stable
    > bit 1 high = scale at zero
    > low = scale not zero
    > bit 2 Not used
    > bit 3 Not used
    >
    > Low-Byte:
    > bit 0 high = scale under capacity
    > low = scale not under capacity
    > bit 1 high = scale over capacity
    > low = scale not over capacity
    > bit 2 Not used
    > bit 3 Not used
    >
    > I used 16780 for baud rate after checking with the version 2.0
    > manual and then tried all kind of different variation of the Serin
    > command with no luck. I just get rubbish.
    >
    > Any help as to how to structure the Serin command to receive the
    > above sequence of information?
    >
    > many thanks in advance...
    >
    >
    > AL
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-12 04:19
    Al-

    If your scale uses "true" logic levels (an idle line would typically
    read 5V), you'd need 396:

    SERIN pin,396,[noparse][[/noparse]WAIT ($0A),sign,DEC ints,DEC frac,STR units\2...

    At 2400 baud you should be able to liberally use the SERIN modifiers
    to your advantage.

    Regards,

    Steve

    On 11 May 03 at 21:58, brownstamp wrote:

    > I have a digital scale with RS232 but cannot understand how to use
    > the data in the scale's manual to write the code for my BS2...
Sign In or Register to comment.