public Form1() { InitializeComponent(); redis = ConnectionMultiplexer.Connect("localhost,abortConnect=false"); deviceList = new Dictionary <string, ACT12x>(); for (int x = 0; x < checkedListBoxChannel.Items.Count; x++) { this.checkedListBoxChannel.SetItemChecked(x, false); } dataQueue = new ConcurrentQueue <DataValue>(); backgroundWorkerSaveData = new BackgroundWorker(); signalBuffer = new float[WindowSize]; backgroundWorkerSaveData.WorkerSupportsCancellation = true; backgroundWorkerSaveData.DoWork += BackgroundWorkerSaveData_DoWork; window = RaisedCosineWindow.Hann(WindowSize); LoadDevices(); vact = null; saveDataSuccess = false; isStarted = false; ToolStripMenuItemStart.Enabled = true; ToolStripMenuItemStop.Enabled = false; }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedIndices != null && listView1.SelectedIndices.Count > 0) { ListView.SelectedIndexCollection c = listView1.SelectedIndices; List <string> checkedIndices = new List <string>(); foreach (ListViewItem item in listView1.CheckedItems) { checkedIndices.Add(item.SubItems[3].Text); } string tag = listView1.Items[c[0]].SubItems[3].Text; if (!checkedIndices.Contains(tag)) { return; } chart1.Titles[0].Text = listView1.Items[c[0]].SubItems[0].Text; string key = listView1.Items[c[0]].SubItems[2].Text; if (deviceList.ContainsKey(key)) { if (vact == null) { vact = deviceList[key]; vact.SetUpdateChart(true); } else { vact.SetUpdateChart(false); vact = deviceList[key]; vact.SetUpdateChart(true); } } } }
private void LoadDevices() { this.deviceList.Clear(); using (SQLiteConnection connection = new SQLiteConnection(database)) { connection.Open(); string strainStatement = "select RemoteIP,LocalPort,DeviceId,Type,Desc,Path,IsCalculateForce,Threshold,LocalIP from SensorInfo"; SQLiteCommand command2 = new SQLiteCommand(strainStatement, connection); using (SQLiteDataReader reader = command2.ExecuteReader()) { while (reader.Read()) { string remoteIP = reader.GetString(0); int localPort = reader.GetInt32(1); string deviceId = reader.GetString(2); string type = reader.GetString(3); string description = reader.GetString(4); string path = reader.GetString(5); bool isCalculateForce = bool.Parse(reader.GetString(6)); double threshold = reader.GetDouble(7); string loclaIP = reader.GetString(8); string[] itemString = { description, type, deviceId, remoteIP, localPort.ToString(), path, loclaIP }; ListViewItem item = new ListViewItem(itemString); item.Checked = true; listView1.Items.Add(item); ACT12x device = null; if (type == "ACT1228CableForce") { device = new ACT1228CableForce(deviceId, remoteIP, loclaIP, localPort, chart1, type, path, this.database, textBoxLog, threshold, redis); } else if (type == "ACT12816Vibrate") { device = new ACT12816Vibrate(deviceId, remoteIP, loclaIP, localPort, chart1, type, path, this.database, textBoxLog, threshold, redis); } else if (type == "ACT1228EarthQuake") { device = new ACT1228EarthQuake(deviceId, remoteIP, loclaIP, localPort, chart1, type, path, this.database, textBoxLog, threshold, redis); } else if (type == "ACT1228Vibrate") { device = new ACT1228Vibrate(deviceId, remoteIP, loclaIP, localPort, chart1, type, path, this.database, textBoxLog, threshold, redis); } else if (type == "ACT1228CableForceV4") { device = new ACT1228CableForceV4(deviceId, remoteIP, loclaIP, localPort, chart1, type, path, this.database, textBoxLog, threshold, redis); } else if (type == "ACT1228VibrateV4") { device = new ACT1228VibrateV4(deviceId, remoteIP, loclaIP, localPort, chart1, type, path, this.database, textBoxLog, threshold, redis); } else { } if (device != null) { this.deviceList.Add(deviceId, device); } } } strainStatement = "select ip,user,password,database,tableName from dbconfig"; SQLiteCommand command3 = new SQLiteCommand(strainStatement, connection); using (SQLiteDataReader reader2 = command3.ExecuteReader()) { while (reader2.Read()) { databaseIp = reader2.GetString(0); databaseUser = reader2.GetString(1); databasePwd = reader2.GetString(2); databaseName = reader2.GetString(3); databaseTable = reader2.GetString(4); } } connection.Close(); } }