示例#1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        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 bool WritePDO(int Idx, int SubIndex, int size, byte[] buff)
        {
            int ret = SoemInterrop.WritePDO(Id, Idx, SubIndex, size, buff);

            if (ret != 0)
            {
                Trace.WriteLine("PDO Write OK");
                return(true);
            }
            else
            {
                Trace.WriteLine("PDO Write Fail");
                return(false);
            }
        }