//--------------------------------------------------------------------------- /// <summary> /// Конструктор для десериализатора /// </summary> /// <param name="info"></param> /// <param name="context"></param> public DeviceOld(SerializationInfo info, StreamingContext context) { this._replyToRequest = new ProcessTheRequest(this.RequestParse); this._onReplyTransmitted = new EventOnReplyTransmitted(this.OnReplyTransmitted); this._onError = new EventOnError(this.OnError); this._onRequstRecived = new EventOnRequstRecived(this.OnRequestRecived); this.Address = info.GetByte("Address"); this._dataMap = (DataSet)info.GetValue("DataMap", typeof(DataSet)); Object[] settings = (Object[])info.GetValue("ConnectionSettings", typeof(Object)); switch ((InterfaceType)info.GetValue("ConnectionType", typeof(InterfaceType))) { case InterfaceType.SerialPort: { if ((TransmissionMode)info.GetValue("Mode", typeof(TransmissionMode)) == TransmissionMode.RTU) { // Режим передачи RTU ComPort comport = new ComPort(this.Address, (String)settings[0], (int)settings[1], (System.IO.Ports.Parity)settings[3], (int)settings[2], (System.IO.Ports.StopBits)settings[4]); _connection = (IDataLinkLayer)comport; } else { // Режим передачи ASCII throw new NotImplementedException(); } break; } case InterfaceType.TCPIP: { throw new NotImplementedException(); } default: { throw new NotImplementedException(); } } if (_connection != null) { _connection.ErrorAccured += new EventHandlerErrorAccured(EventHandler_DataLinkObject_ErrorOccured); _connection.ReplyWasTransmitted += new EventHandleReplyTransmitted(EventHandler_DataLinkObject_ReplyTransmited); _connection.RequestRecived += new EventHandlerRequestRecived(EventHandler_DataLinkObject_RequestRecived); } }
//--------------------------------------------------------------------------- /// <summary> /// Конструктор /// </summary> /// <param name="address">Сетевой адрес устройства</param> /// <param name="connection">Объект физического порта подключения</param> public DeviceOld(Byte address, IDataLinkLayer connection) { this.Address = address; this._replyToRequest = new ProcessTheRequest(this.RequestParse); this._onReplyTransmitted = new EventOnReplyTransmitted(this.OnReplyTransmitted); this._onError = new EventOnError(this.OnError); this._onRequstRecived = new EventOnRequstRecived(this.OnRequestRecived); this.InitDataMap(); this._connection = connection; if (_connection != null) { _connection.ErrorAccured += new EventHandlerErrorAccured(EventHandler_DataLinkObject_ErrorOccured); _connection.ReplyWasTransmitted += new EventHandleReplyTransmitted(EventHandler_DataLinkObject_ReplyTransmited); _connection.RequestRecived += new EventHandlerRequestRecived(EventHandler_DataLinkObject_RequestRecived); } }