Общая библиотека для работы с торговым оборудованием.  1.0.0
tereaderbase.h
1 /****************************************************************************
2 ** $Id: tereaderbase.h,v 1.12 2006/07/18 06:01:19 red75 Exp $
3 **
4 ** Trade equipment common portable library project
5 **
6 ** Copyright (C) 1999-2006 Leader InfoTech. All rights reserved.
7 ** Copyright (C) 1999-2006 Valery Grazdankin. All rights reserved.
8 **
9 ** This file is part of the Library of the Ananas
10 ** automation accounting system.
11 **
12 ** This file may be distributed and/or modified under the terms of the
13 ** GNU General Public License version 2 as published by the Free Software
14 ** Foundation and appearing in the file LICENSE.GPL included in the
15 ** packaging of this file.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.leaderit.ru/ or email sales@leaderit.ru
21 **
22 ** Contact org@leaderit.ru if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26 
27 #ifndef TEREADERBASE_H
28 #define TEREADERBASE_H
29 
30 #include <tebase.h>
31 #include <qvaluelist.h>
32 #include <qstring.h>
33 #include "templexports.h"
34 
35 #define EVENT_READER_DATAARRIVED 1
36 #define EVENT_READER_ERROR 100
37 
38 
39 class LIB_EXPORT TEReaderBase : public TEBase
40 {
41  Q_OBJECT
42  typedef TEBase superclass;
43 
44 public:
45  // public interface
46  TEReaderBase();
47 
48 public slots:
49  virtual QString text( int iTrackNumber = 0 ) const; // it returns first text data from queue.
50  // iTrackNumber = 0 - returns all tracks
51  // iTrackNumber = 1..max - returns iTrackNumber track text.
52  int next(); // it advances to next barcode in queue, 0-there's no barcode available, 1-ok
53  // if there is barcode in buffer, then emit event EVENT_BARCODE.
54  void setBuffering(int iBufEnabled); // params: iBufEnabled: 0 - buffering disabled, 1 - enabled
55  int buffering() const;
56 
57  void setDropStopByte(bool bDSB) {m_bDropStopByte=bDSB;}
58  bool dropStopByte() const {return m_bDropStopByte;}
59 
60  void setUseStopByte(bool bUSB) {m_bUseStopByte=bUSB;}
61  bool useStopByte() const {return m_bUseStopByte;}
62 
63  void setMaxLength(int iML) {m_iMaxLength=iML;}
64  int maxLength() const {return m_iMaxLength;}
65 
66  void setDropBegCnt(int iDBC) {m_iDropBegCnt=iDBC;}
67  int dropBegCnt() const {return m_iDropBegCnt;}
68 
69  void setDropEndCnt(int iDEC) {m_iDropEndCnt=iDEC;}
70  int dropEndCnt() const {return m_iDropEndCnt;}
71 
72  int clearBuffer(); // it clears queue of barcodes. Return value: 0 - there was no pending barcodes, 1 - there was pending barcodes
73 
74  void setStopByte(int); // sets 'stop byte' - byte value which marks the end of barcode
75  int stopByte() const;
76 
77  void setMaxDelay(int); // sets maximum allowed wait time in ms for reading single barcode
78  int maxDelay() const;
79 
80  void setStartSequence( const QString &seq );
81  QString startSequence() const {return m_qsStartSequence;}
82 
83  void setStopSequence( const QString &seq );
84  QString stopSequence() const {return m_qsStopSequence;}
85 
86  QString errorText() const;
87 
88  virtual int startDriver(); // open port, then start polling it
89  virtual int stopDriver(); // stop polling, then closes port
90 
91  virtual bool setParameter(const QString &, const QString &);
92 
93  int queueSize() const
94  {
95  return (int)m_qBuffer.size();
96  }
97 
98  enum ReaderType
99  {
100  RT_BARCODE,
101  RT_CARD
102  };
103 
105  virtual int readerType() const=0;
106 
107 protected:
108 // Interface for descendant classes
109 
110  int pushText(const QString &); // It pushes given barcode to the end of a queue,
111  // emits event immediatly, or drops barcode.
112  // Action depends on current driver settings.
113 
114  virtual int openPort()=0; // opens port
115  virtual int closePort()=0; // closes port
116  virtual int readBarcode()=0; // tries to read barcode. It is called by poll()
117 
118  virtual void emitSignal(); // emits EVENT_BARCODE_ARRIVED device event, can be replaced by miniport driver
119  virtual void reportError(const QString &); // emits EVENT_ERROR device event
120 
121  void setErrorText(const QString & err);
122 
123  virtual void handleData( const QString &data );
124 
125 private:
126  virtual int poll(); // this function gets called every nth millisecond
127 
128  QString m_qsReadBuffer;
129 
130  QValueList <QString> m_qBuffer;
131  bool m_bClearToChangeBC; // it's clear to change value returned by barcode()
132  bool m_bUseStopByte;
133  bool m_bDropStopByte;
134  int m_iStopByte; // stop byte value
135  int m_iMaxDelay;
136  int m_iBuffering; // 0-disable buffering, 1-enable buffering
137  int m_iMaxLength; // maximal barcode length
138  int m_iDropBegCnt; // number of starting characters to drop
139  int m_iDropEndCnt; // number of ending characters to drop
140  QString m_qsErrorText;
141  QString m_qsStartSequence, m_qsStopSequence;
142 };
143 
144 #endif
The TEReaderBase is base class for all reader classes.
Definition: tereaderbase.h:39
virtual int stopDriver()
Definition: tebase.cpp:641
virtual int startDriver()
Definition: tebase.cpp:627
virtual QString errorText() const
Definition: tebase.cpp:144
The TEBase is base class for all trade equipment classes.
Definition: tebase.h:148