public void PrintLogRecordToFile(ClassDevice device, List <float> pressuresUnderTest, string path, byte tempIndex) { string path1 = path + @"\" + device.CSVFileName; file = new StreamWriter(path1, true); if (file != null) { //write temp header string line = string.Format(",,,Temp#{0},", tempIndex); file.WriteLine(line); line = ",PLC_Pressure,A2D_Right,A2D_Left,A2D Delta,Temp on DP,"; file.WriteLine(line); for (int i = 0; i < pressuresUnderTest.Count; i++) { line = string.Format("Pressure {0} = {1}[bar]", i, pressuresUnderTest[i]); line += "," + device.CalibrationData[tempIndex, i].extA2dPressureValue; line += "," + device.CalibrationData[tempIndex, i].RightA2DValue; line += "," + device.CalibrationData[tempIndex, i].LeftA2DValue; line += "," + Math.Abs(device.CalibrationData[tempIndex, i].RightA2DValue - device.CalibrationData[tempIndex, i].LeftA2DValue); line += "," + device.CalibrationData[tempIndex, i].tempOnDevice; file.WriteLine(line); } file.WriteLine(""); file.WriteLine(""); file.Close(); } }
void DetectDevicesTask() { while (DetectFlag) { classDevices = null; classDevices = new ClassDevice[MAX_DP_DEVICES]; DpCountAxist = 0; classCalibrationSettings.ConnectedChanels.Clear(); for (int i = 0; i < classCalibrationSettings.JigConfiguration; i++) { bool Ch = new bool(); classMultiplexingInstanse.ConnectDpDevice((byte)i); Thread.Sleep(250); classDpCommunicationInstanse.NewDpInfoEvent = false; classDpCommunicationInstanse.DPgetDpInfo(); Thread.Sleep(300); //classDpCommunicationInstanse.NewDpInfoEvent = true; if (classDpCommunicationInstanse.NewDpInfoEvent) // check if recieve data from DP { classDpCommunicationInstanse.NewDpInfoEvent = false; if (classDpCommunicationInstanse.dpInfo.DeviceSerialNumber == "" || classDpCommunicationInstanse.dpInfo.DeviceSerialNumber.StartsWith("\0")) { continue; } ClassDevice newDeviceExist = new ClassDevice(); newDeviceExist.PositionOnBoard = i; newDeviceExist.BoardNumber = (i >= 0 && i < 8) ? 1 : 2; newDeviceExist.DeviceMacAddress = classDpCommunicationInstanse.dpInfo.DeviseMacAddress; newDeviceExist.DeviceSerialNumber = classDpCommunicationInstanse.dpInfo.DeviceSerialNumber; classDevices[DpCountAxist] = newDeviceExist; UpdatePressAndTempOnDPBeforCalib(newDeviceExist); DpCountAxist++; Ch = true; classCalibrationSettings.ConnectedChanels.Add(Ch); } else { Ch = false; classCalibrationSettings.ConnectedChanels.Add(Ch); } } DetectFlag = false; EndDetectEvent = true; } DetectDevicesTaskHandlerThread = null; }
void UpdatePressAndTempOnDPBeforCalib(ClassDevice deviceToUpdate) { for (int i = 0; i < classCalibrationSettings.TempUnderTestList.Count; i++) { for (int j = 0; j < classCalibrationSettings.PressureUnderTestList.Count; j++) { DpCalibPointData newPoint = new DpCalibPointData(); //newPoint.pressureUnderTest = PressureUnderTestList[j]; //newPoint.tempUnderTest = TempUnderTestList[i]; deviceToUpdate.CalibrationData[i, j] = newPoint; } } }
public string PrintLogRecordToFile(ClassDevice device, List <float> pressuresUnderTest, string path, byte tempIndex) { string path1 = path + @"\" + device.CSVFileName; try { file = new StreamWriter(path1, true); } catch { return("Log error: fail to open " + device.CSVFileName + " file to logging\r\nCheck Device name is correct!\r\n" + "Current device position is " + device.PositionOnBoard); } if (file != null) { //write temp header string line = string.Format(",,,Temp#{0},", tempIndex); file.WriteLine(line); line = ",TIME,PLC_Pressure,A2D_Right,A2D_Left,A2D Delta,Temp on DP,"; file.WriteLine(line); for (int i = 0; i < pressuresUnderTest.Count; i++) { line = device.CalibrationData[tempIndex, i].time.ToString(); line += "," + string.Format("Pressure {0} = {1}[bar]", i, pressuresUnderTest[i]); line += "," + device.CalibrationData[tempIndex, i].extA2dPressureValue; line += "," + device.CalibrationData[tempIndex, i].RightA2DValue; line += "," + device.CalibrationData[tempIndex, i].LeftA2DValue; line += "," + Math.Abs(device.CalibrationData[tempIndex, i].RightA2DValue - device.CalibrationData[tempIndex, i].LeftA2DValue); line += "," + device.CalibrationData[tempIndex, i].tempOnDevice; file.WriteLine(line); } file.WriteLine(""); file.WriteLine(""); file.Close(); } return(""); }
public string OpenFileForLogging(List <float> pressuresUnderTeat, string path, ClassDevice dpDevice) { string title1 = ","; DateTime now = DateTime.Now; sPath = path; logFileName = string.Format("{0:0000}_{1:00}_{2:00}_{3:00}_{4:00}_{5:00}_{6}", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, dpDevice.DeviceSerialNumber) + ".csv"; dpDevice.CSVFileName = logFileName; CreateDirectoryIfNotExist(path); try { file = new StreamWriter(path + @"\" + logFileName, false); file.WriteLine(""); title1 = string.Format("DP Name(SN),{0}", dpDevice.DeviceSerialNumber); file.WriteLine(title1); title1 = string.Format("MAC address,{0}", dpDevice.DeviceMacAddress); file.WriteLine(title1); title1 = string.Format("Calibration date,{0}", now); file.WriteLine(title1); file.WriteLine(""); file.WriteLine(""); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return(logFileName); }
private void SendCalibPointToDp(ClassDevice CurrentCalibDevice) { }
private void CalibrationTask() { while (DoCalibration) { while (!CalibrationPaused && DoCalibration) { UpdateRealTimeData(); switch (CurrentState) { case StateStartCalib: { CurrentCalibDevice = classDevices[CurrentCalibDeviceIndex]; StateChangeState(StateSendTempSetPoints); CurrentCalibPressureIndex = 0; CurrentCalibTempIndex = 0; CriticalStates = true; } break; case StateSendPressureSetPoints: { CriticalStates = true; if (CurrentCalibPressureIndex > 0) { List <Int16> SetPointPressure = new List <short>(); SetPointPressure.Add(PlcBar2Adc(classCalibrationSettings.PressureUnderTestList[CurrentCalibPressureIndex])); classDeltaProtocolInstanse.classDeltaWriteSetpoint(SetPointPressure); TimeFromSetPressurePointRequest = DateTime.Now; StateChangeState(StateWaitToSetPressureStable); IncermentCalibPointStep = true; } else { // noo need set 0 bar becouse i still set when i sent temp setpoint. TimeFromSetPressurePointRequest = DateTime.Now; StateChangeState(StateWaitToSetPressureStable); IncermentCalibPointStep = true; } } break; case StateSendTempSetPoints: { // send 0[bar] to PLC comtroller VentToRead0Bar(); // vent system after finish calib. WriteTempSetPoint(TEMP_SET_POINT_1_REGISTER_ADDRESSS, classCalibrationSettings.TempUnderTestList[CurrentCalibTempIndex]); SelectSetPoint(TEMP_SELECT_SET_POINT_REGISTER_ADDRESSS, 0); TimeFromSetTempPointRequest = DateTime.Now; CriticalStates = false; ////TIME TO TEMP STABLE ERROR = CURRENT SKIP TIME + ERROR TIMEOUT //classCalibrationSettings.TempToTimoutError += StateChangeState(StateWaitToSetTempStable); } break; case StateWaitToSetPressureStable: { if (CheckTimout(TimeFromSetPressurePointRequest, MAX_TIME_WAIT_TO_PRESSURE_SET_POINT)) { PressureTimoutErrorEvent = true; ResetPressureAndTemp(); StateChangeState(StatePressureStableError); } else if (PressureStableFlag) { if (classCalibrationSettings.PressureAutoMode) { StateChangeState(StateRunOfAllDp); } else { classCalibrationSettings.AlertToTechnican = true; StateChangeState(StateWaitToTechnicanApprovePressure); } } else if (Pressure0AfterVentStable && CurrentCalibPressureIndex == 0) { Pressure0AfterVentStable = false; StateChangeState(StateRunOfAllDp); } } break; case StateWaitToTechnicanApprovePressure: { if (classCalibrationSettings.TechnicianApproveGoNext) { classCalibrationSettings.TechnicianApproveGoNext = false; StateChangeState(StateRunOfAllDp); } } break; case StateWaitToSetTempStable: { // timout error -> current skip time + max time wait to temp if (CheckTimout(TimeFromSetTempPointRequest, classCalibrationSettings.MaxTimeWaitToTemp + classCalibrationSettings.TempSkipStartTime[CurrentCalibTempIndex])) { StateChangeState(StateTempStableError); ResetPressureAndTemp(); TempTimoutErrorEvent = true; } else //if (CheckTimout(TimeFromSetTempPointRequest, 1))//debug mode if (CheckTimout(TimeFromSetTempPointRequest, classCalibrationSettings.TempSkipStartTime[CurrentCalibTempIndex])) { if (CheckTempStableOnOneDp(classCalibrationSettings.TempDeltaRange)) { StateChangeState(StateSendPressureSetPoints); } else { Thread.Sleep(TEMP_WAIT_BETWEEN_TOW_SMPLINGS_CYCLE * 1000); } } //StateChangeState(StateSendPressureSetPoints); } break; case StateTempStableError: { if (NextAfterTempTimoutErrorEvent) { StateChangeState(StateSendTempSetPoints); NextAfterTempTimoutErrorEvent = false; } } break; case StateRunOfAllDp: { ConnectingToDP = true; WriteReadInfoFromDp(); //loop of all dp's ConnectingToDP = false; StateChangeState(StateEndOneCalibPoint); } break; case StateEndOneCalibTemp: { CurrentCalibPressureIndex = 0; WriteOneLineToFile(); //write line to csv file if (CurrentCalibTempIndex < classCalibrationSettings.TempUnderTestList.Count - 1) { CurrentCalibTempIndex++; StateChangeState(StateSendTempSetPoints); } else { StateChangeState(StateFinishAllCalibPoint); } } break; case StateEndOneCalibPoint: { PressureStableFlag = false; if (CurrentCalibPressureIndex < classCalibrationSettings.PressureUnderTestList.Count - 1) { CurrentCalibPressureIndex++; StateChangeState(StateSendPressureSetPoints); } else { StateChangeState(StateEndOneCalibTemp); } } break; case StateFinishAllCalibPoint: { DoCalibration = false; FinishCalibrationEvent = true; ResetPressureAndTemp(); StateChangeState(StateStartCalib); } break; case StatePressureStableError: { if (NextAfterPressureTimoutErrorEvent) { StateChangeState(StateSendPressureSetPoints); NextAfterPressureTimoutErrorEvent = false; } } break; } } CalibrationTaskHandlerThread = null; } CriticalStates = false; }
private void bt_next_Click(object sender, EventArgs e) { if (Properties.Settings.Default.StationType == "CalibrationStation") { if (calibForm == null) { //MultiplexingIncomingInformation MultiplexingInfo = new MultiplexingIncomingInformation(); //classMultiplexing classMultiplexing = new classMultiplexing(Properties.Settings.Default.multiplexingComPort, 115200, MultiplexingInfo); //DpIncomingInformation DPinfo = new DpIncomingInformation(); //ClassDpCommunication ClassDpCommunication = new ClassDpCommunication(Properties.Settings.Default.dpComPort, 115200, DPinfo); //tempControllerInstanse = new TempControllerProtocol(Properties.Settings.Default.TempControllerComPort, 9600); //DeltaIncomingInformation PLCinfo = new DeltaIncomingInformation(); //classDeltaProtocol ClassDeltaProtocol = new classDeltaProtocol(Properties.Settings.Default.plcComPort, 9600, PLCinfo); //classCalibrationInfo = new ClassCalibrationInfo(tempControllerInstanse, ClassDpCommunication, classMultiplexing, ClassDeltaProtocol); //calibForm = new CalibForm(classCalibrationInfo); } } else if (Properties.Settings.Default.StationType == "ProgramStation") { if (progForm == null) { DeltaIncomingInformation PLCinfo = new DeltaIncomingInformation(); classDeltaProtocol ClassDeltaProtocol = new classDeltaProtocol(Properties.Settings.Default.plcComPort, 9600, PLCinfo); MultiplexingIncomingInformation MultiplexingInfo = new MultiplexingIncomingInformation(); classMultiplexing classMultiplexing = new classMultiplexing(Properties.Settings.Default.multiplexingComPort, 115200, MultiplexingInfo); DpIncomingInformation DPinfo = new DpIncomingInformation(); ClassDpCommunication ClassDpCommunication = new ClassDpCommunication(Properties.Settings.Default.dpComPort, 115200, DPinfo); tempControllerInstanse = new TempControllerProtocol(Properties.Settings.Default.TempControllerComPort, 9600); classCalibrationInfo = new ClassCalibrationInfo(tempControllerInstanse, ClassDpCommunication, classMultiplexing, ClassDeltaProtocol); progForm = new ProgForm(classCalibrationInfo, this); } } classCalibrationInfo.DpCountAxist = 0; for (int i = 0; i <= MAX_DP_DEVICES; i++) { if (dgv_registerDpPacket.Rows[i].Cells[1].Value == null) { break; } if ((bool)dgv_registerDpPacket.Rows[i].Cells[1].Value == false) { break; } ClassDevice NewExistDevice = new ClassDevice(); classCalibrationInfo.DpCountAxist++; if (dgv_registerDpPacket.Rows[i].Cells[2].Value != null) { NewExistDevice.DeviceSerialNumber = dgv_registerDpPacket.Rows[i].Cells[2].Value.ToString(); } classCalibrationInfo.classDevices[i] = NewExistDevice; } string UpdateMassege = string.Format("{0} DP devices added.", classCalibrationInfo.DpCountAxist.ToString()); MessageBox.Show(UpdateMassege); this.Hide(); if (Properties.Settings.Default.StationType == "CalibrationStation") { calibForm.Show(); } else if (Properties.Settings.Default.StationType == "ProgramStation") { progForm.Show(); } }