Example #1
0
        public bool Homing(string hostIp, int port)
        {
            Socket           s = ModbusSocket.GetConnection(hostIp, port);
            ModesOfOperation modesOfOperation = new ModesOfOperation();

            modesOfOperation.Write(s, ModesOfOperation.ModesEnum.Homing);
            while (modesOfOperation.ReadDisplay(s) != ModesOfOperation.ModesEnum.Homing)
            {
                Thread.Sleep(100);
            }
            ControlWord controlWord = new ControlWord();

            // Byte 19: 31
            controlWord.Bit00 = true; // 1
            controlWord.Bit01 = true; // 2
            controlWord.Bit02 = true; // 4
            controlWord.Bit03 = true; // 8
            controlWord.Bit04 = true; // 16
            controlWord.Write(s);

            StatusWord statusWord = new StatusWord();

            while (!(statusWord.Bit00 && statusWord.Bit01 && statusWord.Bit02 && statusWord.Bit05 && // 39
                     statusWord.Bit09 && statusWord.Bit10 && statusWord.Bit12)) // 22
            {
                statusWord.Read(s);
                Thread.Sleep(100);
            }
            return(true);
        }
        private void PrintStatusWord(Socket s)
        {
            StatusWord sw = new StatusWord();

            sw.Read(s);
            var bitArray19 = new BitArray(new bool[8] {
                sw.Bit00, sw.Bit01, sw.Bit02, sw.Bit03, sw.Bit04, sw.Bit05, sw.Bit06, sw.Bit07
            });
            var bitArray20 = new BitArray(new bool[8] {
                sw.Bit08, sw.Bit09, sw.Bit10, sw.Bit11, sw.Bit12, sw.Bit13, sw.Bit14, sw.Bit15
            });

            byte[] byte19 = new byte[1];
            bitArray19.CopyTo(byte19, 0);

            byte[] byte20 = new byte[1];
            bitArray20.CopyTo(byte20, 0);
            Debug.WriteLine("");
            Debug.WriteLine("StatusWord");
            Debug.WriteLine($"Byte 19: {byte19[0]}");
            Debug.WriteLine($"0: {sw.Bit00}, 1: {sw.Bit01}, 2: {sw.Bit02}, 3: {sw.Bit03}, 4: {sw.Bit04}, 5: {sw.Bit05}, 6: {sw.Bit06}, 7: {sw.Bit07}");
            Debug.WriteLine($"Byte 20: {byte20[0]}");
            Debug.WriteLine($"8: {sw.Bit08}, 9: {sw.Bit09}, 10: {sw.Bit10}, 11: {sw.Bit11}, 12: {sw.Bit12}, 13: {sw.Bit13}, 14: {sw.Bit14}, 15: {sw.Bit15}");
            Debug.WriteLine("");
        }
        public StatusWord GetStatusWord(string hostIp, int port)
        {
            Socket     s          = ModbusSocket.GetConnection(hostIp, port);
            StatusWord statusWord = new StatusWord();

            statusWord.Read(s);
            return(statusWord);
        }
Example #4
0
        private void ShutDown(Socket s)
        {
            ControlWord controlWord = new ControlWord();

            // Byte 19: 6
            controlWord.Bit01 = true; // 2
            controlWord.Bit02 = true; // 4
            controlWord.Write(s);

            StatusWord statusWord = new StatusWord();

            while (!(statusWord.Bit00 && statusWord.Bit05 && // 33
                     statusWord.Bit09)) // 2
            {
                statusWord.Read(s);
                Thread.Sleep(100);
            }
        }
Example #5
0
        private void EnableOperation(Socket s)
        {
            ControlWord controlWord = new ControlWord();

            // Byte 19: 15
            controlWord.Bit00 = true; // 1
            controlWord.Bit01 = true; // 2
            controlWord.Bit02 = true; // 4
            controlWord.Bit03 = true; // 8
            controlWord.Write(s);

            StatusWord statusWord = new StatusWord();

            while (!(statusWord.Bit00 && statusWord.Bit01 && statusWord.Bit02 && statusWord.Bit05 && // 39
                     statusWord.Bit09)) // 2
            {
                statusWord.Read(s);
                Thread.Sleep(100);
            }
        }