serial port - SerialDataReceivedEventHandler with C# and PLC (not triggering event) -
I have used nModBus to communicate my PLC with my C # application, but now I have all of the PLC Reading is going on continuously through a loop for input.
I want to design my code so that only when a piece of data is received through the serial port, then it will trigger the loop to read through each input, Which input is higher.
Here I have what I have set breakpoints and my code never accesses the DataReceivedHandler method, I manually change PLC input high (using a jumper wire). Any suggestions or comments?
Namespace WindowsFormsApplication2 {Static Class Program {
Public Fixed Zero Main () {SerialPort mySerialPort = new SerialPort ("COM1"); MySerialPort.BaudRate = 38400; MySerialPort.Parity = Parity.Odd; MySerialPort.StopBits = StopBits.One; MySerialPort.DataBits = 8; Messierport Airport Handshake = Handshake.No; MySerialPort.ReadBufferSize = 4096; MySerialPort.DataReceived + = New SerialDataReceivedEventHandler (DataReceivedHandler); Imodbus SerialMaster Master = ModebusSerialMaster. KrettRetu (Myersialport); Console.light line ("press any key to continue ..."); Console.WriteLine (); Console.ReadKey (); MySerialPort.Close (); } Public static Zero Datairisevandler (Object Sender, Serial Data ReservesEurges E) {SerialPort sp = (SerialPort) Sender; String indenta = sp.ReadExisting (); Console WrightLine ("Received Data:"); Console.Write (indata); }
Master your PC, but choose the event. When it is true, then "bulk", then reset "event" to your PC / master.
I will make this "event" a different "communication event" from the actual UI. Become "CommEvent", PLC has set it (actual event occurs), and once it finishes bulk com, the PC / Master cleans it.
Read CommEvent if the Commevent is true Bulk Read Clear Comm.
Comments
Post a Comment