void channel_MonitorChanged(EpicsChannel sender, object newValue) { if (ChannelUpdated != null) { ChannelUpdated(sender.ChannelName, newValue.ToString()); } }
void ChannelMonitorChanged(EpicsChannel<string> sender, string newValue) { this.Dispatcher.BeginInvoke((Action)delegate { channelDisplay.First(row => sender.ChannelName.EndsWith(row.Key)).Value.Text = newValue; }); }
internal ClientChannel(EpicsChannel <T> channel) { this.channel = channel; // ToDo: this.value = this.channel.Get(); // This is used to get the initial value from the channel this.channel.MonitorChanged += (sender, newValue) => { var oldValue = this.value; this.value = newValue; if (this.EvaluateFilters(newValue, oldValue)) { // Make sure that all the updates occur on the UI thread this.asyncOperation.Post( state => { // Update listeners through this.Changed if (this.Changed != null) { this.Changed(newValue); } // Update UI through INotifyPropertyChanged if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs("Value")); } }, null); } }; }
internal void Add(EpicsChannel channel) { lock (toSearch) { channel.SearchInvervalCounter = channel.SearchInverval = 1; if (!toSearch.Contains(channel)) toSearch.Add(channel); } }
internal void AddChannel(EpicsChannel channel) { lock (ConnectedChannels) { if (!ConnectedChannels.Contains(channel)) { ConnectedChannels.Add(channel); } } }
async Task ConnectAsync(string channelName) { lock (knownChannels) { if (knownChannelsLastUsage.ContainsKey(channelName)) { knownChannelsLastUsage.Remove(channelName); } } bool shouldCheck = true; EpicsChannel c = null; lock (knownChannels) { shouldCheck = !knownChannels.ContainsKey(channelName); } if (shouldCheck) { c = epicsClient.CreateChannel(channelName); await c.ConnectAsync(); } lock (knownChannels) { if (!knownChannels.ContainsKey(channelName) && c != null) { if (c.ChannelDefinedType != null && c.ChannelDefinedType.Name == "Enum") { knownChannels.Add(channelName, epicsClient.CreateChannel <int>(channelName)); if (!knownChannelsEnum.ContainsKey(channelName)) { var t = epicsClient.CreateChannel <ExtControlEnum>(channelName); var v = t.Get(); knownChannelsEnum.Add(channelName, v.States); } } else { knownChannels.Add(channelName, c); } knownChannelsUsage.Add(channelName, 0); } if (knownChannelsEnum.ContainsKey(channelName)) { if (ChannelEnumStates != null) { ChannelEnumStates(channelName, knownChannelsEnum[channelName]); } } knownChannels[channelName].MonitorChanged += channel_MonitorChanged; knownChannelsUsage[channelName]++; subscribedChannels.Add(knownChannels[channelName]); } }
internal void RemoveChannel(EpicsChannel channel) { lock (ConnectedChannels) { ConnectedChannels.Remove(channel); } lock (Client.Channels) { if (!Client.Channels.Any(row => row.Value.ChannelName == channel.ChannelName)) { ChannelSID.Remove(channel.ChannelName); } } }
static void screen_MonitorChanged(EpicsChannel<sbyte[]> sender, sbyte[] newValue) { Console.Clear(); for (int y = 0; y < 99; y++) { List<Byte> bytes = new List<byte>(); for (int x = 0; x < 200; x++) { if (newValue[x + y * 200] == 0) break; bytes.Add((byte)newValue[x + y * 200]); } string line = Encoding.ASCII.GetString(bytes.ToArray()); Console.CursorLeft = 0; Console.CursorTop = y; Console.Write(line); } }
static void Main(string[] args) { EpicsClient client = new EpicsClient(); client.Configuration.SearchAddress = "129.129.130.87:5432"; channel = client.CreateChannel<string>("ADG1:IST1:2"); channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged); channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged); while (true) { switch (Console.ReadKey().KeyChar) { case (char)27: return; case (char)13: if (channel == null) { channel = client.CreateChannel<string>("ADG1:IST1:2"); channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged); channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged); } else { channel.Dispose(); channel = null; } break; case ' ': monitored = !monitored; if (monitored) channel.MonitorChanged += new EpicsDelegate<string>(channel_MonitorChanged); else channel.MonitorChanged -= new EpicsDelegate<string>(channel_MonitorChanged); break; default: break; } } }
internal abstract void Decode(EpicsChannel channel, uint nbElements);
static void Channel_MonitorChanged(EpicsChannel<string> sender, string newValue) { nbEvents++; }
static void Channel_MonitorChangedExtObject(EpicsChannel<PSI.EpicsClient2.ExtControl<string>> sender, PSI.EpicsClient2.ExtControl<string> newValue) { nbEvents++; }
static void Program_MonitorChanged(EpicsChannel sender, object newValue) { Console.WriteLine("CID: " + sender.CID + ", SID: " + sender.SID + ", Value: " + newValue.ToString()); }
static void channel_MonitorChanged(EpicsChannel<string> sender, string newValue) { Console.WriteLine("Value: " + newValue); gotMonitorValue.Set(); }
//static void gotValueNotified(EpicsChannel sender, object newValue) static void gotValueNotified(EpicsChannel<ExtControl<string>> sender, ExtControl<string> newValue) { //gotValue.Set(); }
static void intChan_MonitorChanged(EpicsChannel<int> sender, int newValue) { Console.WriteLine("New val: " + newValue); }
static void ch_MonitorChangedGotValue(EpicsChannel<ExtGraphic<string>> sender, ExtGraphic<string> newValue) { lock (hadValue) { if (!hadValue.ContainsKey(sender.ChannelName)) { multiActionCountDown.Signal(); hadValue.Add(sender.ChannelName, true); } } }
static void ch_StatusChanged(EpicsChannel sender, ChannelStatus newStatus) { Console.WriteLine(sender.ChannelName + ": " + newStatus); }
static void ca2_MonitorChanged(EpicsChannel sender, object newValue) { Console.WriteLine("Ca2: " + newValue); }
static void Channel_MonitorChangedObject(EpicsChannel sender, object newValue) { nbEvents++; }
static void i_StatusChanged(EpicsChannel sender, ChannelStatus newStatus) { if(newStatus == ChannelStatus.DISCONNECTED && previousState != newStatus) Console.WriteLine("\nClosed!"); previousState = newStatus; }
static void channel_MonitorChanged(EpicsChannel <string> sender, string newValue) { Console.WriteLine("Value: " + newValue); gotMonitorValue.Set(); }
public override void ProcessData(DataPacket packet) { lock (lockObject) { switch ((CommandID)packet.Command) { case CommandID.CA_PROTO_VERSION: break; case CommandID.CA_PROTO_ECHO: // We sent the echo... we should therefore avoid to answer it if (Pipe.GeneratedEcho) { Pipe.GeneratedEcho = false; } else { // Send back the echo ((TcpReceiver)Pipe[0]).Send(packet); } break; case CommandID.CA_PROTO_SEARCH: { int port = packet.DataType; //Console.WriteLine("Answer from: " + packet.Sender.Address + ":" + port); EpicsChannel channel = Client.GetChannelByCid(packet.Parameter2); if (channel == null) { return; } IPAddress addr = packet.Sender.Address; if (packet.Parameter1 != 0xFFFFFFFF) { addr = IPAddress.Parse("" + packet.Data[8] + "." + packet.Data[8 + 1] + "." + packet.Data[8 + 2] + "." + packet.Data[8 + 3]); } channel.SearchAnswerFrom = packet.Sender.Address; if (Client.Configuration.DebugTiming) { lock (channel.ElapsedTimings) { if (!channel.ElapsedTimings.ContainsKey("SearchResponse")) { channel.ElapsedTimings.Add("SearchResponse", channel.Stopwatch.Elapsed); } } } if (channel != null) { try { channel.SetIoc(Client.GetIocConnection(new IPEndPoint(addr, port))); } catch { } } } break; case CommandID.CA_PROTO_ACCESS_RIGHTS: { EpicsChannel channel = Client.GetChannelByCid(packet.Parameter1); if (channel != null) { channel.AccessRight = (AccessRights)((ushort)packet.Parameter2); } break; } case CommandID.CA_PROTO_CREATE_CHAN: { EpicsChannel channel = Client.GetChannelByCid(packet.Parameter1); if (channel != null) { channel.SetServerChannel(packet.Parameter2, (EpicsType)packet.DataType, packet.DataCount); } break; } case CommandID.CA_PROTO_READ_NOTIFY: { TcpReceiver ioc = (TcpReceiver)Pipe[0]; EpicsChannel channel; lock (ioc.PendingIo) { channel = ioc.PendingIo[packet.Parameter2]; } if (channel != null) { channel.SetGetRawValue(packet); } break; } case CommandID.CA_PROTO_WRITE_NOTIFY: { TcpReceiver ioc = (TcpReceiver)Pipe[0]; EpicsChannel channel; lock (ioc.PendingIo) { channel = ioc.PendingIo[packet.Parameter2]; } if (channel != null) { channel.SetWriteNotify(); } break; } case CommandID.CA_PROTO_EVENT_ADD: { EpicsChannel channel = Client.GetChannelByCid(packet.Parameter2); if (channel != null) { channel.UpdateMonitor(packet); } break; } case CommandID.CA_PROTO_SERVER_DISCONN: { List <EpicsChannel> connectedChannels; TcpReceiver receiver = ((TcpReceiver)Pipe[0]); lock (receiver.ConnectedChannels) { connectedChannels = receiver.ConnectedChannels.Where(row => row.CID == packet.Parameter1).ToList(); } foreach (EpicsChannel channel in connectedChannels) { lock (receiver.ChannelSID) { receiver.ChannelSID.Remove(channel.ChannelName); } channel.Disconnect(); } } break; default: break; } } }
static void Check2() { EpicsChannel[] channels = new EpicsChannel[intRecords.Length]; for (int i = 0; i < channels.Length; i++) channels[i] = client.CreateChannel("PCT:INT-" + i); client.MultiConnect(channels); Dictionary<uint, string> sids = new Dictionary<uint, string>(); Console.WriteLine("Connecting...."); client.MultiConnect(channels); Console.WriteLine("Done..."); foreach (EpicsChannel c in channels) { if (sids.ContainsKey(c.SID) && sids[c.SID] != c.ChannelName) { Console.WriteLine("Reuse: " + c.SID); } else if (!sids.ContainsKey(c.SID)) sids.Add(c.SID, c.ChannelName); } for (int k = 0; k < 1000; k++) { List<EpicsChannel> myList = channels.Where(row => rnd.Next(0, 2) == 0).ToList(); object[] res = client.MultiGet<int>(myList); int nbEmpty = 0; int nbFaults = 0; for (int i = 0; i < myList.Count; i++) { if (res[i] == null) nbEmpty++; else { int v = (int)res[i]; int id = int.Parse(myList[i].ChannelName.Split('-')[1]); if (id != v / 1000) nbFaults++; } } Console.WriteLine("Empty: " + nbEmpty + ", Faults: " + nbFaults + ", Asked: " + myList.Count); Thread.Sleep(rnd.Next(10, 100)); } client.Dispose(); }
internal void RemoveChannel(EpicsChannel channel) { lock (ConnectedChannels) { ConnectedChannels.Remove(channel); } lock(Client.Channels) { if (!Client.Channels.Any(row => row.Value.ChannelName == channel.ChannelName)) ChannelSID.Remove(channel.ChannelName); } }
static void ch_MonitorChangedView(EpicsChannel<ExtGraphic<string>> sender, ExtGraphic<string> newValue) { Console.WriteLine(newValue.Value); }
internal void AddChannel(EpicsChannel channel) { lock (ConnectedChannels) { if (!ConnectedChannels.Contains(channel)) ConnectedChannels.Add(channel); } }
static void c_StatusChanged(EpicsChannel sender, ChannelStatus newStatus) { if (newStatus == ChannelStatus.DISCONNECTED) { gotDisconnect.Set(); needToStop = true; } }
internal void RemoveChannel(EpicsChannel channel) { lock (ConnectedChannels) { ConnectedChannels.Remove(channel); } }
static void IntChannelStatusChanged(EpicsChannel sender, ChannelStatus newStatus) { Console.WriteLine("Channel status changed: " + newStatus); }
static void Main(string[] args) { using (EpicsClient client = new EpicsClient()) { client.Configuration.SearchAddress="129.129.130.87:6789"; if (args.Length > 0 && args[0] == "-m") { //Console.WriteLine("Running monitor mode"); EpicsChannel<string>[] channels = new EpicsChannel<string>[100]; for (int j = 0; j < channels.Length; j++) { channels[j] = client.CreateChannel<string>("STRESS:INT:" + j / 2); channels[j].MonitorChanged += new EpicsDelegate<string>(Program_MonitorChanged); } Thread.Sleep(5000); int nbNotConnected = 0; for (int j = 0; j < channels.Length; j++) { if (channels[j].Status != ChannelStatus.CONNECTED) nbNotConnected++; } if (nbNotConnected > 0) { Console.WriteLine("Channels not connected: " + nbNotConnected); Console.Beep(); Thread.Sleep(10000); } for (int j = 0; j < channels.Length; j++) { channels[j].Dispose(); } } else { for (int i = 0; i < 10; i++) { //Console.WriteLine("Create channel"); EpicsChannel<string> channel = client.CreateChannel<string>("STRESS:INT"); channel.StatusChanged += new EpicsStatusDelegate(channel_StatusChanged); try { //Console.WriteLine("Get"); for (int j = 0; j < 10; j++) { string val = channel.Get(); if (val != "1234") Console.WriteLine("Wrong value!"); //Console.WriteLine("Got " + val); } } catch { Console.WriteLine("Didn't got back!"); //Console.Beep(); } channel.Dispose(); Thread.Sleep(10); } //Console.WriteLine("Disposed"); } } }
static void MultiConnect() { EpicsChannel[] channels = new EpicsChannel[intRecords.Length]; for (int i = 0; i < channels.Length; i++) channels[i] = client.CreateChannel("PCT:INT-" + i); client.MultiConnect(channels); client.Dispose(); client = new EpicsClient(); client.Configuration.SearchAddress = "127.0.0.1:5555"; for (int i = 0; i < channels.Length; i++) channels[i] = client.CreateChannel("PCT:INT-" + i); client.MultiConnect(channels); Console.WriteLine("Done..."); Dictionary<uint, string> sids = new Dictionary<uint, string>(); foreach (EpicsChannel c in channels) { if (sids.ContainsKey(c.SID) && sids[c.SID] != c.ChannelName) { Console.WriteLine("Reuse: " + c.SID); } else if (!sids.ContainsKey(c.SID)) sids.Add(c.SID, c.ChannelName); } client.Dispose(); }
internal ClientChannel(EpicsChannel <T> channel, T initialValue) : this(channel) { this.value = initialValue; }
static void QuickMonitor(EpicsChannel<ExtGraphic<string>> sender, ExtGraphic<string> newValue) { /*if (needToShow) Console.WriteLine(sender.ChannelName + ": " + newValue);*/ }
internal void Remove(EpicsChannel channel) { lock (toSearch) toSearch.Remove(channel); }
static void channel_StatusChanged(EpicsChannel sender, ChannelStatus newStatus) { //Console.WriteLine("Status: " + newStatus.ToString()); }
static void Main(string[] args) { int nbRepeat = 1; if (args.Any(row => row == "-r")) { for (int i = 0; i < args.Length; i++) { if (args[i] == "-r") { i++; nbRepeat = int.Parse(args[i]); } } } for (int r = 0; r < nbRepeat || nbRepeat == 0;) { if (nbRepeat > 0) { r++; } if (r != 0 || nbRepeat == 0) { Console.WriteLine("-------------------------------------------"); Console.WriteLine("-------------------------------------------"); Thread.Sleep(100); } using (EpicsClient client = new EpicsClient()) { client.Configuration.WaitTimeout = 10000; string channelName = ""; bool usingMonitor = false; for (int i = 0; i < args.Length; i++) { if (args[i] == "-e") { i++; client.Configuration.SearchAddress = args[i]; } else if (args[i] == "-m") { usingMonitor = true; } else { channelName = args[i]; } } client.Configuration.DebugTiming = true; Console.WriteLine("EPICS Configuration: " + client.Configuration.SearchAddress); Console.WriteLine("Trying to read " + channelName); EpicsChannel <string> channel = client.CreateChannel <string>(channelName); bool hasError = false; if (usingMonitor) { Console.WriteLine("Monitor and wait for the first value back."); channel.MonitorChanged += new EpicsDelegate <string>(channel_MonitorChanged); try { gotMonitorValue.WaitOne(5000); } catch { hasError = true; } } else { Console.WriteLine("Get and waits the value back."); try { Console.WriteLine(channel.Get()); } catch (Exception ex) { hasError = true; Console.WriteLine(ex); } } Console.WriteLine(channel.Status.ToString()); TimeSpan?prevTime = null; foreach (var i in channel.ElapsedTimings) { if (!prevTime.HasValue) { Console.WriteLine(i.Key + ": " + i.Value.ToString()); } else { Console.WriteLine(i.Key + ": " + (i.Value - prevTime).ToString()); } prevTime = i.Value; } Console.WriteLine("Total: " + prevTime.ToString()); Console.WriteLine("Search answered by " + channel.SearchAnswerFrom); Console.WriteLine("IOC: " + channel.IOC); Console.WriteLine("EPICS Type: " + channel.ChannelDefinedType); if (channel.Status != ChannelStatus.CONNECTED || hasError) { Console.Beep(); } } } }
static void Program_MonitorChanged(EpicsChannel<string> sender, string newValue) { //Console.WriteLine(newValue); }
internal bool Contains(EpicsChannel channel) { lock (toSearch) return toSearch.Contains(channel); }