private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (_deviceHandle > 0) { RelayDeviceWrapper.usb_relay_device_close(_deviceHandle); } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (_deviceHandle > 0) { RelayDeviceWrapper.usb_relay_device_close(_deviceHandle); _deviceHandle = 0; } for (int i = 0; i < _buttonList.Count; i++) { _buttonList[i].BackColor = BackColor; _buttonList[i].Enabled = false; } var lb = (ListBox)sender; usb_relay_device_info device = (usb_relay_device_info)lb.SelectedItem; _deviceHandle = RelayDeviceWrapper.usb_relay_device_open(ref device); int numberOfRelays = (int)device.type; uint status = 0; RelayDeviceWrapper.usb_relay_device_get_status(_deviceHandle, ref status); for (int i = 0; i < numberOfRelays; i++) { _buttonList[i].Enabled = true; if (status > numberOfRelays) { _buttonList[i].BackColor = Color.Red; } else if (i + 1 == status) { _buttonList[i].BackColor = Color.Red; } } }