/// <summary> /// Creates a new generic <see cref="EpicsChannel"/>, even if the channel already exists.<br/> /// The Channel is at the Moment it's given back still in creation. So if the Channel doesn't exist will not be checked.<br/> /// Further the Channel will be created to serve the requested <typeparamref name="DataType"/>. /// </summary> /// <typeparam name="DataType"> /// </typeparam> /// <param name="ChannelName"> /// Name of the Channel. /// </param> /// <returns> /// !new! generic <see cref="EpicsChannel"/> /// </returns> public EpicsChannel <DataType> CreateChannel <DataType>(string ChannelName) { var Channel = new EpicsChannel <DataType>(ChannelName.Trim(), ++CIDCounter, this); lock (this.cidChannels) { this.cidChannels.Add((int)Channel.CID, Channel); } this.SearchChannel((int)Channel.CID, ChannelName); return(Channel); }
/// <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; } }