I come from Delphi with the following code:
// COM port received data processing
procedure TMainForm.CommPortReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
redata: array[0..290] of byte;
begin
move(Buffer^, pchar(@redata)^, BufferLength); // copy data from COM buffer
end;
end;
And I want to do the same thing in C#:
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] byteReadData = new byte[290];
serialPort1 = (SerialPort)sender;
string indata = serialPort1.ReadExisting();
Console.WriteLine("Data Received:");
Console.Write(indata);
// copy data from COM buffer ???
}
I don't know how to take the data from SerialDataReceivedEventArgs and copy it to my byte array byteReadData.
This is what I write to serial port: https://i.stack.imgur.com/EfLI1.png This is what I should be reading from serial port but it fails: https://i.stack.imgur.com/PllQi.png