//////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// 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); } }
// SubIndex=-1 for all public byte[] ReadPDO(int Idx, int SubIndex, out int size) { byte[] buff = new byte[4096]; size = 4096; int ret = SoemInterrop.ReadPDO(Id, Idx, SubIndex, ref size, buff); if (ret != 0) { Trace.WriteLine("PDO Read OK"); return(buff); } else { Trace.WriteLine("PDO Read Fail"); return(null); } }