private void readSensorData() { /* * Read Data From Memory */ tBtn_WriteSensorData.IsEnabled = false; tBtn_ReadSensorData.IsEnabled = false; int blockNum = FILESIZE / (int)INNCOM_CONF.SZ_MAX_MEMORY_BLOCK; int eepAddr = 0; int dataLen = 0; tPbar_DataDownBar.Maximum = blockNum; tPbar_DataDownBar.Value = 0; byte[] EEP_Data = new byte[(int)INNCOM_CONF.SZ_EEP_MEMORY]; for (int i = 0; i <= blockNum; i++) { if (i < blockNum) { dataLen = (int)INNCOM_CONF.SZ_MAX_MEMORY_BLOCK; } else { dataLen = FILESIZE - (int)INNCOM_CONF.SZ_MAX_MEMORY_BLOCK * i; if (dataLen == 0) { break; } } byte[] payload = new byte[6]; payload[0] = (int)INNCOM_CONF.MEM_TYPE_EEPROM; payload[1] = (byte)(eepAddr >> 24); payload[2] = (byte)(eepAddr >> 16); payload[3] = (byte)(eepAddr >> 8); payload[4] = (byte)eepAddr; payload[5] = (byte)dataLen; byte[] result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_DATA_FROM_MEM, payload, ref err, 500); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - READ eerpom : " + eepAddr); tTxt_Logs.AppendText(Environment.NewLine); tBtn_WriteSensorData.IsEnabled = true; tBtn_ReadSensorData.IsEnabled = true; return; } int offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + (int)PACKET_CONF.COMM_RESPONSE_SZ; int dataToRead = result[offset]; Array.Copy(result, offset + 1, EEP_Data, eepAddr, dataToRead); eepAddr += dataLen; tPbar_DataDownBar.Value = i + 1; tTxt_Logs.AppendText("Read eeprom : " + eepAddr); tTxt_Logs.AppendText(Environment.NewLine); Dispatcher.Invoke((ThreadStart)(() => { }), System.Windows.Threading.DispatcherPriority.ApplicationIdle); Thread.Sleep(50); } tBtn_WriteSensorData.IsEnabled = true; tBtn_ReadSensorData.IsEnabled = true; datas = new LogToFile("Incom_Sensor_Dater", "bin"); if (datas.Checked() != null) { try { datas.Write(EEP_Data, 0, eepAddr); datas.Unchecked(); } catch { tTxt_Logs.AppendText("Save Sensor Data : "); tTxt_Logs.AppendText(Environment.NewLine); } } tTxt_Logs.AppendText("Successfully saved"); tTxt_Logs.AppendText(Environment.NewLine); }
private void saveToCSV() { int eventType = tCmb_LogsType.SelectedIndex + 1; List <UIDataGrid> gridList; DataGrid grid; switch (eventType) { case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_CALIBRATION: { logFiles = new LogToFile("Incom_Utility_Calibration_Log", "csv"); grid = grid_LogCal; gridList = logCalList; break; } case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_ALARM: { logFiles = new LogToFile("Incom_Utility_Alarm_Log", "csv"); grid = grid_LogAlarm; gridList = logAlarmList; break; } case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_FAULT: { logFiles = new LogToFile("Incom_Utility_Fault_Log", "csv"); grid = grid_LogFault; gridList = logFaultList; break; } case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_WARNING: { logFiles = new LogToFile("Incom_Utility_Warining_Log", "csv"); grid = grid_LogWarning; gridList = logWarningList; break; } case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_REFLEX: { logFiles = new LogToFile("Incom_Utility_Reflex_Log", "csv"); grid = grid_LogRelfex; gridList = logReflexList; break; } case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_INFO: { logFiles = new LogToFile("Incom_Utility_Info_Log", "csv"); grid = grid_LogInfo; gridList = logInfoList; break; } default: { return; } } string filePath = logFiles.Checked(); if (filePath == null) { return; } string strHeader = ""; int columCount = grid.Columns.Count; for (int i = 0; i < columCount; i++) { if (i == grid.Columns.Count - 1) { strHeader += grid.Columns[i].Header.ToString(); break; } strHeader += grid.Columns[i].Header.ToString() + ","; } logFiles.SetDataHeader(strHeader); for (int i = 0; i < gridList.Count; i++) { string strWrite = UIDataGrid.getDataToStr(gridList[i], columCount); logFiles.Write(strWrite); } logFiles.Unchecked(); MessageBox.Show("Saved CSV file"); }