Beispiel #1
0
        private void WritePortCommand(byte code, byte[] data)
        {
            _lastCommandStatus = EltraCommandStatus.Unknown;
            _lastErrorCode     = EltraErrorCodes.None;
            _lastData          = null;

            List <byte> command = new List <byte> {
                0x12, //WUP
                0x02, //STX
                0x42, //DEST
                code  //CMD
            };

            if (data != null)
            {
                command.AddRange(data); //DATA
            }
            command.Add(0x03);          //ETX

            Lrc8 lrc = Lrc8.GetEltra();

            lrc.Append(command.ToArray());
            command.AddRange(lrc.DigestAsAscii30); //LRC

            command.Add(0x04);                     //EOT

            _serial.Write(command.ToArray(), 0, command.Count);
        }
Beispiel #2
0
        private bool ReadPortAnswer()
        {
            int value = _serial.ReadByte(); //Check whether command was ok.

            if (value != 0x06)              //ACK
            {
                _lastCommandStatus = EltraCommandStatus.CommandError;
                return(false);
            }

            while (true)
            {
                _serial.Write(new byte[] { 0x12, 0x05 }, 0, 2); //WUP ENQ  Pool whether answer is ready.

                value = _serial.ReadByte();
                if (value == 0x10)                      //DLE  No message to send.
                {
                    System.Threading.Thread.Sleep(100); //just wait a little
                }
                else if (value == 0x02)                 //STX  Answer is ready.
                {
                    List <byte> buffer = new List <byte> {
                        (byte)value
                    };
                    do
                    {
                        value = _serial.ReadByte();
                        buffer.Add((byte)value);
                    } while (value != 0x04); //EOT
                    if (buffer.Count < 10)
                    {
                        _lastCommandStatus = EltraCommandStatus.Unknown;
                        return(false);
                    }

                    switch (buffer[3])
                    {
                    case 0x30: {
                        _lastCommandStatus = EltraCommandStatus.CommandAccepted;
                    } break;

                    case 0x52: {
                        _lastCommandStatus = EltraCommandStatus.CommandRefused;
                    } break;

                    case 0x54: {
                        _lastCommandStatus = EltraCommandStatus.CommandNotAvailable;
                    } break;

                    default: throw new System.FormatException("Unknown answer status.");
                    }
                    int errorCodesX = (buffer[4] & 0xF);
                    int errorCodesY = (buffer[5] & 0xF);
                    switch (buffer[2])
                    {
                    case 0x3C:     //Insert Ticket. Ticket in Position
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketAlreadyInsideTheTransport;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketNotPresentInMouth;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x3F:     //Send Sensor Status
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInHomePosition;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInCentralPosition;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInTailPosition;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x41:     //Enable Ticket Insertion
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketAlreadyInsideTheTransport;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInMouthPosition;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x42:     //Disable Ticket Insertion
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x43:     //Read Barcode Field
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.NoTicketInsideTheTransport;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.ReadError;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x44:     //Initialize Module
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInHomePosition;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x45:     //Send Logical Status
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInTailPosition;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInReadPosition;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.NoTicketInsideTheTransport;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.PhotocellFailure;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x46:     //Eject Ticket
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.NoTicketInsideTheTransport;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInMouthPosition;
                        }
                        break;

                    case 0x47:     //Get Inside, Read Data and Parking under Printer
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketAlreadyInsideTheTransport;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.ReadError;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketAlreadyUnderPrinter;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketNotPresentInMouth;
                        }
                        break;

                    case 0x48:     //Hardware Reset
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x49:     //Read 2nd Barcode Field
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.NoTicketInsideTheTransport;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.ReadError;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x50:     //Print Text on Ticket
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.JammingError;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInMouthPosition;
                        }
                        break;

                    case 0x52:     //Insert Ticket and Read Barcode Field
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketAlreadyInsideTheTransport;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.ReadError;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketAlreadyUnderPrinter;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketNotPresentInMouth;
                        }
                        break;

                    case 0x56:     //Validate Ticket
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketUnderPrinter;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.VerifyError;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.JammingError;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInMouthPosition;
                        }
                        break;

                    case 0x58:     //Read Module Configuration
                        break;

                    case 0x59:     //Peripheral Address Setting
                        break;

                    case 0x70:     //Load Ticket under Printer
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x72:     //Unload Ticket from Printer
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.TicketInReadPosition;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    case 0x76:     //Capture Ticket
                        if ((errorCodesX & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.TransportFailure;
                        }
                        if ((errorCodesX & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesX & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x01) == 0x01)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x02) == 0x02)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x04) == 0x04)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if ((errorCodesY & 0x08) == 0x08)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;

                    default:
                        if (errorCodesX != 0x00)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        if (errorCodesY != 0x00)
                        {
                            _lastErrorCode |= EltraErrorCodes.Unknown;
                        }
                        break;
                    }
                    _lastData = new byte[buffer.Count - 10];
                    Array.Copy(buffer.ToArray(), 6, _lastData, 0, _lastData.Length);
                    return(_lastCommandStatus == EltraCommandStatus.CommandAccepted);
                }
            }
        }