private void btn_ACClose_Click(object sender, EventArgs e) //关闭自动清洁 { if (MainForm.handler != null && MainForm.handler.isConnected()) { MainForm.handler.SendData(DataSent.SetAutoClean(gw_SN, addr_Short, endpoint, 0)); } }
private void btn_SetAlarmV_Click(object sender, EventArgs e) //设置报警电压 { if (MainForm.handler != null && MainForm.handler.isConnected()) { MainForm.handler.SendData(DataSent.SetAlarmVoltage(gw_SN, addr_Short, endpoint, Decimal.ToInt32(num_alarmV.Value))); } }
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)); } }
private void btn_ACOpen_Click(object sender, EventArgs e) //开启自动清洁 { if (MainForm.handler != null && MainForm.handler.isConnected()) { MainForm.handler.SendData(DataSent.SetAutoClean(gw_SN, addr_Short, endpoint, Decimal.ToInt32(num_interval.Value))); } }
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)); } }
private void btn_SetSpeed_Click(object sender, EventArgs e) //风速调节 { if (MainForm.handler != null && MainForm.handler.isConnected()) { MainForm.handler.SendData(DataSent.SetSpeed(gw_SN, addr_Short, endpoint, Decimal.ToInt32(num_speed.Value))); } }
private void btn_getDevices_Click(object sender, EventArgs e) //获取设备 { if (handler != null && handler.isConnected()) { handler.SendData(DataSent.GetDevices(lab_SNID.Text)); } }
private void btn_netPermit_Click(object sender, EventArgs e) //允许入网 { if (handler != null && handler.isConnected()) { handler.SendData(DataSent.NetPermission(lab_SNID.Text)); } }
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));//获取状态数据 } }
private void dgv_gwIP_DoubleClick(object sender, EventArgs e) //双击连接网关设备 { if (dgv_gwIP.RowCount > 0 && dgv_gwIP.CurrentCell.Value != null) { lab_SNID.Text = dgv_gwIP.CurrentRow.Cells[0].Value.ToString(); lab_IP.Text = dgv_gwIP.CurrentRow.Cells[1].Value.ToString(); } else { return; } IPAddress ip; try { ip = IPAddress.Parse(lab_IP.Text);//当前网关设备IP地址是否合法 } catch (Exception error) { MessageBox.Show("<当前网关设备IP地址输入格式错误> " + error.Message, "系统提示"); return; } handler = new TCPHandler(lab_IP.Text, 8001); Thread.Sleep(100); if (handler != null && handler.isConnected()) { lab_Fans.Text = "" + dgv_fanList.RowCount; lab_Connected.Text = "已连接"; dgv_gwIP.Enabled = false; Timer_Received.Enabled = true; menu_stop_Click(sender, e); //停止搜索网关设备 Thread.Sleep(100); handler.SendData(DataSent.GetDevices(lab_SNID.Text)); //获取当前连接的所有设备 } else { lab_IP.Text = "0.0.0.0"; lab_SNID.Text = ""; lab_Fans.Text = "0"; lab_Connected.Text = "未连接"; dgv_gwIP.Enabled = true; Timer_Received.Enabled = false; MessageBox.Show("连接失败,请重试!", "系统提示"); } }
private void btn_ACClose_Click(object sender, EventArgs e) //组操作——关闭自动清洁 { if (handler != null && handler.isConnected()) { foreach (Fan fan in this.GroupFanList.Values) { string gw_SN = lab_SNID.Text; string addr_Short = fan.ShorAddress; string endpoint = fan.EndPoint; handler.SendData(DataSent.SetAutoClean(gw_SN, addr_Short, endpoint, 0)); Thread.Sleep(100); } } }
private void btn_SetAlarmV_Click(object sender, EventArgs e) //组操作——设置报警电压 { if (handler != null && handler.isConnected()) { foreach (Fan fan in this.GroupFanList.Values) { string gw_SN = lab_SNID.Text; string addr_Short = fan.ShorAddress; string endpoint = fan.EndPoint; handler.SendData(DataSent.SetAlarmVoltage(gw_SN, addr_Short, endpoint, Decimal.ToInt32(num_alarmV.Value))); Thread.Sleep(100); } } }
private void cMenu_Delete_Click(object sender, EventArgs e) //删除指定设备 { if (dgv_fanList.RowCount > 0) { string addr_Short = dgv_fanList.CurrentRow.Cells[8].Value.ToString(); string addr_IEEE = ""; if (dgv_fanList.CurrentRow.Cells[9].Value != null) { addr_IEEE = dgv_fanList.CurrentRow.Cells[9].Value.ToString(); } string endpoint = dgv_fanList.CurrentRow.Cells[10].Value.ToString(); if (handler != null && handler.isConnected()) { handler.SendData(DataSent.DeleteDevice(lab_SNID.Text, addr_Short, addr_IEEE, endpoint)); FanList.Remove(addr_Short); DeleteElementFromDocument(addr_Short); Refresh_FanList(); } } }
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 = "更新设备状态成功!"; }