Skip to main content
1 de 5

How to read serail port (weighing machine) from c#

i have a problem when i want to read a serial port (weighing machine) from c#

the method "DataReceivedHandler" never is triggered

private static SerialPort puertoSerial;

public static void InitSerialInterface(string puerto, int baudios)
{ 
              mySerialPort.PortName = "COM1";
             mySerialPort.BaudRate = 9600;
             mySerialPort.Parity = Parity.Even;
             mySerialPort.StopBits = StopBits.One;
             mySerialPort.DataBits = 7;
             mySerialPort.Handshake = Handshake.None;
             mySerialPort.DtrEnable = true;
            mySerialPort.RtsEnable = true;
            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(mySerialPort_DataReceived);
             mySerialPort.Open();
}
       //THIS METHOD NEVER triggered :(
private static void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;
            string indata = sp.ReadExisting();
            Console.WriteLine("Data Received:");
            Console.Write(indata);
        }