Exemple #1
0
        private void BeginReceiveCallBack(IAsyncResult reault)
        {
            int cout = 0;

            try
            {
                cout = sendTcp.Client.EndReceive(reault);
            }
            catch (SocketException e)
            {
                socketError = e.SocketErrorCode;
            }
            catch (Exception ex)
            {
                socketError = SocketError.HostDown;
            }
            if (socketError == SocketError.Success && cout > 0)
            {
                byte[] buffer = reault.AsyncState as byte[];
                byte[] data   = new byte[cout];
                Array.Copy(buffer, 0, data, 0, data.Length);
                PreventLostContext context      = new PreventLostContext(data);
                PrinterState       printerstate = context.Tactic(ip);
                if (PrintExecCallBack != null)
                {
                    PrintExecCallBack((int)printerstate);
                }
                BeginReceive();
            }
            else
            {
                sendTcp.Client.Close();
            }
        }
Exemple #2
0
        protected override PrintResults PrintNormalImpl(PrinterStation station, PrinterState printerState, string data)
        {
            if (station == PrinterStation.Receipt && (printerState.RecRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
            {
                Window.DisplayText("[Begin " + printerState.RecRotationMode.ToString() + " rotation]\r\n");
            }
            else if (station == PrinterStation.Slip && (printerState.SlpRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
            {
                Window.DisplayText("[Begin " + printerState.SlpRotationMode.ToString() + " rotation]\r\n");
            }

            Window.DisplayText(data);

            if (station == PrinterStation.Receipt && (printerState.RecRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
            {
                Window.DisplayText("[End " + printerState.RecRotationMode.ToString() + " rotation]\r\n");
            }
            else if (station == PrinterStation.Slip && (printerState.SlpRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
            {
                Window.DisplayText("[End " + printerState.SlpRotationMode.ToString() + " rotation]\r\n");
            }

            Thread.Sleep(printDelay);

            return(GetPrintStats(station, data.Length));
        }
        public PrinterManager()
        {
            _state = PrinterState.UNREGISTERED;

            this.pages_printed = 0;

            mabel_api        = new MabelAPI();
            mabel_api.Debug += MabelDebug;
            mabel_api.Error += MabelError;
            _running         = false;
            // if magicard API enabled
        }
Exemple #4
0
        private void PrintWatch_Tick(object sender, EventArgs e)
        {
            PrintState = PrintIO.CheckPrinterQueue(ConfigurationManager.AppSettings["PhotoPrinterName"]);

            if (PrintJobStatus.None != PrintState.status)
            {
                PrintStatusLbl.Visible = true;
                PrintStatusLbl.Text    = PrintState.status.ToString();
            }
            else
            {
                //status is None
                PrintStatusLbl.Visible = false;
            }
        }
        public bool Unregister()
        {
            MabelResponse resp = mabel_api.UnregisterPrinter(printer_id);

            _registered = false;
            if (resp.isError)
            {
                OnUnregisterError(new PrinterEventArgs(null, "Unregister failed " + resp.message, _printerInfo));
                return(false);
            }
            else
            {
                OnUnregistered(new PrinterEventArgs(null, "Unregistered Successfully", _printerInfo));
                _state = PrinterState.UNREGISTERED;
                return(true);
            }
        }
        public bool Register()
        {
            string selectedPrinter = Properties.Settings.Default.LocalPrinter;

            if (selectedPrinter.Equals(""))
            {
                // no selected printer
                lastError = "No selected printer";
                return(false);
            }
            UpdatePrinterInfo();
            MabelResponse resp;

            try {
                resp = mabel_api.RegisterPrinter(printer_id, selectedPrinter, printer_location, _printerInfo);
            } catch (Exception e)
            {
                OnDebug(new DebugEventArgs("", e.Message));
                return(false);
            }

            if (resp.isError)
            {
                OnRegisterError(new PrinterEventArgs(null, "Register failed " + resp.message, _printerInfo));
                _state      = PrinterState.UNREGISTERED;
                _registered = false;
                return(false);
            }
            else
            {
                OnRegistered(new PrinterEventArgs(null, "Registered successfully", _printerInfo));
                _state      = PrinterState.IDLE;
                _registered = true;
                return(true);
            }
        }
Exemple #7
0
        public ActionResult State()
        {
            PrinterState printerState = new PrinterState(_db);

            return(View(printerState.State()));
        }
Exemple #8
0
 public Printer()
 {
     printerName  = "imprimante_";
     printerState = PrinterState.OFF;
 }
        public void DoWork()
        {
            UpdatePrinterInfo();
            // operate the state machine here
            if (_running)
            {
                return;
            }
            _running = true;

            switch (_state)
            {
            case (PrinterState.UNREGISTERED):
                if (_requestRegister)
                {
                    _requestRegister = false;
                    if (Register())
                    {
                        // successfully registered
                        _state = PrinterState.IDLE;
                    }
                }
                break;

            case (PrinterState.IDLE):
                // if we are idle, then we should go go into a requesting state
                _abortPressed = false;
                _retryPressed = false;
                _state        = PrinterState.REQUESTING;
                break;

            case (PrinterState.REQUESTING):
                OnCardRequest(new PrinterEventArgs(null, "Checking", _printerInfo));
                _abortPressed = false;
                _retryPressed = false;
                if (RequestNextCard())
                {
                    // if there is a card available to process
                    _state = PrinterState.CARD_READY;

                    OnCardReady(new PrinterEventArgs(this.nextCard, "Card available to print", _printerInfo));
                }
                else
                {
                    // otherwise go back to Idle.
                    _state = PrinterState.IDLE;
                }
                break;

            case (PrinterState.CARD_READY):
                // if there is a card ready, should we print it?
                if (_abortPressed)
                {
                    // how do we abort from this situation?
                    _abortPressed = false;
                    _state        = PrinterState.IDLE;
                    break;
                }
                if (_requestPrint)
                {
                    _requestPrint = false;     // turn off the switch
                    if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                    {
                        _state = PrinterState.LOADING;
                    }
                    else
                    {
                        _state = PrinterState.PRINTING;
                    }
                }
                break;

            case (PrinterState.LOADING):
                _state = PrinterState.ENCODING;

                /* // actually don't think this is needed unless you have a printer capable of chip card encoding?
                 * if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                 *
                 * OnCardLoad(new PrinterEventArgs(this.nextCard, "loading", _printerInfo));
                 * if (_abortPressed)
                 * {
                 *  if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                 *  {
                 *      try {
                 *          EjectCard();
                 *          magi_api.DisableReporting();
                 *      } catch (Exception e)
                 *      {
                 *          OnDebug(new DebugEventArgs("", "Magicard Error: " + e.Message + magi_api.GetLastError()));
                 *      }
                 * }
                 *  _state = PrinterState.IDLE;
                 *  OnAborted(new PrinterEventArgs(this.nextCard, "Loading Aborted", _printerInfo));
                 *  break;
                 * }
                 *
                 * if (LoadCard())
                 * {
                 *  // card loaded successfully, progress to Encoding
                 *  OnCardLoadSuccess(new PrinterEventArgs(this.nextCard, "Loading succeeded", _printerInfo));
                 *  if (Properties.Settings.Default.MagstripeEnabled)
                 *  {
                 *      _state = PrinterState.ENCODING;
                 *  } else
                 *  {
                 *      _state = PrinterState.PRINTING;
                 *  }
                 * }
                 * else
                 * {
                 *  // card wasn't loaded successfully, go to FAILURe
                 *  OnCardLoadFail(new PrinterEventArgs(this.nextCard, "Loading failed: " + magi_api.GetLastEnduroMessage() + " : " + magi_api.GetLastError(), _printerInfo));
                 *  _state = PrinterState.FAILURE;
                 * }*/
                break;

            case (PrinterState.ENCODING):
                // we are encoding the card
                if (_abortPressed)
                {
                    EjectCard();
                    magi_api.DisableReporting();
                    _state = PrinterState.IDLE;
                    OnAborted(new PrinterEventArgs(this.nextCard, "Aborted encoding", _printerInfo));
                    break;
                }
                OnMagEncode(new PrinterEventArgs(this.nextCard, "Encoding mag stripe", _printerInfo));
                if (EncodeCard())
                {
                    // encoding completed successfully, progress to Printing
                    OnMagEncodeSuccess(new PrinterEventArgs(this.nextCard, "Mag encoding success", _printerInfo));
                    _state = PrinterState.PRINTING;
                }
                else
                {
                    // encoding did not complete successfully, eject the card;
                    OnMagEncodeFail(new PrinterEventArgs(this.nextCard, "Mag encoding failure: " + magi_api.GetLastEnduroMessage() + " : " + magi_api.GetLastError(), _printerInfo));
                    _state = PrinterState.EJECTING_FAIL;
                }
                break;

            case (PrinterState.PRINTING):
                // we are printing the card
                if (_abortPressed)
                {
                    if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                    {
                        EjectCard();
                        magi_api.DisableReporting();
                    }
                    OnAborted(new PrinterEventArgs(this.nextCard, "Aborted Printing", _printerInfo));
                }
                OnPrint(new PrinterEventArgs(this.nextCard, "Printing card", _printerInfo));
                if (Properties.Settings.Default.DontPrint)
                {
                    OnPrintSuccess(new PrinterEventArgs(this.nextCard, "Printed successfully (not really, disabled)", _printerInfo));
                    _state = PrinterState.IDLE;
                    break;
                }
                if (PrintCard())
                {
                    OnPrintSuccess(new PrinterEventArgs(this.nextCard, "Printed successfully", _printerInfo));
                    if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                    {
                        magi_api.DisableReporting();
                    }
                    // if we have RFID enabled, then go to that state
                    if (Properties.Settings.Default.RFIDEnabled)
                    {
                        // if RFID reading is enabled, go to that state
                        _state = PrinterState.RFIDREAD;
                    }
                    else
                    {
                        // otherwise if RFID isn't enabled, we're done
                        _state = PrinterState.IDLE;
                    }
                }
                else
                {
                    if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                    {
                        OnPrintFail(new PrinterEventArgs(this.nextCard, "Printing failure: " + magi_api.GetLastEnduroMessage() + " : " + magi_api.GetLastError(), _printerInfo));
                    }
                    else
                    {
                        OnPrintFail(new PrinterEventArgs(this.nextCard, "Printing failure", _printerInfo));
                    }
                    _state = PrinterState.FAILURE;
                }
                break;

            case (PrinterState.RFIDREAD):
                // read the RFID
                OnRFIDRead(new PrinterEventArgs(this.nextCard, "Reading RFID", _printerInfo));
                try {
                    if (ReadRFID())
                    {
                        // read the RFID successfully, now we wait for it to be removed, then enroll it
                        OnRFIDReadSuccess(new PrinterEventArgs(this.nextCard, _currentRfidToken, _printerInfo));
                        _state = PrinterState.RFIDWAITREMOVE;
                    }
                    else
                    {
                        // didn't read RFID successfully
                        OnRFIDReadTimeout(new PrinterEventArgs(this.nextCard, lastError, _printerInfo));
                        _state = PrinterState.RFIDREADTIMEOUT;
                    }
                } catch (Exception e)
                {
                    OnRFIDReadTimeout(new PrinterEventArgs(this.nextCard, e.Message, _printerInfo));
                    _state = PrinterState.RFIDREADTIMEOUT;
                }
                break;

            case (PrinterState.RFIDWAITREMOVE):
                rfid.WaitForRemoval();
                OnRFIDRemoved(new PrinterEventArgs(this.nextCard, "RFID Removed", _printerInfo));
                _state = PrinterState.ENROLLING;
                break;

            case (PrinterState.RFIDREADTIMEOUT):
                // if we request a RFID retry
                if (_retryPressed)
                {
                    // go back to the RFIDREAD state and try again
                    _state        = PrinterState.RFIDREAD;
                    _retryPressed = false;
                }
                if (_abortPressed)
                {
                    _abortPressed = false;
                    // otherwise go back to the idle state.
                    _state = PrinterState.IDLE;
                }
                // otherwise, do nothing.
                break;

            case (PrinterState.ENROLLING):
                OnEnrol(new PrinterEventArgs(this.nextCard, "Enrolling", _printerInfo));
                if (EnrolToken())
                {
                    OnEnrolSuccess(new PrinterEventArgs(this.nextCard, "Enrolled successfully", _printerInfo));
                    _state = PrinterState.IDLE;
                }
                else
                {
                    // if enrolling didn't work properly, go to the RFID timeout state so we can try again, or abort.
                    OnEnrolFail(new PrinterEventArgs(this.nextCard, lastError, _printerInfo));
                    _state = PrinterState.RFIDREADTIMEOUT;
                }
                break;

            case (PrinterState.FAILURE):
                // a failure has occurred. We can either retry or abort.
                if (_retryPressed)
                {
                    _retryPressed = false;
                    magi_api.DisableReporting();
                    _state = PrinterState.CARD_READY;
                }
                if (_abortPressed)
                {
                    // abort card , return to idle state.
                    magi_api.DisableReporting();
                    _abortPressed = false;
                    if (!AbortCard())
                    {
                        // if it doesn't abort, then there's clearly a bigger problem and we need to force re-registration
                        Unregister();
                    }
                    // go back to the idle state
                    _state = PrinterState.IDLE;
                }
                break;

            case (PrinterState.EJECTING_FAIL):
                if (Properties.Settings.Default.PrinterType.Equals("Magicard"))
                {
                    if (EjectCard())
                    {
                        // eject the card. only if it has succeeded then proceed to the next step.
                        _state = PrinterState.FAILURE;
                    }     // if it fails, keep trying to eject the card.
                }
                else
                {     // if it's a non Magicard printer, proceed to the next stage anyway.
                    _state = PrinterState.FAILURE;
                }
                break;
            }
            _running = false;
        }
Exemple #10
0
		protected override PrintResults PrintImmediateImpl(PrinterStation station, string data, PrinterState state)
		{
			Window.DisplayText(data );
			Thread.Sleep(printDelay);
			return GetPrintStats(station, data.Length);
		}
Exemple #11
0
		protected override PrintResults PrintNormalImpl(PrinterStation station, PrinterState printerState, string data)
		{
			if (station == PrinterStation.Receipt && (printerState.RecRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
				Window.DisplayText("[Begin " + printerState.RecRotationMode.ToString() + " rotation]\r\n");
			else if (station == PrinterStation.Slip && (printerState.SlpRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
				Window.DisplayText("[Begin " + printerState.SlpRotationMode.ToString() + " rotation]\r\n");

			Window.DisplayText(data );
			
			if (station == PrinterStation.Receipt && (printerState.RecRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
				Window.DisplayText("[End " + printerState.RecRotationMode.ToString() + " rotation]\r\n");
			else if (station == PrinterStation.Slip && (printerState.SlpRotationMode & PrintRotation.Rotate180) == PrintRotation.Rotate180)
				Window.DisplayText("[End " + printerState.SlpRotationMode.ToString() + " rotation]\r\n");
			
			Thread.Sleep(printDelay);

			return GetPrintStats(station, data.Length);
		}
 public Printer(PrinterState printerState)
 {
     PrinterState = printerState;
 }
Exemple #13
0
 protected override PrintResults PrintImmediateImpl(PrinterStation station, string data, PrinterState state)
 {
     Window.DisplayText(data);
     Thread.Sleep(printDelay);
     return(GetPrintStats(station, data.Length));
 }
 public StateChangedEventArgs(PrinterState oldState, PrinterState newState)
 {
     OldState = oldState;
     NewState = newState;
 }