private static void Main(string[] args) { Stopwatch watch = new Stopwatch(); LinkUpUdpConnector serverToClient = new LinkUpUdpConnector(IPAddress.Parse("127.0.0.1"), IPAddress.Parse("127.0.0.1"), 1000, 2000); serverToClient.ReveivedPacket += ServerToClient_ReveivedPacket; LinkUpNode node = new LinkUpNode(); node.Name = "root"; node.AddSubNode(serverToClient); while (node.Labels.Count < 1) { } LinkUpPropertyLabel <int> val1 = node.Labels[0] as LinkUpPropertyLabel <int>; for (int i = 0; i < 100; i++) { watch.Restart(); int value = val1.Value; Console.WriteLine("GET {0}: {1} in {2} µs", val1.Name, value, watch.ElapsedTicks * 1000 * 1000 / Stopwatch.Frequency); Console.Read(); watch.Restart(); val1.Value = value * i; Console.WriteLine("SET {0}: {1} in {2} µs", val1.Name, value * i, watch.ElapsedTicks * 1000 * 1000 / Stopwatch.Frequency); Console.Read(); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); _Node.Name = "api"; _Node.AddSubNode(new LinkUpUdpConnector(IPAddress.Parse("127.0.0.1"), IPAddress.Parse("127.0.0.1"), 2000, 1000)); services.AddSingleton <IConnectorRepository>(new ConnectorRepository(_Node)); services.AddSingleton <INodeRepository>(new NodeRepository(_Node)); services.AddSingleton <ILabelRepository>(new LabelRepository(_Node)); }
private static void Main(string[] args) { watch = new Stopwatch(); watch.Start(); LinkUpNamedPipeConnector connector = new LinkUpNamedPipeConnector("linkup", LinkUpNamedPipeConnector.Mode.Server); connector.ReveivedPacket += Connector_ReveivedPacket; connector.SentPacket += Connector_SentPacket; LinkUpNode node = new LinkUpNode(); node.Name = "net45"; node.AddSubNode(connector); Thread.Sleep(5000); while (true) { Console.WriteLine("ENTER FOR GET"); Console.ReadLine(); foreach (LinkUpPropertyLabel <int> value in node.Labels.Where(c => c is LinkUpPropertyLabel <int>)) { try { Console.WriteLine(string.Format("{0}: {1}", value.Name, value.Value)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } Console.WriteLine("ENTER FOR SET"); Console.ReadLine(); foreach (LinkUpPropertyLabel <int> value in node.Labels.Where(c => c is LinkUpPropertyLabel <int>)) { try { value.Value = 100; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } } }
private static LinkUpNode CreateNode(LinkUpNode masterNode, string name) { LinkUpNode node = new LinkUpNode(); node.Name = name; BlockingCollection <byte[]> col1 = new BlockingCollection <byte[]>(); BlockingCollection <byte[]> col2 = new BlockingCollection <byte[]>(); LinkUpMemoryConnector slaveToMaster = new LinkUpMemoryConnector(col1, col2); LinkUpMemoryConnector masterToSlave = new LinkUpMemoryConnector(col2, col1); node.MasterConnector = slaveToMaster; masterNode.AddSubNode(masterToSlave); node.AddLabel <LinkUpPropertyLabel <int> >("val1"); node.AddLabel <LinkUpPropertyLabel <int> >("val2"); return(node); }
internal void UpdateSettings(bool connectionSettingsChanged) { SettingsUpdated(); if (connectionSettingsChanged) { if (Node != null) { Node.Dispose(); Node = null; } if (SettingViewModel.SelectedHost != null) { _Connector = new LinkUpTcpClientConnector(IPAddress.Parse(SettingViewModel.SelectedHost.IpAddress), SettingViewModel.SelectedHost.Port); _Connector.DebugDump = false; _Connector.ConnectivityChanged += Connector_ConnectivityChanged; _Connector.ConnectivityChanged += IOProxy.Connector_ConnectivityChanged; _Connector.MetricUpdate += Connector_MetricUpdate; Node = new LinkUpNode(); Node.Name = NodeName; Node.AddSubNode(Connector); IOProxy.Node = Node; IOProxy.UpdateLinkUpBindings(); } } _SettingContainer.Save(); if (Connector != null && Connector.ConnectivityState == LinkUpConnectivityState.Connected) { _IOProxy.UpdateSettings(); } }
private static void Main(string[] args) { using (LinkUpTcpClientConnector connector = new LinkUpTcpClientConnector(IPAddress.Parse("127.0.0.1"), 3000)) //using (LinkUpTcpClientConnector connector = new LinkUpTcpClientConnector(IPAddress.Parse("127.0.0.1"), 3000)) { connector.ReveivedPacket += ClientToServer_ReveivedPacket; connector.SentPacket += ClientToServer_SentPacket; connector.MetricUpdate += Connector_MetricUpdate; connector.ConnectivityChanged += Connector_ConnectivityChanged; node = new LinkUpNode(); node.Name = "leaf"; node.AddSubNode(connector); LinkUpEventLabel eventLabel = node.GetLabelByName <LinkUpEventLabel>("leaf/test/label_event"); func = node.GetLabelByName <LinkUpFunctionLabel>("leaf/test/label_function"); func.Return += Func_Return; eventLabel.Subscribe(); eventLabel.Fired += Program_Fired; Console.Read(); connector.Dispose(); } }
private static void Main(string[] args) { watch = new Stopwatch(); watch.Start(); if (!string.IsNullOrEmpty(DEBUG_PORT)) { Task.Run(() => { while (true) { try { if (port == null || !port.IsOpen) { port = new SerialPort(DEBUG_PORT, DEBUG_BAUD); port.Open(); port.ReadExisting(); port.DataReceived += Port_DataReceived; } } catch (Exception) { port = null; } Thread.Sleep(100); } }); } LinkUpSerialPortConnector connector = new LinkUpSerialPortConnector(DATA_PORT, DATA_BAUD); connector.ReveivedPacket += Connector_ReveivedPacket; connector.SentPacket += Connector_SentPacket; LinkUpNode node = new LinkUpNode(); node.Name = "net45"; node.AddSubNode(connector); Thread.Sleep(5000); while (true) { foreach (LinkUpPropertyLabel <int> value in node.Labels.Where(c => c is LinkUpPropertyLabel <int>)) { try { Console.WriteLine(string.Format("{0}: {1}", value.Name, value.Value)); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } foreach (LinkUpPropertyLabel <int> value in node.Labels.Where(c => c is LinkUpPropertyLabel <int>)) { try { value.Value = 100; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } } Console.Read(); } }
private static void StaticTest2() { BlockingCollection <byte[]> col1 = new BlockingCollection <byte[]>(); BlockingCollection <byte[]> col2 = new BlockingCollection <byte[]>(); BlockingCollection <byte[]> col3 = new BlockingCollection <byte[]>(); BlockingCollection <byte[]> col4 = new BlockingCollection <byte[]>(); LinkUpMemoryConnector masterToSlave = new LinkUpMemoryConnector(col1, col2); LinkUpMemoryConnector slaveToMaster = new LinkUpMemoryConnector(col2, col1); LinkUpMemoryConnector masterToSuper = new LinkUpMemoryConnector(col3, col4); LinkUpMemoryConnector superToMaster = new LinkUpMemoryConnector(col4, col3); masterToSlave.ReveivedPacket += MasterToSlave_ReveivedPacket; slaveToMaster.ReveivedPacket += SlaveToMaster_ReveivedPacket; masterToSuper.ReveivedPacket += MasterToSuper_ReveivedPacket; superToMaster.ReveivedPacket += SuperToMaster_ReveivedPacket; LinkUpNode super = new LinkUpNode(); super.AddSubNode(superToMaster); super.Name = "super"; LinkUpNode master = new LinkUpNode(); master.AddSubNode(masterToSlave); master.MasterConnector = masterToSuper; master.Name = "master"; LinkUpNode slave = new LinkUpNode(); slave.MasterConnector = slaveToMaster; slave.Name = "slave"; LinkUpPropertyLabel <int> value2 = master.AddLabel <LinkUpPropertyLabel <int> >("value2"); LinkUpPropertyLabel <int> value1 = slave.AddLabel <LinkUpPropertyLabel <int> >("value1"); value1.Value = 10; value2.Value = 1011; Console.WriteLine("Continue after init!"); Console.ReadLine(); LinkUpPropertyLabel <int> value1Ref = (LinkUpPropertyLabel <int>)master.Labels.FirstOrDefault(c => c.Name == "master/slave/value1"); Console.WriteLine("value1Ref: " + value1Ref.Value); value1Ref.Value = 123; Console.WriteLine("value1: " + value1.Value); value1Ref.Value = 10; Console.WriteLine("value1: " + value1.Value); LinkUpPropertyLabel <int> value1RefSuper = (LinkUpPropertyLabel <int>)super.Labels.FirstOrDefault(c => c.Name == "super/master/slave/value1"); Console.WriteLine("value1RefSuper: " + value1RefSuper.Value); value1RefSuper.Value = 123; Console.WriteLine("value1: " + value1.Value); value1RefSuper.Value = 10; Console.WriteLine("value1: " + value1.Value); LinkUpPropertyLabel <int> value2RefSuper = (LinkUpPropertyLabel <int>)super.Labels.FirstOrDefault(c => c.Name == "super/master/value2"); Console.WriteLine("value2RefSuper: " + value2RefSuper.Value); value2RefSuper.Value = 1245; Console.WriteLine("value2: " + value2.Value); value2RefSuper.Value = 1152; Console.WriteLine("value2: " + value2.Value); Console.WriteLine("done"); Console.ReadLine(); }