internal CAChannelMonitor(CARecord record, string property, CAServerChannel channel, EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId) { Record = record; Property = property; Channel = channel; Type = type; DataCount = dataCount; MonitorMask = monitorMask; SubscriptionId = subscriptionId; try { object val = Record[Property.ToString()]; if (val == null) val = 0; byte[] realData = val.ToByteArray(Type, Record); Channel.TcpConnection.Send(Channel.Server.Filter.MonitorChangeMessage(SubscriptionId, Channel.ClientId, Type, DataCount, val.ToByteArray(Type, Record))); lastValue = Record[Property]; Record.RecordProcessed += new EventHandler(Record_RecordProcessed); } catch (Exception e) { Channel.TcpConnection.Send(Channel.Server.Filter.MonitorChangeMessage(SubscriptionId, Channel.ClientId, Type, DataCount, new byte[0])); } }
/// <summary> /// The create subscription message. /// </summary> /// <param name="SID"> /// The sid. /// </param> /// <param name="SubscriptionID"> /// The subscription id. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="mask"> /// The mask. /// </param> /// <returns> /// </returns> internal byte[] createSubscriptionMessage( uint SID, uint SubscriptionID, Type type, ushort dataCount, MonitorMask mask) { if (type.IsArray) { if (CTypeTranslator.ContainsKey(type.GetElementType())) { return(this.createSubscriptionMessage(SID, SubscriptionID, CTypeTranslator[type.GetElementType()], dataCount, mask)); } else { this.client.ExceptionContainer.Add(new Exception("Requested datatype which is not accepted by Epics")); return(this.createSubscriptionMessage(SID, SubscriptionID, EpicsType.String, dataCount, mask)); } } else if (CTypeTranslator.ContainsKey(type)) { return(this.createSubscriptionMessage(SID, SubscriptionID, CTypeTranslator[type], dataCount, mask)); } else { this.client.ExceptionContainer.Add(new Exception("Requested datatype which is not accepted by Epics")); return(this.createSubscriptionMessage(SID, SubscriptionID, EpicsType.String, dataCount, mask)); } }
internal ChannelMonitor(CARecord record, string property, CAServerChannel channel, EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId) { Record = record; Property = property; Channel = channel; Type = type; DataCount = dataCount; MonitorMask = monitorMask; SubscriptionId = subscriptionId; try { object val = Record[Property.ToString()]; if (val == null) val = 0; byte[] realData = val.ToByteArray(Type, Record); Channel.sendMonitorChange(SubscriptionId, Type, DataCount, EpicsTransitionStatus.ECA_NORMAL, realData); lastValue = Record[Property]; Record.RecordProcessed += new EventHandler(Record_RecordProcessed); } catch (Exception e) { Channel.sendMonitorChange(SubscriptionId, Type, DataCount, EpicsTransitionStatus.ECA_ADDFAIL, new byte[0]); } }
internal CAChannelMonitor(CARecord record, string property, CAServerChannel channel, EpicsType type, int dataCount, MonitorMask monitorMask, int subscriptionId) { Record = record; Property = property; Channel = channel; Type = type; DataCount = dataCount; MonitorMask = monitorMask; SubscriptionId = subscriptionId; try { object val = Record[Property.ToString()]; if (val == null) { val = 0; } byte[] realData = val.ToByteArray(Type, Record); using (Record.CreateAtomicChange(false)) Channel.TcpConnection.Send(Channel.Server.Filter.MonitorChangeMessage(SubscriptionId, Channel.ClientId, Type, DataCount, val.ToByteArray(Type, Record))); Record.RecordProcessed += new EventHandler(Record_RecordProcessed); } catch (Exception e) { Channel.TcpConnection.Send(Channel.Server.Filter.MonitorChangeMessage(SubscriptionId, Channel.ClientId, Type, DataCount, new byte[0])); } }
internal void AddMonitor(EpicsType type, int dataCount, int subscriptionId, MonitorMask mask) { //does he request to add a subscriptionId at the same Id as it already exist? lock (monitors) { if (monitors.ContainsKey(subscriptionId)) { return; } monitors.Add(subscriptionId, new CAChannelMonitor(Record, Property, this, type, dataCount, mask, subscriptionId)); } }
/// <summary> /// The add monitor. /// </summary> /// <param name="type"> /// The type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="subscriptionId"> /// The subscription id. /// </param> /// <param name="mask"> /// The mask. /// </param> internal void addMonitor(EpicsType type, int dataCount, int subscriptionId, MonitorMask mask) { // does he request to add a subscriptionId at the same Id as it already exist? if (this.monitors.ContainsKey(subscriptionId)) { return; } lock (this.monitors) { this.monitors.Add( subscriptionId, new EpicsServerMonitor(this.Record, this.Property, this, type, dataCount, mask, subscriptionId)); } }
/// <summary> /// The create subscription message. /// </summary> /// <param name="SID"> /// The sid. /// </param> /// <param name="SubscriptionID"> /// The subscription id. /// </param> /// <param name="type"> /// The type. /// </param> /// <param name="dataCount"> /// The data count. /// </param> /// <param name="mask"> /// The mask. /// </param> /// <returns> /// </returns> internal byte[] createSubscriptionMessage( uint SID, uint SubscriptionID, EpicsType type, ushort dataCount, MonitorMask mask) { var mem = new MemoryStream(); var writer = new BinaryWriter(mem); mem.Capacity = 32; writer.Write(NetworkByteConverter.ToByteArray(CommandID.CA_PROTO_EVENT_ADD)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)16)); writer.Write(NetworkByteConverter.ToByteArray((UInt16)type)); writer.Write(NetworkByteConverter.ToByteArray(dataCount)); writer.Write(NetworkByteConverter.ToByteArray(SID)); writer.Write(NetworkByteConverter.ToByteArray(SubscriptionID)); writer.Write(new byte[12]); writer.Write(NetworkByteConverter.ToByteArray((UInt16)mask)); var buffer = mem.GetBuffer(); writer.Close(); mem.Dispose(); return(buffer); }
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]); } }
internal void RegisterEvent(CAServer server, uint sid, uint subscriptionId, int nbElements, EpicsType type, MonitorMask mask) { CARecord record = ((ServerTcpReceiver)this.Pipe.FirstFilter).FindRecord(server, sid); string property = ((ServerTcpReceiver)this.Pipe.FirstFilter).FindProperty(server, sid); DataPacket response = DataPacketBuilder.Encode(type, record[property], record, (nbElements == 0) ? record.ElementsInRecord : Math.Min(nbElements, record.ElementsInRecord)); response.Command = (ushort)CommandID.CA_PROTO_EVENT_ADD; response.Parameter1 = 1; response.Parameter2 = (uint)subscriptionId; ((TcpReceiver)this.Pipe.FirstFilter).Send(response); var lastStatus = record.AlarmStatus; EventHandler newEvent = delegate(object obj, EventArgs evt) { if (!record.IsDirty) { return; } // We have a alarm mask, if the status didn't change, don't send the event if (mask == MonitorMask.ALARM && lastStatus == record.AlarmStatus) { return; } lastStatus = record.AlarmStatus; DataPacket p = DataPacketBuilder.Encode(type, record[property], record, (nbElements == 0) ? record.ElementsInRecord : Math.Min(nbElements, record.ElementsInRecord)); p.Command = (ushort)CommandID.CA_PROTO_EVENT_ADD; p.Parameter1 = 1; p.Parameter2 = (uint)subscriptionId; ((TcpReceiver)this.Pipe.FirstFilter).Send(p); }; record.RecordProcessed += newEvent; lock (subscribedEvents) { subscribedEvents.Add(subscriptionId, new EpicsEvent { Handler = newEvent, Record = record, DataCount = nbElements, EpicsType = type, SID = sid }); } }
internal void AddMonitor(EpicsType type, int dataCount, int subscriptionId, MonitorMask mask) { //does he request to add a subscriptionId at the same Id as it already exist? lock (monitors) { if (monitors.ContainsKey(subscriptionId)) return; monitors.Add(subscriptionId, new CAChannelMonitor(Record, Property, this, type, dataCount, mask, subscriptionId)); } }