3
Man Arduous sends data continuously to my C# via serial port. However, I understand that the first figures sent by Arduous are simply disappearing, sometimes disappear more numbers, sometimes less, and always only at the beginning of the application. Example:
Arduino sends -> "0 1 100 1023 45 67 ..."
C# gets -> " 1023 45 67 ..." or "1 100 1023 45 67..."
Currently I am printing in Serial as follows:
//ARDUINO:
int CANAL1, CANAL2, CANAL3;
void setup()
{
Serial.begin(9600);
}
void loop()
{
analogReference(DEFAULT);
CANAL1 = analogRead(A0);
Serial.print(CANAL1,DEC);
Serial.print(" ");
CANAL2 = analogRead(A1);
Serial.print(CANAL2,DEC);
Serial.print(" ");
CANAL3 = analogRead(A2);
Serial.print(CANAL3,DEC);
Serial.print(" ");
}
And in my application in C#, to receiving of the data is made as follows:
//C#
string RxString = "";
private void SerialCOM_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (SerialCOM.IsOpen)
{
SerialPort sData = (SerialPort)sender;
{
RxString += sData.ReadExisting();
}
}
}
This kind of problem could not happen in my application because it would trigger problems with other functions.
Is there something wrong with receiving or sending the information? I’ve done it and I’ve repeated it many times and all this same problem happens.
As you can attest programmatically that the messages sent and received are exactly these?
– Caio de Paula Silva
I landed the Arduino input A0 in the hardware and left a known signal in A1 and A2, made inspection by the Serial Monitor proving that the first number corresponded to the input A0, every time.
– Felipe Mateus
Losing information in serial communication is normal. Your application should be robust enough to try to signal communication errors in the communication protocol.
– Marcelo Shiniti Uchimura
Anyway, you can try handshaking hardware https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.handshake?redirectedfrom=MSDN&view=netframework-4.7.2
– Marcelo Shiniti Uchimura
If it is normal to lose information in communication, there is some way to know what information and which Arduino input it belongs to by C#?
– Felipe Mateus
I’ll take a look at this Handshake, thanks
– Felipe Mateus