示例#1
0
        public static LotInfo ReadMeasurementFileHeader(string outputFilePath)
        {
            var lotInfo = new LotInfo();

            using (var outputFile = new StreamReader(outputFilePath))
            {
                var line = outputFile.ReadLine() ?? throw new Exception("Fisierul de masuratori e gol!");
                {
                    if (!line.Contains("#;Cantitatea Cantarita [Cc];Ora"))
                    {
                        throw new Exception("Headerul fisierului de masuratori are un format necunoscut!");
                    }


                    var splitLine = line.Split(';');

                    lotInfo.Lot          = splitLine[3];
                    lotInfo.ProductName  = splitLine[4];
                    lotInfo.Package.Type = splitLine[5];

                    var netWeight = splitLine[6];
                    lotInfo.Package.NetWeight = Misc.GetValueInGrams(netWeight);

                    var tare = splitLine[7];
                    lotInfo.Package.Tare = Misc.GetValueInGrams(tare);

                    lotInfo.Date = splitLine[8];
                }
            }

            return(lotInfo);
        }
示例#2
0
 private void InitializeInputControls()
 {
     dataTable.Rows.Clear();
     dataGridViewMeasurements.Refresh();
     lotInfo = new LotInfo();
     uctlLotData.InitializeInputControls();
 }
示例#3
0
        public LotInfo ReadLotInfoFromLog(string logFilePath)
        {
            var lotInfoFound = false;

            var lotInfo = new LotInfo();

            using (var file = new StreamReader(logFilePath))
            {
                var line = "";
                while ((line = file.ReadLine()) != null)
                {
                    if (line.Contains("### Lot Info ###"))
                    {
                        lotInfo.Lot               = GetLotInfoValueString(file, "Lot");
                        lotInfo.ProductName       = GetLotInfoValueString(file, "Product Name");
                        lotInfo.Package.Type      = GetLotInfoValueString(file, "Package");
                        lotInfo.Package.NetWeight = GetLotInfoValueDouble(file, "Net Weight");
                        lotInfo.Package.Tare      = GetLotInfoValueDouble(file, "Tare");
                        lotInfo.ZeroThreshold     = GetLotInfoValueDouble(file, "Zero Threshold");
                        lotInfo.Date              = GetLotInfoValueString(file, "Date");

                        lotInfoFound = true;
                        break;
                    }
                }

                if (!lotInfoFound)
                {
                    log.Error("No Lot Info found!");
                }
            }

            return(lotInfo);

            string GetLotInfoValueString(StreamReader file, string attributeName)
            {
                var line = file.ReadLine();

                if (line == null)
                {
                    return("");
                }

                attributeName += ": ";
                var splitLine = line.Split(new[] { attributeName }, StringSplitOptions.None);

                return(splitLine[1]);
            }

            double GetLotInfoValueDouble(StreamReader file, string attributeName)
            {
                var rawValue     = GetLotInfoValueString(file, attributeName);
                var valueInGrams = Misc.GetValueInGrams(rawValue);

                return(valueInGrams);
            }
        }
示例#4
0
 private void LogLotInfo(LotInfo lotInfo)
 {
     log.Info("### Lot Info ###");
     log.Info("Lot: " + lotInfo.Lot);
     log.Info("Product Name: " + lotInfo.ProductName);
     log.Info("Package: " + lotInfo.Package.Type);
     log.Info("Net Weight: " + lotInfo.Package.NetWeight);
     log.Info("Tare: " + lotInfo.Package.Tare);
     log.Info("Zero Threshold: " + zeroThreshold);
     log.Info("Date: " + lotInfo.Date + Environment.NewLine);
 }
示例#5
0
        public void SetLotInfo(LotInfo lotInfo)
        {
            LotInfo = lotInfo ?? throw new ArgumentNullException(nameof(lotInfo));

            txtLot.Text            = LotInfo.Lot;
            cbProduct.SelectedItem = LotInfo.ProductName;
            cbPackage.SelectedItem = LotInfo.Package.Type;
            txtPackageTare.Text    = (LotInfo.Package.Tare != 0) ? LotInfo.Package.Tare / 1000 + "Kg" : "";

            // Tare validated() event will fill Nominal Weight
        }
示例#6
0
        public void PrepareOutputFile(string folderPath, LotInfo lotInfo)
        {
            CalculatePaths(folderPath, lotInfo.Id, lotInfo.AppendToLot);

            if (appendToExistingOutputFile)
            {
                return;
            }

            var fileHeader = lotInfo.MakeMeasurementFileHeader();

            InitializeOutputFileContents(OutputFilePath, fileHeader);
        }
示例#7
0
        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();
        }
示例#8
0
 // Make sure we do noy use an old object
 public void InitializeLotInfo()
 {
     LotInfo = new LotInfo();
 }