Ejemplo n.º 1
0
        private IEnumerable <JobLogDB.EventLogMaterial> CreateUnloadMaterial(MessageState state, string pal, IReadOnlyList <LogEntry> oldEvents = null)
        {
            var    oldMat   = FindMaterial(pal, oldEvents)[0];
            var    ret      = new List <JobLogDB.EventLogMaterial>();
            string partName = "";
            int    count    = 1;

            if (state.PartCompletedMessagesBySetup.Count > 0)
            {
                // use highest setup value
                var msgs = state.PartCompletedMessagesBySetup.ElementAt(state.PartCompletedMessagesBySetup.Count - 1).Value;
                count    = msgs.Count;
                partName = msgs[0].PartName;
            }
            Log.Debug("During unload, found {cnt} parts with name {part} that were unloaded/completed",
                      count, partName);

            _log.SetDetailsForMaterialID(oldMat.MaterialID, null, partName, null);

            if (_settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerCycle ||
                _settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerMaterial
                )
            {
                _log.RecordSerialForMaterialID(oldMat, _settings.ConvertMaterialIDToSerial(oldMat.MaterialID).PadLeft(_settings.SerialLength, '0'), state.LastSeenMessage.TimeUTC);
            }
            ret.Add(oldMat);

            var oldMatDetails = _log.GetMaterialDetails(oldMat.MaterialID);

            //allocate new materials, one per completed part in addition to the existing one
            for (int i = 1; i < count; i++)
            {
                var newId  = _log.AllocateMaterialID(oldMatDetails.JobUnique, oldMatDetails.PartName, 1);
                var newMat = new JobLogDB.EventLogMaterial()
                {
                    MaterialID = newId,
                    Process    = 1,
                    Face       = ""
                };
                if (_settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerCycle)
                {
                    _log.RecordSerialForMaterialID(newMat, oldMatDetails.Serial, state.LastSeenMessage.TimeUTC);
                }
                else if (_settings.SerialType == BlackMaple.MachineFramework.SerialType.AssignOneSerialPerMaterial)
                {
                    _log.RecordSerialForMaterialID(newMat, _settings.ConvertMaterialIDToSerial(newId).PadLeft(_settings.SerialLength, '0'), state.LastSeenMessage.TimeUTC);
                }
                ret.Add(newMat);
            }

            return(ret);
        }
Ejemplo n.º 2
0
        public static void CreateSerial(long matID, string jobUniqe, string partName, int process, string face,
                                        JobLogDB _log, FMSSettings Settings)
        {
            foreach (var stat in _log.GetLogForMaterial(matID))
            {
                if (stat.LogType == LogType.PartMark &&
                    stat.LocationNum == 1)
                {
                    foreach (LogMaterial mat in stat.Material)
                    {
                        if (mat.Process == process)
                        {
                            //We have recorded the serial already
                            return;
                        }
                    }
                }
            }

            var serial = Settings.ConvertMaterialIDToSerial(matID);

            //length 10 gets us to 1.5e18 which is not quite 2^64
            //still large enough so we will practically never roll around
            serial = serial.Substring(0, Math.Min(Settings.SerialLength, serial.Length));
            serial = serial.PadLeft(Settings.SerialLength, '0');

            Log.Debug("Recording serial for matid: {matid} {serial}", matID, serial);


            var logMat = new JobLogDB.EventLogMaterial()
            {
                MaterialID = matID, Process = process, Face = face
            };

            _log.RecordSerialForMaterialID(logMat, serial);
        }