79758553

Date: 2025-09-08 06:12:41
Score: 0.5
Natty:
Report link

Most weighbridge indicators send ASCII strings with a standard format. A typical output looks like:
ST,GS,001234kg

using System;
using System.IO.Ports;

class Program
{
    static void Main()
    {
        SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
        port.NewLine = "\r\n";  // many indicators use CRLF as line end
        port.Open();

        while (true)
        {
            try
            {
                string rawData = port.ReadLine().Trim();
                Console.WriteLine("Raw: " + rawData);

                // Example: ST,GS,001234kg → extract weight only
                string[] parts = rawData.Split(',');
                string weight = parts[parts.Length - 1]; // last part
                Console.WriteLine("Weight: " + weight);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Endel Digital Solution