Working with continuous output hardware

The task:
I'm trying to use a piece of hardware that outputs readings continuously (a floor scale) thru an Rs232 9 pin connection. I have it connected to a Rs232 to TTL converter and then to D4 and D5 on a Arduino Nano. Attached is the page of the users manual with the format of the output. I'm starting with the SoftwareSerial example sketch (as opposed to the HardwareSerial or AltSoftSerial, etc.) because there are other parameters to the overall job that i'm omitting for now to keep this simple. One thing at a time. Just know that there's another component running simultaneously on I2C and it connects to A4 and A5.

The Error:
I'm not going to list a specific error because this code won't work for reasons that are obvious even to me. I just don't know where to go from here.

The question:
How can i modify this to except the format spec'd in the manual (attached) and print just the weight to the serial monitor? or is there a sketch out there that is more appropriate for the job.

thx

*/

// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>

#define rxPin D4
#define txPin D5
#define ledPin 13

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() {
  // listen for new serial coming in:
  char someChar = mySerial.read();
  // print out the character:
  mySerial.print(someChar);
  // toggle an LED just so you see the thing's alive.  
  // this LED will go on with every OTHER character received:
  toggle(13);

}


void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState); 
  // if pinState = 0, set it to 1, and vice versa:
  pinState = !pinState;
}

quote:"The question:
How can i modify this to except the format spec'd in the manual (attached) and print just the weight to the serial monitor? or is there a sketch out there that is more appropriate for the job.".

First off, you are reading the serial without even testing to see if there is a character in the buffer to be read.

Second, If you know there is a character indicating the beginning of a transmission, throw away everything until you read that character. OR if the message ends with a specific character, throw away every character up to that point and then toss the end character. The next character read will begin a new message. I guess you will need to count characters to get the complete message.

Paul

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Try this. Not compiled (compiles with errors for a 2560 due to 'D4' etc) or tested.

// include the SoftwareSerial library so you can use its functions:
#include <SoftwareSerial.h>

#define rxPin   D4
#define txPin   D5
#define ledPin  13


// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

#define MAX_BUFF_SIZE   31
char
    RxBuffer[MAX_BUFF_SIZE+1];
char
    szWeight[50];
        
void setup() 
{
    // define pin modes for tx, rx, led pins:
    pinMode(rxPin, INPUT);
    pinMode(txPin, OUTPUT);
    pinMode(ledPin, OUTPUT);
    // set the data rate for the SoftwareSerial port
    mySerial.begin(9600);
    //set the serial monitor
    Serial.begin(9600);
    
}//setup

void loop() 
{
    if( ReadScale() )
        Serial.print( szWeight );
        
}//loop

#define ST_SYNCUP       0
#define ST_SYNCED       1
//
bool ReadScale( void )
{
    char
        ch;
    static byte
        buffptr = 0,
        stateScale = ST_SYNCUP;

    if( mySerial.available() )
    {
        ch = mySerial.read();
        
        switch( stateScale )
        {
            case    ST_SYNCUP:
                //looking for a LF character indicating the end of the current message
                if( ch == '\n' )
                {
                    buffptr = 0;
                    stateScale = ST_SYNCED; 
                    
                    return false;
                       
                }//if
                                
            break;
    
            case    ST_SYNCED:
                RxBuffer[buffptr] = ch;
                buffptr++;
                if( buffptr == MAX_BUFF_SIZE )
                    buffptr = MAX_BUFF_SIZE;
                    
                if( ch == '\n' )
                {
                    //msg is done; parse to print string and reset buff pointer
                    //
                    //should still be in sync; added robustness can check this if desired
                    //by making sure 17th byte is CR and 18th is LF due to known msg structure
                    //if things get out of sync, go back to ST_SYNCUP and try to resync
                    ParseMessage();
                    buffptr = 0;

                    //true return means msg is finished and string is ready to print
                    return true;
                    
                }//if

            break;
                    
        }//switch
        
    }//if
    
    return false;
                
}//ReadScale

//structure of scale message is well defined
//xx,yy,zzzzzzzz uu cl
//XX = S1 (index 0, 2 bytes)
//  ST=standstill
//  US=not standstill
//  OL = overload
//YY = S2 (index 3, 2 bytes)
//  GS=gross mode
//  NT=net mode
//ZZ=S3 (index 6, 8 bytes)
//  weight, with '+'/'-' and '.'
//UU=S4 (index 14, 2 bytes)
//  kg or lb
//c=CR (index 16, 1 byte; '\r')
//l=LF (index 17, 1 byte; '\n')
//
void ParseMessage( void )
{
    byte
        index;
          
    //just copy first 16 chars of the message to a printable string and add a NULL termination 
    for( index=0; index<16; index++ )
        szWeight[index] = RxBuffer[index];

    //index now points to position after last msg char; put a NULL there
    szWeight[index] = 0x00;   //null termination
    
}//ParseMessage