private void ReadThread() { readPort = new MySerialReader(Measurements, 5000); }
void btnStart_Click(object sender, EventArgs e) { stopPressed = false; btnPause.Enabled = false; if (!uctlLotData.AreInputControlsValid()) { return; } lotInfo = uctlLotData.LotInfo; lotInfo.Date = DateTime.Now.ToString("yyyy-MM-dd"); netWeight = lotInfo.Package.NetWeight; measurementTolerance = (netWeight * Settings.Default.MeasurementTollerace) / 100; zeroThreshold = (netWeight * Settings.Default.ZeroThreshold) / 100; // for each LOT save logs in separate files. (If a log file was already created for a lot reuse it) if (CsvHelper.LogAlreadyPresent(lotInfo.Id, logFolderPath, ref logFilePath)) { DialogResult result = MessageBox.Show("Pentru lotul selectat exista deja masuratori. Noile masuratori se vor adauga celor existente. Doriti sa Continuati?", "Continuare Lot", MessageBoxButtons.YesNo); if (result != DialogResult.Yes) { return; } log.ChangeLoggingFile(logFilePath); lotInfo.AppendToLot = true; log.Info("Button Start Clicked" + Environment.NewLine); log.Info("### Lot " + lotInfo.Id + " Resumed on " + lotInfo.Date + " ###"); } else { logFilePath = logFolderPath + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_" + lotInfo.Id + ".log"; log.ChangeLoggingFile(logFilePath); lotInfo.AppendToLot = false; log.Info("Button Start Clicked" + Environment.NewLine); LogLotInfo(lotInfo); } var CSVOutputFolderPath = Path.Combine(Misc.AssemblyPath, Settings.Default.CSVOutputPath); csvHelper = new CsvHelper(); csvHelper.PrepareOutputFile(CSVOutputFolderPath, lotInfo); readPort?.Dispose(); readPort = new MySerialReader(Measurements, zeroThreshold); // Code for Start Reading in a new Thread //readThread?.Abort(); //readThread = new Thread(new ThreadStart(ReadThread)); //readThread.Start(); Thread.Sleep(100); if (simulationEnabled) { writePort?.Dispose(); writeThread?.Abort(); writeThread = new Thread(WriteThread); writeThread.Start(); } btnStart.Enabled = false; btnPause.Enabled = true; btnStopLot.Enabled = true; uctlLotData.DisableInputControls(); }