Exemplo n.º 1
0
 private void btn_off_Click(object sender, EventArgs e)  //关闭离子风机
 {
     if (MainForm.handler != null && MainForm.handler.isConnected())
     {
         MainForm.handler.SendData(DataSent.GetSendData(gw_SN, addr_Short, endpoint, 0x11));
     }
 }
Exemplo n.º 2
0
 private void btn_setAuto_Click(object sender, EventArgs e)  //切换为自动模式
 {
     if (MainForm.handler != null && MainForm.handler.isConnected())
     {
         MainForm.handler.SendData(DataSent.GetSendData(gw_SN, addr_Short, endpoint, 0x21));
     }
 }
Exemplo n.º 3
0
        private void DeviceForm_Load(object sender, EventArgs e)
        {
            lab_devName.Text = dev_Name;

            if (MainForm.handler != null && MainForm.handler.isConnected())
            {
                MainForm.handler.SendData(DataSent.GetSendData(gw_SN, addr_Short, endpoint, 0x00));//获取状态数据
            }
        }
Exemplo n.º 4
0
        private void Parse_DeviceState(byte[] data) //处理返回的设备状态数据
        {
            if (data.Length != 35)
            {
                return;
            }
            else if (data.Length != data[1] + 2)
            {
                TCPHandler.State = "更新设备状态失败!";
                return;
            }

            //短地址
            byte[] tmp        = data.Skip(2).Take(2).ToArray();
            string addr_short = tmp[0].ToString("X2") + tmp[1].ToString("X2");

            //string addr_short = System.Text.Encoding.Default.GetString(tmp);

            //EndPoint
            tmp = data.Skip(4).Take(1).ToArray();
            string endpoint = tmp[0].ToString("X2");

            //string endpoint = System.Text.Encoding.Default.GetString(tmp);

            //RealData
            byte[] data_real;
            if (data[12] == 0x68 && data[15] == 0x80 && data[16] == 0x2F)   //设备状态数据
            {
                data_real = data.Skip(17).Take(17).ToArray();

                //版本信息
                string ver_hard = "" + data_real[0];
                string ver_soft = "" + data_real[1];

                //运行时间
                tmp = data_real.Skip(3).Take(2).ToArray();
                string work_time = "" + BitConverter.ToInt16(tmp, 0);

                //风机运行状态
                string work_mode      = (data_real[9] & 1) == 1?"自动":"手动";
                string fan_state      = (data_real[9] & 64) == 64 ? "打开" : "关闭";
                string pressure_state = (data_real[9] & 128) == 128 ? "打开" : "关闭";

                //工作电压
                tmp = data_real.Skip(10).Take(2).ToArray();
                string work_voltage = "";
                if ((tmp[1] & 128) == 128)
                {
                    tmp[1]      -= 128;
                    work_voltage = "-" + BitConverter.ToInt16(tmp, 0);
                }
                else
                {
                    work_voltage = "" + BitConverter.ToInt16(tmp, 0);
                }

                work_voltage = Convert.ToString(int.Parse(work_voltage) / 1000);

                //离子风机风速
                string fan_speed = "" + data_real[12];

                //设备ID
                tmp = data_real.Skip(13).Take(2).ToArray();
                string device_id = tmp[0].ToString("X2") + tmp[1].ToString("X2");

                //自动清洁间隔
                string autoclean_interval = "" + data_real[15];

                //报警电压
                string alarm_voltage = "" + data_real[16];

                Update_XmlDataBase(addr_short, device_id);

                if (FanList.Keys.Contains <string>(addr_short) == true)
                {
                    Fan fan = new Fan();
                    FanList.TryGetValue(addr_short, out fan);

                    fan.FanState          = fan_state;
                    fan.PressureState     = pressure_state;
                    fan.BalanceVoltage    = work_voltage;
                    fan.DeviceID          = device_id;
                    fan.AutoCleanInterval = autoclean_interval;
                    fan.AlarmVoltage      = alarm_voltage;

                    FanList[addr_short] = fan;

                    Refresh_FanList();
                }

                if (FormState == true && addr_short == DeviceForm.addr_Short)
                {
                    DeviceForm.hard_Version       = ver_hard;
                    DeviceForm.soft_Version       = ver_soft;
                    DeviceForm.work_Time          = work_time;
                    DeviceForm.bal_Voltage        = work_voltage;
                    DeviceForm.fan_Speed          = fan_speed;
                    DeviceForm.autoClean_Interval = autoclean_interval;
                    DeviceForm.alarm_Voltage      = alarm_voltage;
                    DeviceForm.work_Mode          = work_mode;
                    DeviceForm.fan_State          = fan_state;
                    DeviceForm.pressure_State     = pressure_state;
                }
            }
            else if (data[12] == 0x68 && data[15] == 0xC8 && data[16] == 0x00)  //设备异常状态数据
            {
                string device_voltage  = (data[17] & 1) == 1? "异常" : "正常";
                string device_electric = (data[17] & 2) == 2 ? "异常" : "正常";
                string balance_voltage = (data[17] & 4) == 4 ? "异常" : "正常";
                string fan_error       = (data[17] & 8) == 8 ? "异常" : "正常";
                string device_id       = data[19].ToString("X2") + data[20].ToString("X2");

                Update_XmlDataBase(addr_short, device_id);

                if (FanList.Keys.Contains(addr_short))
                {
                    Fan fan = new Fan();
                    FanList.TryGetValue(addr_short, out fan);

                    fan.PressureError = device_voltage;
                    fan.FanError      = fan_error;
                    fan.DeviceID      = device_id;

                    FanList[addr_short] = fan;

                    Refresh_FanList();
                }

                if (FormState == true && addr_short == DeviceForm.addr_Short)
                {
                    DeviceForm.error_Voltage  = device_voltage;
                    DeviceForm.error_Electric = device_electric;
                    DeviceForm.error_Bal      = balance_voltage;
                    DeviceForm.error_Fan      = fan_error;
                }

                if (handler != null && handler.isConnected())   //回复接收到异常上报数据
                {
                    handler.SendData(DataSent.GetSendData(lab_SNID.Text, addr_short, endpoint, 0x30));
                }
            }
            else
            {
                return;
            }

            TCPHandler.State = "更新设备状态成功!";
        }