Example #1
0
        //make sure printer is ready to print when create PrintController
        public PrintController(Batch batch)
        {
            X30Client = new X30Client();

            _batch         = batch;
            _batchsToPrint = batch.Items;

            SerialPort = new SerialPort();

            _timer          = new Timer();
            _timer.Interval = 1000;
            _timer.Tick    += _timer_Tick;
        }
Example #2
0
        private async void Setup()
        {
            if (_isBusy)
            {
                OnLog("上次请求还未处理");
                return;
            }

            _isBusy = true;
            try
            {
                await X30Client.StateChangeAsync(StateChangeStatus.Producing);

                var jobUpdateCommand = new JobCommand();
                var bi = _batchsToPrint[_batch.StartIndex];

                PopulateJobCommandFields(jobUpdateCommand, bi.QRCodeContent);

                await X30Client.UpdateJob(jobUpdateCommand);

                //log sent batch info
                _initialized = true;
                _batchIndex  = _batch.StartIndex;

                bi.Status = BatchStatus.CodeSent;
                var message = $"成功初始化--{bi.SerinalNo} - {bi.QRCodeContent} 已赋码";
                OnLog(message);
            }
            catch (Exception e)
            {
                var message = $"初始化失败--{e.Message}";
                OnLog(message);
            }

            _isBusy = false;
        }
Example #3
0
        private async void UpdateJob()
        {
            if (_isBusy)
            {
                OnLog("上次请求还未处理");
                return;
            }

            _isBusy = true;

            try
            {
                var status = await X30Client.GetClearSendStatusAsync();

                if (status == ClearSendStatus.Ready)
                {
                    if (IsComplete)
                    {
                        _timer.Stop();
                        await X30Client.StateChangeAsync(StateChangeStatus.Ready);

                        PrintCompleted?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        CurrentBatchItem.Status = BatchStatus.Printed;
                        AppContext.Instance.DB.Update(CurrentBatchItem);

                        if (IsFatalError)
                        {
                            _timer.Stop();
                            FatalError?.Invoke(this, EventArgs.Empty);
                            await X30Client.StateChangeAsync(StateChangeStatus.Ready);

                            return;
                        }
                        var jobUpdateCommand = new JobCommand();
                        var bi = _batchsToPrint[_batchIndex + 1];

                        PopulateJobCommandFields(jobUpdateCommand, bi.QRCodeContent);

                        await X30Client.UpdateJob(jobUpdateCommand);

                        _currentClearStatus = ClearSendStatus.NotReady;
                        _batchIndex++;
                        bi.Status = BatchStatus.CodeSent;
                        AppContext.Instance.DB.Update(bi);
                        var message = $"{bi.SerinalNo} - {bi.QRCodeContent} 已赋码";
                        OnLog(message);
                        Printed?.Invoke(this, EventArgs.Empty);
                    }
                }
                else
                {
                    CurrentBatchItem.Status = BatchStatus.Printing;
                }
            }
            catch (Exception e)
            {
                var message = $"错误--{e.Message}";
                OnLog(message);
            }

            _isBusy = false;
        }