/// <summary> /// Listens to the shared connection for incoming data. /// </summary> protected void ListenSharedConn() { IncomingRequestArgs requestArgs = new IncomingRequestArgs(); byte[] buffer = new byte[InBufferLenght]; while (!terminated) { try { lock (sharedConn) { if (sharedConn.Connected && sharedConn.TcpClient.Available > 0 && !ReceiveIncomingRequest(LineContext.SelectDevices(), sharedConn, requestArgs)) { sharedConn.ClearNetStream(buffer); } } Thread.Sleep(SlaveThreadDelay); } catch (Exception ex) { Log.WriteException(ex, Locale.IsRussian ? "Ошибка при приёме данных через общее соединение" : "Error receiving data over a shared connection"); Thread.Sleep(ScadaUtils.ThreadDelay); } } }
/// <summary> /// Listens to the individual connections for incoming data. /// </summary> protected void ListenIndividualConn() { IncomingRequestArgs requestArgs = new IncomingRequestArgs(); byte[] buffer = new byte[InBufferLenght]; while (!terminated) { try { foreach (TcpConnection conn in indivConnList) { lock (conn) { if (conn.Connected && conn.TcpClient.Available > 0 && !ReceiveIncomingRequest(conn.BoundDevices, conn, requestArgs)) { sharedConn.ClearNetStream(buffer); } } } Thread.Sleep(SlaveThreadDelay); } catch (Exception ex) { Log.WriteException(ex, Locale.IsRussian ? "Ошибка при приёме данных через индивидуальное соединение" : "Error receiving data over an individual connection"); Thread.Sleep(ScadaUtils.ThreadDelay); } } }
protected volatile bool terminated; // necessary to stop the thread /// <summary> /// Initializes a new instance of the class. /// </summary> public SerialChannelLogic(ILineContext lineContext, ChannelConfig channelConfig) : base(lineContext, channelConfig) { options = new SerialChannelOptions(channelConfig.CustomOptions); requestArgs = new IncomingRequestArgs(); serialConn = null; thread = null; terminated = false; }
protected volatile bool terminated; // necessary to stop receiving data /// <summary> /// Initializes a new instance of the class. /// </summary> public UdpChannelLogic(ILineContext lineContext, ChannelConfig channelConfig) : base(lineContext, channelConfig) { options = new UdpChannelOptions(channelConfig.CustomOptions); requestArgs = new IncomingRequestArgs(); deviceLock = new object(); masterConn = null; slaveConn = null; deviceDict = null; terminated = false; }
protected volatile bool terminated; // necessary to stop the thread /// <summary> /// Initializes a new instance of the class. /// </summary> public TcpServerChannel(ILineContext lineContext, ChannelConfig channelConfig) : base(lineContext, channelConfig) { options = new TcpServerChannelOptions(channelConfig.CustomOptions); requestArgs = new IncomingRequestArgs(); inBuf = new byte[InBufferLenght]; connList = new List <TcpConnection>(); tcpListener = null; currentConn = null; deviceDict = null; thread = null; terminated = false; }
/// <summary> /// Processes the incoming request just read for the specified device. /// </summary> protected bool ProcessIncomingRequest(DeviceLogic deviceLogic, byte[] buffer, int offset, int count, IncomingRequestArgs requestArgs) { try { deviceLogic.ProcessIncomingRequest(buffer, offset, count, requestArgs); return(!requestArgs.HasError); } catch (Exception ex) { Log.WriteException(ex, Locale.IsRussian ? "Ошибка при обработке входящего запроса КП {0}" : "Error processing incoming request for the device {0}", deviceLogic.Title); return(false); } }
/// <summary> /// Receives an unread incoming request for the specified device. /// </summary> protected bool ReceiveIncomingRequest(DeviceLogic deviceLogic, Connection conn, IncomingRequestArgs requestArgs) { try { deviceLogic.ReceiveIncomingRequest(conn, requestArgs); return(!requestArgs.HasError); } catch (Exception ex) { Log.WriteException(ex, Locale.IsRussian ? "Ошибка при приёме входящего запроса КП {0}" : "Error receiving incoming request for the device {0}", deviceLogic.Title); return(false); } }
/// <summary> /// Processes the incoming request just read for specified devices. /// </summary> protected bool ProcessIncomingRequest(IEnumerable <DeviceLogic> devices, byte[] buffer, int offset, int count, IncomingRequestArgs requestArgs) { requestArgs.SetToDefault(); foreach (DeviceLogic deviceLogic in devices) { ProcessIncomingRequest(deviceLogic, buffer, offset, count, requestArgs); if (!requestArgs.NextDevice) { break; } } return(!requestArgs.HasError); }
/// <summary> /// Receives an unread incoming request for specified devices. /// </summary> protected bool ReceiveIncomingRequest(IEnumerable <DeviceLogic> devices, Connection conn, IncomingRequestArgs requestArgs) { requestArgs.SetToDefault(); foreach (DeviceLogic deviceLogic in devices) { ReceiveIncomingRequest(deviceLogic, conn, requestArgs); if (!requestArgs.NextDevice) { break; } } return(!requestArgs.HasError); }