Juan Pablo Gomez
Juan Pablo Gomez

Reputation: 5524

Serial port read string

I have a serial port app that read weighing machine.

    public void Read()
    {
        while (Puerto.BytesToRead > 0)
        {
            try
            {
                string inputData = Puerto.ReadExisting();
                dataReceived = inputData;
            }
            catch (TimeoutException) { }
        }
    }

the return string is like this

Data returned by weighing machine

It has other extrange chars in it, how can i do to parse or get a clean data from it? all I need is 0.52lb

Upvotes: 0

Views: 1734

Answers (2)

Bobby
Bobby

Reputation: 251

I have no idea what weighing machine is it and what the serial port specs on it but, if it is black box to you too then, check the following: - check if you have a technical spec that explains what comes out of RS232 port - do several (10?) samples with one sample weight and see if the number of bytes are delivered each time - if you see the number of bytes being constant (barring discrepancy in the 0.52lb text changing to 0.5lb once in a while), it is likely that garbage following the weight is additional binary data. - if not, and you see the weight (text) with exact offset each time, you just can scrape the output

this is complete reverse engineering, I suggest going after technical spec and doing more insightful data handling though.

Upvotes: 1

Eugene Osovetsky
Eugene Osovetsky

Reputation: 6541

This could be anything - a bug in the weighing machine, some sort of hardware issue, or a problem in how the serial port is configured. I would suspect a configuration problem. Make sure all the settings are correct (BaudRate, Handshake, Parity, StopBits). Also, try connecting to the same serial port device using another program (e.g. see http://helpdeskgeek.com/windows-7/windows-7-hyperterminal/ ) and see if you see the same garbage data.

Upvotes: 1

Related Questions