/// <summary> /// 开关 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PowerButton_Click(object sender, EventArgs e) { Button powerBtn = (Button)sender; int groupId = 0; int addressId = 0; HelperTool.GetControllerAddressId(powerBtn.Tag.ToString(), out groupId, out addressId); currentControllerItem = GetCurrentController(groupId, addressId); if (currentControllerItem == null) { return; } byte powerByte = 0x01; if (currentControllerItem.PowerState) { powerByte = 0x00; powerBtn.BackgroundImage = Properties.Resources.powerOff; } else { powerBtn.BackgroundImage = Properties.Resources.powerOn; } currentControllerItem.PowerState = !currentControllerItem.PowerState; byte[] txData = { (byte)currentControllerItem.GroupId, (byte)currentControllerItem.AddressId, 0x10, 0x10, 0x01, powerByte }; SerialPortHelper.SendData(serialPort, txData); }
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e) { // 读取控制器信息 ComboBox comboBox = (ComboBox)sender; int groupId = 0; int addressId = 0; HelperTool.GetControllerAddressId(comboBox.Text, out groupId, out addressId); if (groupId == 0 || addressId == 0) { return; } ControllerItem selectedControllerItem = GetCurrentController(groupId, addressId); nameTextBox.Text = selectedControllerItem.Name; zoneTextBox.Text = selectedControllerItem.Zone; panel1.Visible = false; // 读取数据 ReadSelectedComData(groupId, addressId); }
private void DeleteButton_Click(object sender, EventArgs e) { if (MessageBox.Show("Confirm delete?", "Delete", MessageBoxButtons.YesNo) == DialogResult.No) { return; } // 删除控制器 Button powerBtn = (Button)sender; int groupId = 0; int addressId = 0; HelperTool.GetControllerAddressId(powerBtn.Tag.ToString(), out groupId, out addressId); controllerItems.RemoveAll(c => c.GroupId == groupId && c.AddressId == addressId); HelperTool.WriteControllersToFile <ControllerItem>(controllerItems.ToArray()); ReLoadControllerItems(); }
/// <summary> /// 设置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SettingButton_Click(object sender, EventArgs e) { Button settingBtn = (Button)sender; int groupId = 0; int addressId = 0; HelperTool.GetControllerAddressId(settingBtn.Tag.ToString(), out groupId, out addressId); currentControllerItem = GetCurrentController(groupId, addressId); if (currentControllerItem == null) { return; } SettingControllerForm settingControllerForm = new SettingControllerForm(serialPort, currentControllerItem, controllerItems.ToArray()); settingControllerForm.saveSetting = () => { // 刷新控制器列表 Invoke(reLoadControllerItems); }; settingControllerForm.ShowDialog(); }