C # Read Balance Weight Toledo Line Prix PS 600

-1

Hello, I'm trying to get the weight of a Toledo Model PS 600 scale. I used the example of the link below to perform the communication: rnmioshi toledo Github

So far I can capture the COM port where the balance is connected and open the connection as follows:

 public Form1()
    {
        InitializeComponent();

        serialPort1.PortName = ConfigurationManager.AppSettings["PortaSerial"];  //"COM6";
        serialPort1.BaudRate = 4800;
        serialPort1.DataBits = 8;
        serialPort1.DtrEnable = true;
        serialPort1.StopBits = StopBits.One;
        serialPort1.DataBits = 7;
        serialPort1.NewLine = "vbCr";
        serialPort1.ReadTimeout = 500;
        serialPort1.WriteTimeout = 500;
    }


    private void Inicio_Click(object sender, EventArgs e)
    {
        serialPort1.Open();
        if (serialPort1.IsOpen)
        {
            Inicio.Enabled = false;
            Parar.Enabled = true;
        }
    }

Importing DLLs is also being done:

 // Get a handle to an application window.
    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    // Activate an application window.
    [DllImport("USER32.DLL")]

However, I'm not able to capture the weight at any time, either by data event received by the COM port, or by forcing the balance weight reading.

 private void CapturarPeso()
    {
        // Capturar peso
        _pesoAtual = serialPort1.ReadExisting();

        if (!string.IsNullOrEmpty(_pesoAtual))
        {
            _pesoAtual = serialPort1.ReadTo("\x0D");
            _pesoAtual = _pesoAtual.Replace("\x02", "");
            _pesoAtual = _pesoAtual.Replace("00.", "0.");
            _pesoAtual = _pesoAtual.Replace(".", ",");
            this.Invoke(new EventHandler(DisplayText));
        }
    }

Does anyone know how to resolve this? Thank you.

    
asked by anonymous 08.01.2018 / 16:39

1 answer

-1

Hi, I was with the same problem, and at least with me the error was in the response time for the command .ReadExisting();

Try to put it inside a while or a for .

for (int i = 0; i < 50000; i++)
{
  _pesoAtual += serialPort1.ReadExisting();
}
    
10.08.2018 / 21:28