/// <summary> /// The handle message. /// </summary> /// <param name="CommandId"> /// The command id. /// </param> /// <param name="DataType"> /// The data type. /// </param> /// <param name="PayloadSize"> /// The payload size. /// </param> /// <param name="DataCount"> /// The data count. /// </param> /// <param name="Parameter1"> /// The parameter 1. /// </param> /// <param name="Parameter2"> /// The parameter 2. /// </param> /// <param name="header"> /// The header. /// </param> /// <param name="payload"> /// The payload. /// </param> /// <param name="iep"> /// The iep. /// </param> protected override void HandleMessage( ushort CommandId, ushort DataType, ref uint PayloadSize, ref uint DataCount, ref uint Parameter1, ref uint Parameter2, ref byte[] header, ref byte[] payload, ref EndPoint iep) { switch (CommandId) { // Got Back Value for Get case CommandID.CA_PROTO_READ_NOTIFY: if (DataCount == 0) { this.client.cidChannels[(int)Parameter2].LastValue = null; } else if (DataCount == 1) { this.client.cidChannels[(int)Parameter2].LastValue = NetworkByteConverter.byteToObject( payload, (EpicsType)DataType); } else { this.client.cidChannels[(int)Parameter2].LastValue = NetworkByteConverter.byteToObject( payload, (EpicsType)DataType, (int)DataCount); } break; // Got Status Back for Put case CommandID.CA_PROTO_WRITE_NOTIFY: if (this.client.cidChannels.ContainsKey((int)Parameter2)) { this.client.cidChannels[(int)Parameter2].writeSucceeded(); } break; // Did receive a Monitor Signal case CommandID.CA_PROTO_EVENT_ADD: if (DataCount == 0) { this.client.cidChannels[(int)Parameter2].receiveValueUpdate(null); } else if (DataCount == 1) { this.client.cidChannels[(int)Parameter2].receiveValueUpdate( NetworkByteConverter.byteToObject(payload, (EpicsType)DataType)); } else { this.client.cidChannels[(int)Parameter2].receiveValueUpdate( NetworkByteConverter.byteToObject(payload, (EpicsType)DataType, (int)DataCount)); } break; // Got information about Access Rights case CommandID.CA_PROTO_ACCESS_RIGHTS: this.client.cidChannels[(int)Parameter1].AccessRight = (AccessRights)Parameter2; break; // Could register a Channel on the IOC case CommandID.CA_PROTO_CREATE_CHAN: try { this.tmpChan = this.client.cidChannels[(int)Parameter1]; this.tmpChan.ChannelEpicsType = (EpicsType)DataType; this.tmpChan.ChannelDefinedType = CETypeTranslator[(EpicsType)DataType]; this.tmpChan.ChannelDataCount = DataCount; if (this.tmpChan.MonitorDataCount == 0) { this.tmpChan.MonitorDataCount = DataCount; } this.tmpChan.SID = Parameter2; } catch (Exception e) { } break; // failed to created a Channel. case CommandID.CA_PROTO_CREATE_CH_FAIL: this.tmpChan = this.client.cidChannels[(int)Parameter1]; this.tmpChan.Conn = null; break; case CommandID.CA_PROTO_SERVER_DISCONN: this.client.cidChannels[(int)Parameter1].conn_ConnectionStateChanged(false); break; case CommandID.CA_PROTO_SEARCH: // if a channel is disposed it will fail here. try { var riep = new IPEndPoint(((IPEndPoint)iep).Address, DataType); this.client.cidChannels[(int)Parameter2].Conn = this.client.GetServerConnection(riep); } catch (Exception e) { this.client.ExceptionContainer.Add(new Exception("MINOR: FOUND CHANNEL WHICH ALREADY IS DISPOSED")); } break; case CommandID.CA_PROTO_RSRV_IS_UP: if (this.client.beaconCollection.ContainsKey(iep.ToString())) { lock (this.client.beaconCollection) { this.client.beaconCollection[iep.ToString()] = DateTime.Now; } } else { this.client.addIocBeaconed(iep); } break; case CommandID.CA_PROTO_VERSION: case CommandID.CA_PROTO_ECHO: case CommandID.CA_PROTO_CLEAR_CHANNEL: if (PayloadSize > 0) { this.client.ExceptionContainer.Add( new Exception("MESSAGE WITHOUT PAYLOAD, REQUESTED PAYLOAD. POSSIBLE MISSREADING!")); } break; case CommandID.CA_PROTO_ERROR: this.client.ExceptionContainer.Add( new Exception("EPICS-ERROR: " + Parameter2 + " - " + NetworkByteConverter.ToString(payload, 16))); break; default: this.client.ExceptionContainer.Add(new Exception("NETWORK MISS READING - DROP WHOLE PACKAGE!")); return; } }
/// <summary> /// The put value. /// </summary> /// <param name="ioId"> /// The io id. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="payload"> /// The payload. /// </param> internal void putValue(int ioId, EpicsType type, int dataCount, byte[] payload) { try { object val; if (dataCount == 1) { val = NetworkByteConverter.byteToObject(payload, type); } else { val = NetworkByteConverter.byteToObject(payload, type, dataCount); } if (this.Property == RecordProperty.VAL) { if (dataCount == 1) { this.Record["VAL"] = Convert.ChangeType(val, this.Record.GetValueType()); } else { switch (this.Record.type) { case EpicsType.String: ((EpicsArray <string>) this.Record["VAL"]).Set(val); break; case EpicsType.Double: ((EpicsArray <double>) this.Record["VAL"]).Set(val); break; case EpicsType.Float: ((EpicsArray <float>) this.Record["VAL"]).Set(val); break; case EpicsType.Int: ((EpicsArray <int>) this.Record["VAL"]).Set(val); break; case EpicsType.Short: ((EpicsArray <short>) this.Record["VAL"]).Set(val); break; case EpicsType.SByte: ((EpicsArray <sbyte>) this.Record["VAL"]).Set(val); break; } } } else { this.Record[this.Property.ToString()] = Convert.ChangeType(val, this.Record[this.Property.ToString()].GetType()); } this.Conn.Send( this.Server.Codec.channelWroteMessage(this.ClientId, ioId, type, dataCount, EpicsTransitionStatus.ECA_NORMAL)); } catch (Exception exp) { this.Conn.Send( this.Server.Codec.errorMessage( this.ClientId, EpicsTransitionStatus.ECA_BADSTR, "Message was not correct", new byte[16])); return; } }