private void button26_Click(object sender, EventArgs e)
        {
            OperateResult <byte[]> read = busRtuClient.ReadBase(HslCommunication.Serial.SoftCRC16.CRC16(HslCommunication.BasicFramework.SoftBasic.HexStringToBytes(textBox13.Text)));

            if (read.IsSuccess)
            {
                textBox11.Text = "Result:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content);
            }
            else
            {
                MessageBox.Show("Read Failed:" + read.ToMessageShowString( ));
            }
        }
Ejemplo n.º 2
0
        //报文读取
        public string ReadFrame(string cmd)
        {
            string info = "";
            OperateResult <byte[]> read = busRtuClient.ReadBase(HslCommunication.Serial.SoftCRC16.CRC16(HslCommunication.BasicFramework.SoftBasic.HexStringToBytes(cmd)));

            if (read.IsSuccess)
            {
                info = "Result:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content);
            }
            else
            {
                MessageBox.Show("Read Failed:" + read.ToMessageShowString());
            }
            return(info);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 电压值
        /// </summary>
        private void VoltageValue()
        {
            try
            {
                //电压地址
                OperateResult <byte[]> read_3 = Modbus_dianya.ReadBase(HslCommunication.Serial.SoftCRC16.CRC16(HslCommunication.BasicFramework.SoftBasic.HexStringToBytes("01 03 01 6e 00 08")));
                if (read_3.IsSuccess)
                {
                    string Voltage = HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read_3.Content, ' ');

                    //截取指定字符串
                    string[] sArray3      = Voltage.Split(' ');
                    string   Voltage_str1 = sArray3[3];
                    string   Voltage_str2 = sArray3[4];
                    string   Voltage_str3 = sArray3[5];
                    string   Voltage_str4 = sArray3[6];
                    string   Voltage_str5 = sArray3[7];
                    string   Voltage_str6 = sArray3[8];
                    string   Voltage_str7 = sArray3[9];
                    string   Voltage_str8 = sArray3[10];


                    string Voltage_str9  = sArray3[11];
                    string Voltage_str10 = sArray3[12];
                    string Voltage_str11 = sArray3[13];
                    string Voltage_str12 = sArray3[14];
                    string Voltage_str13 = sArray3[15];
                    string Voltage_str14 = sArray3[16];
                    string Voltage_str15 = sArray3[17];
                    string Voltage_str16 = sArray3[18];


                    //8个地址的指标
                    string Voltage_h1 = Voltage_str1 + Voltage_str2;
                    string Voltage_h2 = Voltage_str3 + Voltage_str4;
                    string Voltage_h3 = Voltage_str5 + Voltage_str6;
                    string Voltage_h4 = Voltage_str7 + Voltage_str8;
                    string Voltage_h5 = Voltage_str9 + Voltage_str10;
                    string Voltage_h6 = Voltage_str11 + Voltage_str12;
                    string Voltage_h7 = Voltage_str13 + Voltage_str14;
                    string Voltage_h8 = Voltage_str15 + Voltage_str16;



                    //高位字和低位字
                    string Voltage_dh1 = Voltage_h1 + Voltage_h2;                    //A相电压
                    string Voltage_dh2 = Voltage_h3 + Voltage_h4;                    //B相电压
                    string Voltage_dh3 = Voltage_h5 + Voltage_h6;                    //C相电压
                    string Voltage_dh4 = Voltage_h7 + Voltage_h8;                    //A相电流



                    //16进制转10进制
                    double Voltage_d1 = Convert.ToInt32(Voltage_dh1, 16);
                    double Voltage_d2 = Convert.ToInt32(Voltage_dh2, 16);
                    double Voltage_d3 = Convert.ToInt32(Voltage_dh3, 16);
                    double Voltage_d4 = Convert.ToInt32(Voltage_dh4, 16);



                    //电压值(1路)A项电压
                    Voltage01 = Math.Round(((decimal)Voltage_d1 / 10000), 2);
                    Console.WriteLine(Voltage01);
                    text_dianya.Text = Voltage01.ToString();
                    //电压值(2路)B项电压
                    Voltage02 = Math.Round(((decimal)Voltage_d2 / 10000), 2);
                    Console.WriteLine(Voltage02);


                    //电流值
                    Voltage04 = Math.Round(((decimal)Voltage_d4 / 10000), 2);
                    Console.WriteLine(Voltage04);
                    text_dianliu.Text = Voltage04.ToString();
                }
                else
                {
                    MessageBox.Show("电压地址读取失败:" + read_3.ToMessageShowString());
                }
            }
            catch (Exception ex)
            {
                Common.LogHandler.WriteLog("电压地址读取失败");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 温度值
        /// </summary>
        private void TemperatureValue()
        {
            try
            {
                //获取4个温度地址
                OperateResult <byte[]> read_1 = busRtuClient.ReadBase(HslCommunication.Serial.SoftCRC16.CRC16(HslCommunication.BasicFramework.SoftBasic.HexStringToBytes("02 03 00 02 00 04")));
                if (read_1.IsSuccess)
                {
                    string wendu = HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read_1.Content, ' ');
                    //截取指定字符串
                    string[] sArray  = wendu.Split(' ');
                    string   wd_str1 = sArray[3];
                    string   wd_str2 = sArray[4];
                    string   wd_str3 = sArray[5];
                    string   wd_str4 = sArray[6];
                    string   wd_str5 = sArray[7];
                    string   wd_str6 = sArray[8];
                    string   wd_str7 = sArray[9];
                    string   wd_str8 = sArray[10];

                    //4个温度地址16进制
                    string wd_h1 = wd_str1 + wd_str2;
                    string wd_h2 = wd_str3 + wd_str4;
                    string wd_h3 = wd_str5 + wd_str6;
                    string wd_h4 = wd_str7 + wd_str8;

                    //16进制转10进制
                    double wd_d1 = Convert.ToInt32(wd_h1, 16);
                    double wd_d2 = Convert.ToInt32(wd_h2, 16);
                    double wd_d3 = Convert.ToInt32(wd_h3, 16);
                    double wd_d4 = Convert.ToInt32(wd_h4, 16);


                    #region -50-+100温度测试
                    //decimal ElectricCurrent_d = Math.Round(((decimal)wd_d3 / 1000), 2);
                    //Temperature = k * (double)ElectricCurrent_d + b;
                    //Console.WriteLine(Temperature);
                    #endregion

                    //温度(0-300)1路
                    decimal ElectricCurrent_d1 = Math.Round(((decimal)wd_d1 / 1000), 2);
                    Temperature01 = h * (double)ElectricCurrent_d1 + j;
                    double Temperature_01 = (double)((ElectricCurrent_d1 - 4) * 300) / 16;
                    Console.WriteLine(Temperature01);
                    Console.WriteLine(Temperature_01);

                    //温度(0-300)2路
                    decimal ElectricCurrent_d2 = Math.Round(((decimal)wd_d2 / 1000), 2);
                    Temperature02 = h * (double)ElectricCurrent_d2 + j;
                    double Temperature_02 = (double)((ElectricCurrent_d2 - 4) * 300) / 16;
                    Console.WriteLine(Temperature02);
                    Console.WriteLine(Temperature_02);

                    //温度(0-1000)3路
                    decimal ElectricCurrent_d3 = Math.Round(((decimal)wd_d3 / 1000), 2);
                    Temperature03 = y * (double)ElectricCurrent_d3 + z;
                    double Temperature_03 = (double)((ElectricCurrent_d3 - 4) * 300) / 16;
                    Console.WriteLine(Temperature03);
                    Console.WriteLine(Temperature_03);


                    //-50-100测试
                    Temperature03_03 = k * (double)ElectricCurrent_d3 + b;
                    Temperature03_04 = (double)((ElectricCurrent_d3 - 4) * 150) / 16 - 50;
                    //测试
                    Console.WriteLine(Temperature03_03);
                    Console.WriteLine(Temperature03_04);
                    txt_wendu.Text = Temperature03_04.ToString();


                    //温度(0-1000)4路
                    decimal ElectricCurrent_d4 = Math.Round(((decimal)wd_d4 / 1000), 2);
                    Temperature04 = y * (double)ElectricCurrent_d4 + z;
                    double Temperature_04 = (double)((ElectricCurrent_d4 - 4) * 300) / 16;
                    Console.WriteLine(Temperature04);
                    Console.WriteLine(Temperature_04);
                }

                else
                {
                    MessageBox.Show("温度读取失败:" + read_1.ToMessageShowString());
                }
            }

            catch (Exception ex)
            {
                Common.LogHandler.WriteLog("温度地址读取失败");
            }
        }