Ejemplo n.º 1
0
        //  Write %IW1530
        public static void TestWriteLoop()
        {
            IPEndPoint       ep      = new IPEndPoint(IPAddress.Parse("172.20.54.58"), 0xAF12);
            EnIPRemoteDevice WagoPlc = new EnIPRemoteDevice(ep);

            // class 166, instance 1, attribut 1
            EnIPClass    Class166        = new EnIPClass(WagoPlc, 166);
            EnIPInstance Instance1       = new EnIPInstance(Class166, 1);
            EnIPAttribut FirstMemoryByte = new EnIPAttribut(Instance1, 1);

            // Connect made & retry automatically
            WagoPlc.autoConnect         = true;
            WagoPlc.autoRegisterSession = true;

            ushort i = 0;

            for (; ;)
            {
                FirstMemoryByte.RawData = BitConverter.GetBytes(i++);
                if (FirstMemoryByte.WriteDataToNetwork() == EnIPNetworkStatus.OnLine)
                {
                    Console.WriteLine("OK");
                }

                Thread.Sleep(200);
            }
        }
Ejemplo n.º 2
0
        // change in properties Grid, a Byte in the Raw Data
        // send it to the device if it's an attribut value
        private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            if ((e.ChangedItem.Parent != null) && (e.ChangedItem.Parent.Label == "RawData") && (devicesTreeView.SelectedNode.Tag is EnIPAttribut))
            {
                EnIPAttribut v = (EnIPAttribut)devicesTreeView.SelectedNode.Tag;
                if (v.WriteDataToNetwork() == EnIPNetworkStatus.OnLine)
                {
                    Trace.WriteLine("Write OK");
                }
            }
            else
            if ((e.ChangedItem.Parent != null) && (e.ChangedItem.Parent.Label == "DecodedMembers") && (devicesTreeView.SelectedNode.Tag is EnIPAttribut))
            {
                EnIPAttribut v = (EnIPAttribut)devicesTreeView.SelectedNode.Tag;
                if (v.EncodeFromDecodedMembers() == true)     // encoding is done into the previous RawByte (and same size)
                {
                    if (v.WriteDataToNetwork() == EnIPNetworkStatus.OnLine)
                    {
                        Trace.WriteLine("Write OK");
                    }
                }
                else
                {
                    Trace.WriteLine("Encoding not allow here or error during the encoding process, nothing written");
                }
            }
            else
            {
                Trace.WriteLine("Modifications are not taken into account here");
            }

            readAgainToolStripMenuItem_Click(null, null);
        }