public override void OnSimulationStop(SmartComponent component) { base.OnSimulationStop(component); egmPositionGuidance.Stop(); egmLineSensor.Stop(); egmPositionGuidance = null; egmLineSensor = null; monitor = null; }
public void StartUdpThread(IEgmMonitor monitor) { //Debug.WriteLine($"Thread on port: {portNbr} started."); seqNbr = 0; int sleepTime = sleepTimeDefault; int timeoutCounter = 0; UdpClient udpClient = new UdpClient(portNbr); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, portNbr); while (!exitThread) { byte[] data = null; try { if (udpClient.Available > 0) { //Debug.WriteLine($"Thread on port: {portNbr} got data."); sleepTime = 0; data = udpClient.Receive(ref remoteEP); } else { sleepTime = sleepTimeDefault; } } catch (Exception e) { Debug.WriteLine(e.StackTrace); Stop(); } if (data != null) { //ProcessData(udpClient, remoteEP, data, monitor); monitor.Write(portNbr, data); timeoutCounter = 0; seqNbr++; // Send the message byte[] datagram = monitor.Read(portNbr); if (datagram != null) { var byteSent = udpClient.SendAsync(datagram, datagram.Length, remoteEP); } } else if (seqNbr != 0 && timeoutCounter > timeout) { Stop(); } Thread.Sleep(sleepTime); sleepTime = sleepTimeDefault; timeoutCounter++; } }
public override void OnSimulationStart(SmartComponent component) { base.OnSimulationStart(component); if (monitor != null) { egmPositionGuidance.Stop(); egmLineSensor.Stop(); egmPositionGuidance = null; egmLineSensor = null; monitor = null; } monitor = new DemoEgmMonitor(); egmPositionGuidance = new EgmUdpThread((int)DemoEgmPortNumbers.POS_GUIDE_PORT, 4, 50); egmLineSensor = new EgmUdpThread((int)DemoEgmPortNumbers.LINE_SENSOR_PORT, 4, 50); egmPositionGuidance.StartUdp(monitor); egmLineSensor.StartUdp(monitor); }
public void StartUdp(IEgmMonitor monitor) { exitThread = false; thread = new Thread(() => StartUdpThread(monitor)); thread.Start(); }