I had an application that retrieves data from an EXA brand scale, from the serial port c #. I would like to do the same thing, but this time by another brand, KERN PFB, the problem is that the SerialDataReceivedEventHandler event never executes. I do not know what I missing here .
I tried with this : How do I use dataReceived event of the SerialPort Port Object in C#?
public static SerialPort mySerialPort = new SerialPort("COM1");
public static string indata = string.Empty;
public static void SetSetting()
{
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true;
mySerialPort.DataReceived += MySerialPort_DataReceived;
}
public static void MySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
indata += sp.ReadExisting();
}
public static float GetPesage()
{
indata = string.Empty;
mySerialPort.Open();
Thread.Sleep(1000);
string[] dataSplited = indata.Trim().Split(' ');
float poids = 0;
//
...
//
mySerialPort.Close();
return poids;
}
I expect data is received but isn't.
Thank you.