public void 批量读取(MitsubishiVersion version, int port)
        {
            client = new MitsubishiClient(version, ip, port);

            Dictionary <string, DataTypeEnum> readAddresses = new Dictionary <string, DataTypeEnum>();

            //readAddresses.Add("V2634.0", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.1", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.2", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.3", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.4", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.5", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.6", DataTypeEnum.Bool);
            //readAddresses.Add("V2634.7", DataTypeEnum.Bool);
            //readAddresses.Add("V2642", DataTypeEnum.Float);
            //readAddresses.Add("V2646", DataTypeEnum.Float);
            //readAddresses.Add("V2650", DataTypeEnum.Float);
            readAddresses.Add("D100", DataTypeEnum.Float);
            readAddresses.Add("D102", DataTypeEnum.Float);
            readAddresses.Add("D104", DataTypeEnum.Float);
            readAddresses.Add("D263", DataTypeEnum.Int16);
            readAddresses.Add("D265", DataTypeEnum.Int16);
            //readAddresses.Add("V2670", DataTypeEnum.Float);
            //readAddresses.Add("V2674", DataTypeEnum.Float);
            //readAddresses.Add("V1650", DataTypeEnum.Byte);
            //readAddresses.Add("V1651", DataTypeEnum.Byte);
            //readAddresses.Add("V1652", DataTypeEnum.Byte);

            var result = client.BatchRead(readAddresses, 10);
        }
        public void 长连接主动开关(MitsubishiVersion version, int port)
        {
            client = new MitsubishiClient(version, ip, port);

            client.Open();

            ReadWrite();

            client?.Close();
        }
        public void 批量读写(MitsubishiVersion version, int port)
        {
            client = new MitsubishiClient(version, ip, port);

            client.Open();

            Random rnd           = new Random((int)Stopwatch.GetTimestamp());
            short  short_number1 = (short)rnd.Next(short.MinValue, short.MaxValue);
            short  short_number2 = (short)rnd.Next(short.MinValue, short.MaxValue);
            short  short_number3 = (short)rnd.Next(short.MinValue, short.MaxValue);
            short  short_number4 = (short)rnd.Next(short.MinValue, short.MaxValue);
            short  short_number5 = (short)rnd.Next(short.MinValue, short.MaxValue);
            var    bool_value    = short_number1 % 2 == 1;

            client.Write("M100", !bool_value);
            client.Write("M101", !bool_value);
            client.Write("M102", bool_value);
            client.Write("M103", !bool_value);
            client.Write("M104", bool_value);

            var result = client.ReadBoolean("M100", 5);

            foreach (var item in result.Value)
            {
                if (item.Key == "M100" || item.Key == "M101" || item.Key == "M103")
                {
                    Assert.True(item.Value == !bool_value);
                }
                else
                {
                    Assert.True(item.Value == bool_value);
                }
            }

            client.Write("D100", short_number1);
            client.Write("D101", short_number2);
            client.Write("D102", short_number3);
            client.Write("D103", short_number4);
            client.Write("D104", short_number5);

            Assert.True(client.ReadInt16("D100").Value == short_number1);
            Assert.True(client.ReadInt16("D101").Value == short_number2);
            Assert.True(client.ReadInt16("D102").Value == short_number3);
            Assert.True(client.ReadInt16("D103").Value == short_number4);
            Assert.True(client.ReadInt16("D104").Value == short_number5);

            client?.Close();
        }
        public MitsubishiMCControl(MitsubishiVersion version)
        {
            InitializeComponent();
            Size = new Size(880, 450);
            groupBox2.Location   = new Point(13, 5);
            groupBox2.Size       = new Size(855, 50);
            groupBox1.Location   = new Point(13, 55);
            groupBox1.Size       = new Size(855, 50);
            groupBox3.Location   = new Point(13, 105);
            groupBox3.Size       = new Size(855, 50);
            txt_content.Location = new Point(13, 160);

            lab_address.Location = new Point(9, 22);
            txt_address.Location = new Point(39, 18);
            txt_address.Size     = new Size(88, 21);
            but_read.Location    = new Point(132, 17);

            lab_value.Location = new Point(227, 22);
            txt_value.Location = new Point(249, 18);
            txt_value.Size     = new Size(74, 21);
            but_write.Location = new Point(328, 17);

            txt_dataPackage.Location = new Point(430, 18);
            txt_dataPackage.Size     = new Size(186, 21);
            but_sendData.Location    = new Point(620, 17);

            chb_show_package.Location = new Point(776, 19);

            but_read.Enabled         = false;
            but_write.Enabled        = false;
            but_close_server.Enabled = false;
            but_close.Enabled        = false;
            but_sendData.Enabled     = false;

            this.version = version;
        }
Exemple #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 /// <param name="timeout"></param>
 public MitsubishiClient(MitsubishiVersion version, string ip, int port, int timeout = 1500)
 {
     this.version = version;
     IpAndPoint   = new IPEndPoint(IPAddress.Parse(ip), port);;
     this.timeout = timeout;
 }
Exemple #6
0
        public MitsubishiMCControl(MitsubishiVersion version)
        {
            InitializeComponent();
            Size = new Size(880, 450);
            groupBox2.Location   = new Point(13, 5);
            groupBox2.Size       = new Size(855, 50);
            groupBox1.Location   = new Point(13, 55);
            groupBox1.Size       = new Size(855, 50);
            groupBox3.Location   = new Point(13, 105);
            groupBox3.Size       = new Size(855, 50);
            txt_content.Location = new Point(13, 160);

            lab_address.Location = new Point(9, 22);
            txt_address.Location = new Point(39, 18);
            txt_address.Size     = new Size(88, 21);
            but_read.Location    = new Point(132, 17);

            lab_value.Location = new Point(227, 22);
            txt_value.Location = new Point(249, 18);
            txt_value.Size     = new Size(74, 21);
            but_write.Location = new Point(328, 17);

            txt_dataPackage.Location = new Point(430, 18);
            txt_dataPackage.Size     = new Size(186, 21);
            but_sendData.Location    = new Point(620, 17);

            chb_show_package.Location = new Point(776, 19);

            but_read.Enabled         = false;
            but_write.Enabled        = false;
            but_close_server.Enabled = false;
            but_close.Enabled        = false;
            but_sendData.Enabled     = false;

            this.version = version;

            var config = ConnectionConfig.GetConfig();

            switch (version)
            {
            case MitsubishiVersion.A_1E:
                if (!string.IsNullOrWhiteSpace(config.MitsubishiA1E_IP))
                {
                    txt_ip.Text = config.MitsubishiA1E_IP;
                }
                if (!string.IsNullOrWhiteSpace(config.MitsubishiA1E_Port))
                {
                    txt_port.Text = config.MitsubishiA1E_Port;
                }
                if (!string.IsNullOrWhiteSpace(config.MitsubishiA1E_Address))
                {
                    txt_address.Text = config.MitsubishiA1E_Address;
                }
                if (!string.IsNullOrWhiteSpace(config.MitsubishiA1E_Value))
                {
                    txt_value.Text = config.MitsubishiA1E_Value;
                }
                chb_show_package.Checked = config.MitsubishiA1E_ShowPackage;
                switch (config.MitsubishiA1E_Datatype)
                {
                case "rd_bit": rd_bit.Checked = true; break;

                case "rd_short": rd_short.Checked = true; break;

                case "rd_ushort": rd_ushort.Checked = true; break;

                case "rd_int": rd_int.Checked = true; break;

                case "rd_uint": rd_uint.Checked = true; break;

                case "rd_long": rd_long.Checked = true; break;

                case "rd_ulong": rd_ulong.Checked = true; break;

                case "rd_float": rd_float.Checked = true; break;

                case "rd_double": rd_double.Checked = true; break;
                }
                ;
                break;

            case MitsubishiVersion.Qna_3E:
                if (!string.IsNullOrWhiteSpace(config.MitsubishiQna3E_IP))
                {
                    txt_ip.Text = config.MitsubishiQna3E_IP;
                }
                if (!string.IsNullOrWhiteSpace(config.MitsubishiQna3E_Port))
                {
                    txt_port.Text = config.MitsubishiQna3E_Port;
                }
                if (!string.IsNullOrWhiteSpace(config.MitsubishiQna3E_Address))
                {
                    txt_address.Text = config.MitsubishiQna3E_Address;
                }
                if (!string.IsNullOrWhiteSpace(config.MitsubishiQna3E_Value))
                {
                    txt_value.Text = config.MitsubishiQna3E_Value;
                }
                chb_show_package.Checked = config.MitsubishiQna3E_ShowPackage;
                switch (config.MitsubishiQna3E_Datatype)
                {
                case "rd_bit": rd_bit.Checked = true; break;

                case "rd_short": rd_short.Checked = true; break;

                case "rd_ushort": rd_ushort.Checked = true; break;

                case "rd_int": rd_int.Checked = true; break;

                case "rd_uint": rd_uint.Checked = true; break;

                case "rd_long": rd_long.Checked = true; break;

                case "rd_ulong": rd_ulong.Checked = true; break;

                case "rd_float": rd_float.Checked = true; break;

                case "rd_double": rd_double.Checked = true; break;
                }
                ;
                break;
            }
        }
        public void 短连接自动开关(MitsubishiVersion version, int port)
        {
            client = new MitsubishiClient(version, ip, port);

            ReadWrite();
        }