Home Read SerialPort buffer using DataReceived event handler
Reply: 0

Read SerialPort buffer using DataReceived event handler

user1037 Published in July 18, 2018, 10:23 pm

I come from Delphi with the following code:

// COM port received data processing
procedure TMainForm.CommPortReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
  redata: array[0..290] of byte;
  move(Buffer^, pchar(@redata)^, BufferLength); // copy data from COM buffer

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:");
    // 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.imgur.com/x8oK5PI.png This is what I should be reading from serial port but it fails: https://i.imgur.com/WQNhmqa.png

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.326485 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO