//////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// static void Main(string[] args) { // Interfaces list List <Tuple <String, String, String> > Interfaces = GetAvailableInterfaces(); // Start network activity on the first interface (indice 0) String PcapInterfaceName = "\\Device\\NPF_" + Interfaces[0].Item3; int NumberofSlavesDetected = SoemInterrop.StartActivity(PcapInterfaceName, 1); // Until now if the parameter is missing it's Operational, otherwise slaves are // in there default mode (SafeOperational is not used). SoemInterrop.Run(SlaveState.SafeOperational); byte[] buf = new byte[50]; // must be large enough int size = buf.Length; // some Acyclic Read/Write // Could be also realize in operational, init, .... state SoemInterrop.ReadPDO(1, 0x6000, -1, ref size, buf); SoemInterrop.WritePDO(1, 0x7000, 0, 4, buf); DeviceInfo(); // Change to Operational SoemInterrop.WriteState(1, SlaveState.Operational); for (; ;) { SoemInterrop.RefreshSlavesState(); DeviceInfo(); Thread.Sleep(2000); } }
private void devicesTreeView_AfterSelect(object sender, TreeViewEventArgs e) { try { if (e.Node.Tag is EthCATDevice) { SoemInterrop.RefreshSlavesState(); EthCATDevice slave = (EthCATDevice)e.Node.Tag; slave.Refresh(); e.Node.SelectedImageIndex = e.Node.ImageIndex = SlaveStatetoIco(slave.State); propertyGrid.SelectedObject = slave; propertyGrid.ExpandAllGridItems(); propertyInput.SelectedObjects = new object[] { slave.InputData }; propertyInput.ExpandAllGridItems(); propertyOutput.SelectedObjects = new object[] { slave.OutputData }; propertyOutput.ExpandAllGridItems(); PDOToolStripMenuItem.Enabled = slave.MailboxProtocol.Contains(MailBoxProto.CoE.ToString()); } else { propertyGrid.SelectedObject = null; } } catch { } }
private void tmrRefreshState_Tick(object sender, EventArgs e) { tmrStart.Enabled = false; SoemInterrop.RefreshSlavesState(); foreach (TreeNode tn in devicesTreeView.Nodes) { EthCATDevice slave = tn.Tag as EthCATDevice; SlaveState s = slave.State; slave.Refresh(); if (s != slave.State) { int img = SlaveStatetoIco(slave.State); tn.ImageIndex = tn.SelectedImageIndex = img; devicesTreeView.Refresh(); } if (tn == devicesTreeView.SelectedNode) { propertyGrid.Refresh(); propertyInput.Refresh(); } } }