/// <summary> /// Initializes a new instance of the <see cref="EpicsServerChannel"/> class. /// </summary> /// <param name="server"> /// The server. /// </param> /// <param name="serverId"> /// The server id. /// </param> /// <param name="clientId"> /// The client id. /// </param> /// <param name="channelName"> /// The channel name. /// </param> /// <param name="conn"> /// The conn. /// </param> internal EpicsServerChannel( EpicsServer server, int serverId, int clientId, string channelName, EpicsServerTCPConnection conn) { this.NotDisposing = true; this.ServerId = serverId; this.ClientId = clientId; this.ChannelName = channelName; this.Server = server; this.Conn = conn; this.Conn.ConnectionStateChanged += this.Conn_ConnectionStateChanged; try { if (channelName.Contains(".")) { var splitted = channelName.Split('.'); this.Record = this.Server.recordList[splitted[0]]; this.Property = (RecordProperty)Enum.Parse(typeof(RecordProperty), splitted[1]); } else { this.Record = this.Server.recordList[this.ChannelName]; } this.Conn.Send( this.Server.Codec.channelCreatedMessage( this.ClientId, this.ServerId, this.Record.TYPE, this.Record.dataCount, this.Access)); } catch (Exception e) { this.Conn.Send(this.Server.Codec.channelCreationFailMessage(this.ClientId)); this.Dispose(); } }
private void RecordPropertyChanged(EpicsRecord sender, RecordProperty prop, object val, Setter setter) { if (prop == this.property) { var toUpdate = true; if (val is short || val is int || val is float || val is double) { var v = Convert.ToDouble(val); var l = Convert.ToDouble(this.lastValue); if (Math.Abs(v - l) > sender.MDEL) { this.lastValue = val; } else { toUpdate = false; } } else if (val is string) { if ((string)val == (string)this.lastValue) { toUpdate = false; } else { this.lastValue = val; } } else { if (val.ToString() == this.lastValue.ToString()) { toUpdate = false; } else { this.lastValue = val; } } if (toUpdate) { this.channel.sendMonitorChange( this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_NORMAL, NetworkByteConverter.objectToByte(val, this.type, this.record)); } } }
/// <summary> /// The set monitor. /// </summary> /// <param name="record"> /// The record. /// </param> /// <param name="scanInterval"> /// The scan interval. /// </param> internal void SetMonitor(EpicsRecord record, int scanInterval) { if (scanInterval == 0) { if (this.monitoredRecordList.ContainsKey(record)) { lock (this.monitoredRecordList) { this.monitoredRecordList.Remove(record); if (this.monitoredRecordList.Count == 0) { this.hasMonitors = false; } } } } else { lock (this.monitoredRecordList) { if (this.monitoredRecordList.ContainsKey(record)) { this.monitoredRecordList[record] = scanInterval; } else { this.monitoredRecordList.Add(record, scanInterval); if (this.monitoredRecordList.Count == 1) { this.hasMonitors = true; // prepare for calling the Monitors this.recordMonitorCaller = new Thread(this.HandleMonitors); this.recordMonitorCaller.IsBackground = true; this.recordMonitorCaller.Priority = ThreadPriority.Highest; this.recordMonitorCaller.Start(); // recordScanTriggerThread.Start(); } } } } }
/// <summary> /// Returns a EpicsRecord Simulation. Will reuse a already existing or if not existing create a new Record. /// </summary> /// <typeparam name="dataType"> /// Type of value the record serves (int,short,string,double,short) /// </typeparam> /// <param name="recordName"> /// Name of the Record /// </param> /// <returns> /// EpicsRecord for manipulation ready /// </returns> public EpicsRecord <dataType> GetEpicsRecord <dataType>(string recordName) { this.Init(); if (this.recordList.ContainsKey(recordName)) { if (this.recordList[recordName].GetValueType() != typeof(dataType)) { throw new Exception( "Record already exists as different DataType ('" + this.recordList[recordName].GetValueType() + "')"); } return((EpicsRecord <dataType>) this.recordList[recordName]); } else { var newRecord = new EpicsRecord <dataType>(recordName, this); this.recordList.Add(recordName, newRecord); return(newRecord); } }
internal EpicsServerMonitor( EpicsRecord record, RecordProperty property, EpicsServerChannel channel, EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId) { this.record = record; this.property = property; this.channel = channel; this.type = type; this.dataCount = dataCount; this.monitorMask = monitorMask; this.subscriptionId = subscriptionId; try { var val = this.record[this.property.ToString()]; if (val == null) { val = 0; } var realData = NetworkByteConverter.objectToByte(val, this.type, this.record); this.channel.sendMonitorChange( this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_NORMAL, realData); this.StartMonitor(); } catch (Exception e) { this.channel.sendMonitorChange( this.subscriptionId, this.type, this.dataCount, EpicsTransitionStatus.ECA_ADDFAIL, new byte[0]); } }