Пример #1
0
        /// <summary>
        /// 三相电流(A)
        /// </summary>
        public float[] Current_All(byte[] address, SerialPort sp)
        {
            float[] tmp      = new float[3];
            byte[]  _current = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Current_All.ToString());

            sp.Write(_current, 0, _current.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                tmp[0]  = Utilities.bcd_to_dec(_rcvBuf[14]);
                tmp[0]  = tmp[0] + Utilities.bcd_to_dec(_rcvBuf[15]) * 100;
                tmp[0]  = tmp[0] + Utilities.bcd_to_dec(_rcvBuf[16]) * 10000;
                tmp[0] /= 10;

                tmp[1]  = Utilities.bcd_to_dec(_rcvBuf[17]);
                tmp[1]  = tmp[1] + Utilities.bcd_to_dec(_rcvBuf[18]) * 100;
                tmp[1]  = tmp[1] + Utilities.bcd_to_dec(_rcvBuf[19]) * 10000;
                tmp[1] /= 10;

                tmp[2]  = Utilities.bcd_to_dec(_rcvBuf[20]);
                tmp[2]  = tmp[2] + Utilities.bcd_to_dec(_rcvBuf[21]) * 100;
                tmp[2]  = tmp[2] + Utilities.bcd_to_dec(_rcvBuf[22]) * 10000;
                tmp[2] /= 10;
            }
            return(tmp);
        }
Пример #2
0
        /// <summary>
        /// 通信波特率
        /// </summary>
        public int Device_BaudRate(byte[] address, SerialPort sp)
        {
            int tmp = 3;

            byte[] _baudRate = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Device_BaudRate.ToString());

            sp.Write(_baudRate, 0, _baudRate.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                tmp = Utilities.bcd_to_dec(_rcvBuf[10]);
            }
            return(tmp);
        }
Пример #3
0
        /// <summary>
        /// 剩余电流最大相
        /// </summary>
        public float Residual_Phase(byte[] address, SerialPort sp)
        {
            int tmp = 0;

            byte[] _residual = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Residual_Phase.ToString());

            sp.Write(_residual, 0, _residual.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                tmp = _rcvBuf[14];
            }
            return(tmp);
        }
Пример #4
0
        /// <summary>
        /// 额定极限不驱动时间(ms)
        /// </summary>
        public int Rated_Not_Driving_Time(byte[] address, SerialPort sp)
        {
            int tmp = 0;

            byte[] _residual = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Rated_Not_Driving_Time.ToString());

            sp.Write(_residual, 0, _residual.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                tmp = Utilities.bcd_to_dec(_rcvBuf[14]);
                tmp = tmp + Utilities.bcd_to_dec(_rcvBuf[15]) * 100;
            }
            return(tmp);
        }
Пример #5
0
        /// <summary>
        /// 写通信波特率
        /// </summary>
        public bool Write_Device_BaudRate(byte[] address, SerialPort sp, int baudrate)
        {
            byte tmp = 0;

            if (baudrate == 600)
            {
                tmp = 1;
            }
            else if (baudrate == 1200)
            {
                tmp = 2;
            }
            else if (baudrate == 2400)
            {
                tmp = 3;
            }
            else if (baudrate == 4800)
            {
                tmp = 4;
            }
            else if (baudrate == 9600)
            {
                tmp = 5;
            }
            else if (baudrate == 19200)
            {
                tmp = 6;
            }
            byte[] _baudRate = CommandMsg.changeBaudRate(address, (byte)CommandMsg.ControlCode.ChangeBaudRate, (byte)CommandMsg.DataFieldLength.ChangeBaudRate, tmp);

            sp.Write(_baudRate, 0, _baudRate.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                if (_rcvBuf[8] == 0x97)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
        /// <summary>
        /// 读设备号
        /// </summary>
        public int[] Read_Device_Number(byte[] address, SerialPort sp)
        {
            int[]  tmp           = new int[6];
            byte[] _deviceNumber = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Device_Number.ToString());

            sp.Write(_deviceNumber, 0, _deviceNumber.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                for (int i = 0; i < 6; i++)
                {
                    tmp[i] = Utilities.bcd_to_dec(_rcvBuf[14 + i]);
                }
            }
            return(tmp);
        }
Пример #7
0
        /// <summary>
        /// 读通讯地址
        /// </summary>
        public int[] Read_Device_Address(SerialPort sp)
        {
            int[]  tmp       = new int[6];
            byte[] _readAddr = CommandMsg.readAddress((byte)CommandMsg.ControlCode.ReadAddr, (byte)CommandMsg.DataFieldLength.ReadAddr);

            sp.Write(_readAddr, 0, _readAddr.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                for (int i = 0; i < 6; i++)
                {
                    tmp[i] = Utilities.bcd_to_dec(_rcvBuf[10 + i]);
                }
            }
            return(tmp);
        }
Пример #8
0
        /// <summary>
        /// C相电压(V)
        /// </summary>
        public float Voltage_C(byte[] address, SerialPort sp)
        {
            int tmp = 0;

            byte[] _voltage = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Voltage_C.ToString());

            sp.Write(_voltage, 0, _voltage.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                tmp  = Utilities.bcd_to_dec(_rcvBuf[14]);
                tmp  = tmp + Utilities.bcd_to_dec(_rcvBuf[15]) * 100;
                tmp /= 10;
            }
            return(tmp);
        }
Пример #9
0
        private void get_residualLimit()
        {
            Dictionary <string, string> dict = DID();
            CommandMsg dlt = new CommandMsg();

            byte[] _ResidualLimit = dlt.readData(_address, (byte)CommandMsg.ControlCode.ReadData, dict["剩余电流超限事件"]);
            serialPort1.Write(_ResidualLimit, 0, _ResidualLimit.Length);

            if (receive_frame(ref _rcvBuf) == true)
            {
                fill_datatable_ResidualLimit(ref _rcvBuf);
            }
            else
            {
                stalabMBStatus.Text = "剩余电流超限事件读取错误";
            }
        }
Пример #10
0
        private void get_trip()
        {
            Dictionary <string, string> dict = DID();
            CommandMsg dlt = new CommandMsg();

            byte[] _Trip = dlt.readData(_address, (byte)CommandMsg.ControlCode.ReadData, dict["跳闸事件记录"]);
            serialPort1.Write(_Trip, 0, _Trip.Length);

            if (receive_frame(ref _rcvBuf) == true)
            {
                fill_datatable_Trip(ref _rcvBuf);
            }
            else
            {
                stalabMBStatus.Text = "跳闸事件记录读取错误";
            }
        }
Пример #11
0
        /// <summary>
        /// 额定剩余电流动作值参数组
        /// </summary>
        public int[] Rated_Residual_Parameter_Group(byte[] address, SerialPort sp)
        {
            int[]  tmp            = new int[8];
            byte[] _ratedResidual = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Rated_Residual_Parameter_Group.ToString());

            sp.Write(_ratedResidual, 0, _ratedResidual.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                for (int i = 0; i < 8; i++)
                {
                    tmp[i] = Utilities.bcd_to_dec(_rcvBuf[14 + i * 2]);
                    tmp[i] = tmp[i] + Utilities.bcd_to_dec(_rcvBuf[15 + i * 2]) * 100;
                }
            }
            return(tmp);
        }
Пример #12
0
        public int[] Residual_All(byte[] address, SerialPort sp)
        {
            int[]  tmp       = new int[2];
            byte[] _residual = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Residual_All.ToString());

            sp.Write(_residual, 0, _residual.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                //剩余电流最大相

                tmp[0] = _rcvBuf[14];

                //剩余电流值
                tmp[1] = Utilities.bcd_to_dec(_rcvBuf[15]);
                tmp[1] = tmp[1] + Utilities.bcd_to_dec(_rcvBuf[16]) * 100;
            }
            return(tmp);
        }
Пример #13
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            lock (_lock)
            {
                try
                {
                    Dictionary <string, string> dict = DID();
                    CommandMsg dlt = new CommandMsg();

                    byte[] _cmdOpen = dlt.controlCommand(_address, (byte)CommandMsg.ControlCode.Control, (byte)CommandMsg.DataFieldLength.Control, dict["跳闸"]);

                    serialPort1.Write(_cmdOpen, 0, _cmdOpen.Length);
                    receive_frame(ref _rcvBuf);
                }
                catch (Exception ex)
                {
                    offline_process(ex.Message);
                }
            }
        }
Пример #14
0
        /// <summary>
        /// 写通讯地址
        /// </summary>
        public bool Write_Device_Address(byte[] address, SerialPort sp)
        {
            byte[] _writeAddr = CommandMsg.writeAddress(Utilities.dec_to_bcd(address), (byte)CommandMsg.ControlCode.WriteAddr, (byte)CommandMsg.DataFieldLength.WriteAddr);
            sp.Write(_writeAddr, 0, _writeAddr.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                if (_rcvBuf[8] == 0x95)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #15
0
        /// <summary>
        /// 写设备号
        /// </summary>
        public bool Write_Device_Number(byte[] address, SerialPort sp, byte[] data)
        {
            byte[] _deviceNumber = CommandMsg.writeData(address, (byte)CommandMsg.ControlCode.WriteData, (byte)CommandMsg.DataFieldLength.WriteData + 6, MBREG.Device_Number.ToString(), data);

            sp.Write(_deviceNumber, 0, _deviceNumber.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                if (_rcvBuf[8] == 0x94)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #16
0
        /// <summary>
        /// 控制字4
        /// </summary>
        public string[] Control_Word_4(byte[] address, SerialPort sp)
        {
            string[] tmp     = new string[3];
            byte[]   _status = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Control_Word4.ToString());

            sp.Write(_status, 0, _status.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                if ((_rcvBuf[14] & 0x80) == 0x80)
                {
                    tmp[0] = "有";
                }
                else
                {
                    tmp[0] = "无";
                }

                //额定剩余电流动作值
                if ((_rcvBuf[14] & 0xF0) == 0)
                {
                    tmp[0] = "档位1";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x10)
                {
                    tmp[0] = "档位2";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x20)
                {
                    tmp[0] = "档位3";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x30)
                {
                    tmp[0] = "档位4";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x40)
                {
                    tmp[0] = "档位5";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x50)
                {
                    tmp[0] = "档位6";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x60)
                {
                    tmp[0] = "档位7";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0x70)
                {
                    tmp[0] = "档位8";
                }
                else if ((_rcvBuf[14] & 0xF0) == 0xF0)
                {
                    tmp[0] = "连续可调";
                }
                else
                {
                    tmp[0] = "保留";
                }

                //额定极限不驱动时间
                if ((_rcvBuf[14] & 0x0C) == 0)
                {
                    tmp[1] = "档位1";
                }
                else if ((_rcvBuf[14] & 0x0C) == 0x04)
                {
                    tmp[1] = "档位2";
                }
                else if ((_rcvBuf[14] & 0x0C) == 0x08)
                {
                    tmp[1] = "档位3";
                }
                else
                {
                    tmp[1] = "连续可调";
                }

                //剩余电流报警时间
                if ((_rcvBuf[14] & 0x03) == 0)
                {
                    tmp[12] = "关闭";
                }
                else if ((_rcvBuf[14] & 0x0C) == 0x01)
                {
                    tmp[12] = "启用24小时";
                }
                else if ((_rcvBuf[14] & 0x0C) == 0x02)
                {
                    tmp[12] = "长期启用";
                }
                else
                {
                    tmp[12] = "保留";
                }
            }
            return(tmp);
        }
Пример #17
0
        /// <summary>
        /// 运行状态字1
        /// </summary>
        public string[] Running_Status_1(byte[] address, SerialPort sp)
        {
            string[] tmp     = new string[3];
            byte[]   _status = CommandMsg.readData(address, (byte)CommandMsg.ControlCode.ReadData, MBREG.Running_Status1.ToString());

            sp.Write(_status, 0, _status.Length);

            if (CommandMsg.receive_frame(ref _rcvBuf, sp) == true)
            {
                if ((_rcvBuf[14] & 0x80) == 0x80)
                {
                    tmp[0] = "有";
                }
                else
                {
                    tmp[0] = "无";
                }

                if ((_rcvBuf[14] & 0x60) == 0x60)
                {
                    tmp[1] = "跳闸";
                }
                else if ((_rcvBuf[14] & 0x60) == 0x00)
                {
                    tmp[1] = "合闸";
                }
                else if ((_rcvBuf[14] & 0x60) == 0x40)
                {
                    tmp[1] = "重合闸";
                }
                else
                {
                    tmp[1] = "保留";
                }

                if ((_rcvBuf[14] & 0x1F) == 0x00)
                {
                    tmp[2] = "正常运行";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x02)
                {
                    tmp[2] = "剩余电流";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x04)
                {
                    tmp[2] = "断零";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x05)
                {
                    tmp[2] = "过载";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x06)
                {
                    tmp[2] = "短路短延时";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x07)
                {
                    tmp[2] = "缺相";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x08)
                {
                    tmp[2] = "欠压";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x09)
                {
                    tmp[2] = "过压";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x0A)
                {
                    tmp[2] = "接地";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x0B)
                {
                    tmp[2] = "停电";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x0C)
                {
                    tmp[2] = "定时试验";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x0D)
                {
                    tmp[2] = "远程";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x0E)
                {
                    tmp[2] = "按键试验";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x0F)
                {
                    tmp[2] = "闭锁";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x12)
                {
                    tmp[2] = "手动";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x10)
                {
                    tmp[2] = "互感器故障";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x11)
                {
                    tmp[2] = "合闸失败";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x13)
                {
                    tmp[2] = "设置更改";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x16)
                {
                    tmp[2] = "瞬动";
                }
                else if ((_rcvBuf[14] & 0x1F) == 0x17)
                {
                    tmp[2] = "分闸失败";
                }
                else
                {
                    tmp[2] = "保留";
                }
            }
            return(tmp);
        }