C# Read balance weight Toledo Prix PS 600 line

Asked

Viewed 1,913 times

-1

Hi, I’m trying to get the weight of a Toledo Model PS 600 scale. I used the example of the link below to carry out the communication: rnmioshi Oil Github

So far I can capture the COM port where the scale 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;
        }
    }

Import of 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 am unable to capture the weight at any time, either by data event received by 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));
        }
    }

Can anyone tell me how to solve this? Thank you.

  • Some error or simply cannot capture the value?

  • I can’t get the value, no error occurs.

  • You have already consulted the documentation or contacted the equipment support?

1 answer

-1

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

Try to put him inside a while or a for.

for (int i = 0; i < 50000; i++)
{
  _pesoAtual += serialPort1.ReadExisting();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.