How to see indata from outside DataReceivedHandler? Everything that I found on the Internet solved the problem of outputting to the textbox using the delegate, but I do not need the output in the UI, but simply pull out the string variable to process it and send it to Modbus TCP.

private static void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string indata = sp.ReadExisting(); } 
  • DataReceivedHandler runs in an additional stream, so if you need access to shared data, you need to use some kind of synchronization. There is no access to shared data from different streams - there is no need for synchronization. - MBo

1 answer 1

вытащить переменную строкового типа обработать ее и отправить в Modbus TCP

 private static void DataReceivedHandler( object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string indata = sp.ReadExisting(); ProcessIndata(indata); SendToModbus(indata); } 

you need to implement ProcessIndata and SendToModbus

  • thanks, it worked! - TYTAHXAMOH 5:43 pm
  • @TYTAHXAMOH please - tym32167