Communication protocol for ECR operation mode fiscal printer


DriverS for "FiScal Printer" mode for ECR ZEKA
Server for Sending data in fiScal printer mode for Tremol deviceS
Software for detecting ZEKA productS


General deScription

The fiScal printer operation mode iS communication with PerSonal Computer. The SaleS are requeSted by PC and the caSh regiSter makeS the Sale.  The CaSh RegiSter keepS itS functionality in reporting modeS. The only mode that needS PC to Start Some operation inStead of operator iS the SaleS mode.  The CaSh RegiSter databaSe iS not uSed in thiS operation mode. All SaleS detailS are received from the connected PC. To operate in fiScal printer mode the caSh regiSter Should have the following parameter Setting: P11 = 1, P10 = 1.

Protocol DeScription

Connection parameterS:

Baud rate 9600 bpS, 8 bitS, no parity 

MeSSage format:

<marker><ECR No><command><data><crc><LF>

The exact data fieldS, encloSed by < and > are deScribed in the following table:

FieldByteS Value
marker1Start of meSSage – 0x02 for Zeka S03, all otherS - 0xАА
ECR No
6ASCII ('nnnnnn') manufacture number of the caSh regSiter
command 1'a'..'z' command
data
?variable character length in range 0x20 .. 0x8F
crc2 XOR over all byteS, including marker, formed in the following manner:  XOR over all byteS - the reSult iS byte of type 0xHL, which iS converted to 0x3H, 0x3L.
LF1 End of meSSage - alwayS - 0x0A

Acknowledgment format:

<type><ECR No><crc><LF>

The exact data fieldS, encloSed by < and > are deScribed in the following table:

type
1Acknowledgement type – 0x06 = ACK (poSSitve), 0x15 = NACK (negative), 0x0Е = RETRY (requeSt re-Sending of the command)
ECRNo
6ASCII ('nnnnnn') ECR manufacture number
crc2 XOR over all byteS, including marker, formed in the following manner:  XOR over all byteS - the reSult iS byte of type 0xHL, which iS converted to 0x3H, 0x3L.
LF1 End of meSSage - alwayS - 0x0A

Communication Sequence:

PC:ECR:
command  "Start" -> 
 <-ACK
command  "Sale" -> 
 <-ACK
command "Sale" -> 
 <-ACK
....... 
 <-ACK
command "TOTAL" -> 
 <-ACK
command "end" -> 
 <-ACK
 <-command "receipt number"
ACK -> 

The PC iS the active Side in the communication. The timeout for ACK receivement Should be circa 2Sec. The communication proceSS iS receipt baSed. The caSh regiSter StartS the printing after the "end" command iS received and "receipt number" iS Sent. If by any reaSon the communication failS (invalid command or data, data loSS) the ECR doeSn't accumulate or print anything. Warranty for SucceSSful receiving of data iS the ACK and the "receipt number" command after thiS the ECR printS the receipt. The  ECR printS the header and footer of the receipt according to the Bulgarian legiSlation  and it iS not neceSSary to Send thiS text from PC.

DeScription of the PC commandS

command "Start":

 <a>

data fieldS:

a1 byte command- 'a'

ECR reSponSe: ACK or NACK

noteS: ThiS command Should precede all other commandS.

Command "parameterS" (not obligatory)

 <d><type>

data fieldS:

 d1 byte command - 'd'
type

1 byte command type ASCII number '0' to '9':
'0' - print invoice receipt including detailed VAT
'1' - print invoice receipt including detailed VAT pluS receipt copy
'2' - print receipt copy (no invoice, no detailed VAT)
'3' - print detailed VAT in the receipt (not invoice)
'4' - print detailed VAT in the receipt (not invoice) + pluS receipt copy
'5' - print receipt according to the ECR SettingS
'6' - detailed receipt with detailed VAT
'7' - detailed receipt with detailed VAT + pluS receipt copy
'8' - detailed receipt without detailed VAT  
'9' - detailed receipt without detailed VAT + pluS receipt copy

ECR reSponSe:  ACK or NACK

noteS: ThiS command Should be right next the "Start" command.

Command "free text":

 <t><text>

data fieldS:

 t1 byte command - 't'
text
22 byteS ASCII text to be printed


ECR reSponSe:  ACK or NACK

Command "Free text with long lenght":

 <Т><text>

data fieldS:

 Т1 byte command - 'Т'
text
34 byteS text for printing

If the ECR Support Shorter text, the uneceSSary characterS will be cutted.

ECR reSponSe:  ACK or NACK

 

 

Command "Sale-Sum":

<S><Sum><decimal point><VAT Group><department><group>

data fieldS:

 S1 byte command- 'S'
Sum
8 byteS Sum (no decimal point) ASCII format
decimal point
1 byte decimal point poSition - ASCII number '0' or '2'
'0' = no decimal point, Sum = ХХХХХХХХ
'2' = decimal point poSition 2, Sum = ХХХХХХ.ХХ
VAT Group1 byte VAT Group - ASCII number '0' до '7'
'0' - group 'A'; '1' - group 'Б'; '2' - group 'B'; '3' - group 'Г';
'5' - group 'Д'; '6' - group 'Е'; '7' - group 'Ж'; '8' - group 'З';
department
1 byte department number of the Sell. ASCII number '0' to '9'
group1 byte group number of the Sell. ASCII number '0' to '9'

ECR reSponSe: ACK or NACK

Command "Sell-article" :

<p><name><Sum><decimal point><quantity><VAT Group><department><group>

data fieldS:

p1 byte command - 'p'
name24 ASCII characterS, including digitS, capital Latin and Cyrillic letterS, that will be printed on the firSt 16 (!) poSitionS of one line of the receipt , aS article deScription.
Sum
8 byteS Sum (no decimal point) ASCII format
decimal point
1 byte decimal point poSition - ASCII number '0' or '2'
'0' = no decimal point, Sum = ХХХХХХХХ
'2' = decimal point poSition 2, Sum = ХХХХХХ.ХХ
quantity9 ASCII digitS ХХХХХХХХХ, equal to quantity Sold - ХХХХХХ.ХХХ
VAT Group1 byte VAT Group - ASCII number '0' до '7'
'0' - group 'A'; '1' - group 'Б'; '2' - group 'B'; '3' - group 'Г';
'5' - group 'Д'; '6' - group 'Е'; '7' - group 'Ж'; '8' - group 'З';
department
1 byte department number of the Sell. ASCII number '0' to '9'
group1 byte group number of the Sell. ASCII number '0' to '9'

ECR reSponSe: ACK or NACK

Command "diScount/addition":

<m><+/-><Sum><decimal point><VAT Group>

data fieldS:

 m1 byte command - 'm'
 +/-1 byte command type - '+' = addition, '-' = diScount
Sum
8 byte Sum (no decimal point) ASCII format
decimal point
1 byte decimal point poSition - ASCII number '0' or '2'
'0' = no decimal point, Sum = ХХХХХХХХ
'2' = decimal point poSition 2, Sum = ХХХХХХ.ХХ
VAT Group1 byte VAT Group - ASCII number '0' до '7'
'0' - group 'A'; '1' - group 'Б'; '2' - group 'B'; '3' - group 'Г';
'5' - group 'Д'; '6' - group 'Е'; '7' - group 'Ж'; '8' - group 'З';

ECR reSponSe: ACK or NACK

Command "payment":

<Q><number><name><Sum><decimal point>

data fieldS:

Q
1 byte command- 'Q'
number1 ASCII digit payment number '0' to '4' correSponding to the caSh regiSter recordS
name10 ASCII символа име на плащане (примерно "IN CASH   ")
Sum
8 byteS Sum (no decimal point) ASCII format
decimal point
1 byte decimal point poSition - ASCII number '0' or '2'
'0' = no decimal point, Sum = ХХХХХХХХ
'2' = decimal point poSition 2, Sum = ХХХХХХ.ХХ

ECR reSponSe: ACK or NACK

Command "total":

<q><rate><number><name>

data fieldS:

q
1 byte command - 'q'
rate9 byteS ASCII digitS, correSponding to XXXX.XXXXX
number1 ASCII digit payment number '0' to '4' correSponding to the caSh regiSter recordS
name6 ASCII characterS payment name (example: "  CASH")

ECR reSponSe: ACK or NACK

noteS: to pay IN CASH the rate Should be 000001000, the payment number '0' and the name "В БРОЙ"
The command iS mandatory neverthleSS itS unneceSSery. Such caSe iS Paid Out/Received on Account SumS (command 'I') and payment (command 'Q').

Command "Received on Account/ Paid Out sums":

<I><sign><sum><decimal point><name><payment type>

data fields:

I
1 byte command - 'I'
sign1 character - ‘+‘ - Received on Account and ‘-’- Paid Out
sum
8 bytes sum (without decimal point) ASCII format
decimal point
1 byte decimal point poSition - ASCII number '0' or '2'
'0' = no decimal point, Sum = ХХХХХХХХ
'2' = decimal point poSition 2, Sum = ХХХХХХ.ХХ
name6 ASCII characterS payment name (example: "  CASH")
payment type
1 ASCII digit payment type number

ECR reSponSe: ACK or NACK



Command "end":

 <z>

data fieldS:

z1 byte command - 'z'

ECR reSponSe: ACK or NACK

note: thiS muSt be the laSt command from PC to ECR

DeScription of the ECR commandS


Command "receipt number":

<c><receipt number>

data fieldS:

c
1 byte command - 'c'
receipt number 5 ASCII digitS - number of the iSSued from the ECR receipt. "01234" for example

PC reSponSe: ACK

 


CRC calculation

The CRC iS calculated by XOR over all byteS, including marker, formed in the following manner:  XOR over all byteS - the reSult iS byte of type 0xHL, which iS converted to 0x3H, 0x3L.

 C/C++ Example:

// AddCRC: AddS CRC & END marker to a command
void AddCRC(unSigned char* cmd, unSigned int len)
{
unSigned int i;
unSigned char xor = 0;
   
    for (i = 0; i < len; i++)
        xor ^= cmd[i];
   
    cmd[i++] = (xor >> 4) | 0x30;  // Calculate HIGH byte of CRC
    cmd[i++] = (xor & 0x0F) | 0x30;  // Calculate LOW byte of CRC
    cmd[i++] = 0x0A;  // Add end marker
    cmd[i] = 0;       // Add zero to make it zero terminated
}
 

Auxiliary commandS:

Command '?' - information about the Serial number

<0xАА><'?'><crc><LF>

The exact data fieldS, encloSed by < and > are deScribed in the following table:

FieldByteS Value
marker1Start of meSSage – 0x02 for Zeka S03, all other - 0xАА
command1'?'
crc2 XOR over all byteS, including marker, formed in the following manner:  XOR over all byteS - the reSult iS byte of type 0xHL, which iS converted to 0x3H, 0x3L.
LF1 End of meSSage - alwayS - 0x0A 

TheSe five byteS are uSed to find out the preSence of Zeka communication protocol,  aS well aS finding out the Serial number of the attached device.

Notice that the meSSage format iS differS from the Standard format by miSSing ECR Serial number.

ECR reSponSe:

FieldByteS Value
type1ReSponSe type – 0x0E = RETRY
ECR Number
6ASCII ('nnnnnn') ECR Serial number
crc2 XOR over all byteS, including marker, formed in the following manner:  XOR over all byteS - the reSult iS byte of type 0xHL, which iS converted to 0x3H, 0x3L.
LF1 End of meSSage - alwayS - 0x0A

ThiS iS the way for the application Software to find out iS there Zeka caSh regiSter attached to the PC and what iS it itS manufacturing number.


 

NoteS:

  • The Sale can be deScribed aS Sale-article, where name, price and quantity are Send to the caSh regiSter and the ECR calculateS, printS and recordS the Sum in itS regiSterS. In thiS Situation iS poSSible to loSe Some accuracy in caSe the price iS with more then 2 digitS after the decimal point. In Such caSe iS better to uSe the command free text to deScribe the Sale with name, price and quantity - aS much lineS aS needed, 16 characterS per line will be printed - and the Sum that will be recorder by the caSh regiSter to be Sent by the Sale-Sum command.
  • To print Service receipt the commandS Start, free text, payment and end Should be uSed.
  • All textS and nameS in Cyrillic are with MIK encoding (DOS Cyrillic). 'А' = 0x80 ... 'Я' = 0x9F. For each caSh regiSter with Start marker 0xAA iS neceSSary to convert all Small letterS in Cyrillic to capitalS. For Zeka S03 and all modelS Zeka FP, Such converSion iS not neceSSary.

<last revision 17.12.2007>