public RacesSettingsViewModel(TotalRaceInfo totalRaceInfo)
        {
            TotalRaceInfo = new TotalRaceInfo(totalRaceInfo);

            SaveCommand       = new DelegateCommand(Save);
            ChooseFileCommand = new DelegateCommand(ChooseFile);
        }
Пример #2
0
        private void NewProject()
        {
            if (TotalRaceInfo == null)
            {
                TotalRaceInfo = new TotalRaceInfo(null)
                {
                    TagsPerRaceCount = 2,
                    CodeLength       = 4,
                    StartNumber      = 100,
                    EndNumber        = 1000,
                    AddPrefix        = true,
                    IsDigitInserting = true,
                    Prefix           = "123",
                    AccessPassword   = "******"
                }
            }
            ;


            var wnd = new RacesSettings {
                Owner = Application.Current.MainWindow, IsEnabled = !IsEncoding
            };
            var model = new RacesSettingsViewModel(TotalRaceInfo)
            {
                FrameworkElement = wnd
            };

            wnd.DataContext = model;

            if (wnd.ShowDialog().GetValueOrDefault(false))
            {
                var info = model.TotalRaceInfo;

                for (var i = info.StartNumber; i <= info.EndNumber; i++)
                {
                    var list = new List <uint?>();
                    for (var j = 0; j < info.TagsPerRaceCount; j++)
                    {
                        list.Add(null);
                    }

                    var ri = new RaceInfo {
                        RaceNumber = i, TagList = new ObservableCollection <uint?>(list)
                    };
                    info.Add(ri);
                }

                TotalRaceInfo = info;

                NextRaceNumber = TotalRaceInfo.StartNumber;
                SelectedRace   = TotalRaceInfo.First();
                NextTagNumber  = GetNextTag();
            }
        }
Пример #3
0
        public TotalRaceInfo(TotalRaceInfo totalRaceInfo)
        {
            if (totalRaceInfo == null)
            {
                return;
            }

            _startNumber      = totalRaceInfo.StartNumber;
            _endNumber        = totalRaceInfo.EndNumber;
            _tagsPerRaceCount = totalRaceInfo.TagsPerRaceCount;
            _isDigitInserting = totalRaceInfo.IsDigitInserting;
            _fileName         = totalRaceInfo.FileName;
            _addPrefix        = totalRaceInfo.AddPrefix;
            _prefix           = totalRaceInfo.Prefix;
            _codeLength       = totalRaceInfo.CodeLength;
            _accessPassword   = totalRaceInfo.AccessPassword;
            _killPassword     = totalRaceInfo.KillPassword;
        }
Пример #4
0
        private void StartEncoding()
        {
            if (IsEncoding)
            {
                IsEncoding          = false;
                StatusBarText       = "Encoding stopped";
                StatusBarBackground = Brushes.Green;
                return;
            }

            if (string.IsNullOrEmpty(TagOperationsViewModel.SelectedRegion) ||
                TagOperationsViewModel.SelectedRegion == "Select")
            {
                MessageBox.Show("Please, select the region first.", "Information", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                //return;
            }

            Task.Factory.StartNew(() =>
            {
                do
                {
                    //1. Wait for Tag
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        IsEncoding          = true;
                        StatusBarText       = "Waiting for tag...";
                        StatusBarBackground = Brushes.Yellow;
                    });

                    //2. Read tag
                    var tag = TagOperationsViewModel.ReadTagSync();

                    //3. if epc tag is in the number set to be encoded as defined by the project (i.e. 12301020) this indicates it is already encoded,
                    //3a. show 'already encoded as 1020'
                    //3b. return to 1.
                    if (!IsEncoding)
                    {
                        if (tag.HasValue && !OverrideTags && CheckRepeatedTag(tag))
                        {
                            StatusBarText       = "Tag " + tag + " is already encoded";
                            StatusBarBackground = Brushes.OrangeRed;
                            Speak("Already encoded");
                            Thread.Sleep(300);
                            continue;
                        }
                    }

                    var apLocked = false;

                    //4. determine if access password is locked. In URA I see 'Gen2 memory locked' in Reserved Memory Bank (0) access password.
                    if (TagOperationsViewModel.CheckAccessPasswordIsLocked())
                    {
                        //4a. if access password locked, try the current access password from 'new project dialogue'
                        //which has yet to be created. if fails, open dialogue to ask for old access password. Remember this password for
                        //future uses of this dialogue.
                        if (!TagOperationsViewModel.ApplyLockAction
                                (new Gen2.LockAction(Gen2.LockAction.ACCESS_UNLOCK), _totalRaceInfo.AccessPassword))
                        {
                            //open dialog
                            var dialog = new NewPasswordWnd(_totalRaceInfo.AccessPassword);
                            if (dialog.ShowDialog().GetValueOrDefault(false))
                            {
                                if (!TagOperationsViewModel.ApplyLockAction
                                        (new Gen2.LockAction(Gen2.LockAction.ACCESS_UNLOCK), dialog.Password))
                                {
                                    // failed again
                                    // check if epc is locked
                                    // if locked -> invalid chip -> continue
                                    if (TagOperationsViewModel.CheckEpcIsLocked(dialog.Password))
                                    {
                                        StatusBarText       = "Invalid chip, continue...";
                                        StatusBarBackground = Brushes.Red;
                                        Speak("Invalid chip");
                                        Thread.Sleep(300);
                                        continue;
                                    }
                                    //if not locked ask for continue without locking
                                    else
                                    {
                                        if (MessageBox.Show("EPC is not locked. Continue without locking?", "Question",
                                                            MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                        {
                                            //if yes
                                            apLocked = true;
                                        }
                                        //if no -> continue
                                        else
                                        {
                                            Thread.Sleep(300);
                                            continue;
                                        }
                                    }
                                }
                            }
                            else
                            {
                            }
                        }
                    }

                    //4b. if access password is not locked, encode access password =
                    //#8 digits from access password dialogue needed in 'new project' screen# .
                    if (!apLocked)
                    {
                        TagOperationsViewModel.WriteAccessPassword(_totalRaceInfo.AccessPassword);
                    }

                    //5. encode tag to proper number
                    var encoded = TagOperationsViewModel.WriteTag(NextTagNumber);

                    if (encoded && !apLocked)
                    {
                        //6. lock epc memory (tag) with write lock. Gen2.LockAction.EPC_LOCK
                        TagOperationsViewModel.ApplyLockAction(
                            new Gen2.LockAction(Gen2.LockAction.EPC_LOCK), _totalRaceInfo.AccessPassword);

                        //7. lock access password with read/write lock. Gen2.LockAction.ACCESS_LOCK
                        TagOperationsViewModel.ApplyLockAction(
                            new Gen2.LockAction(Gen2.LockAction.ACCESS_LOCK), _totalRaceInfo.AccessPassword);

                        //8. set kill password =#8 digits from kill password dialogue needed in 'new project' screen#
                        TagOperationsViewModel.WriteKillPassword(_totalRaceInfo.KillPassword);

                        //9. lock kill password with read/write lock. Gen2.LockAction.LILL_LOCK
                        TagOperationsViewModel.ApplyLockAction(
                            new Gen2.LockAction(Gen2.LockAction.KILL_LOCK), _totalRaceInfo.AccessPassword);
                    }

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        SelectedRace.TagList[SelectedTagIndex] = NextTagNumber;
                        if (encoded)
                        {
                            StatusBarText       = "Successfully encoded!";
                            StatusBarBackground = Brushes.LawnGreen;
                        }
                        else
                        {
                            StatusBarText       = "Encoding error, trying again...";
                            StatusBarBackground = Brushes.Red;
                        }
                    });

                    if (encoded)
                    {
                        //10. re-read tag to validate that it is properly coded.
                        StatusBarText       = "Verifying...";
                        StatusBarBackground = Brushes.Orange;
                        encoded             = TagOperationsViewModel.VerifyTag(NextTagNumber);
                    }

                    //11. have computer speak the last two digits of the number.
                    if (encoded || Debugger.IsAttached)
                    {
                        SayNumber(NextTagNumber);
                        WriteToFile();
                        //12. increment to next tag
                        TotalRaceInfo.FireNextTag(NextTagNumber);
                    }

                    Thread.Sleep(300);
                } while (IsEncoding);
            }
                                  );
        }