marți, 15 martie 2011

COMMUNICATION PROTOCOL BETWEEN ECR MP-500 AND PERSONAL COMPUTER

COMMUNICATION PROTOCOL BETWEEN ECR MP-500 AND PERSONAL COMPUTER



1. INTRODUCTION

The Electronic cash registers DATECS MP-500 are connected to a PC’s serial port through a bus structure topology. The physical layer of the interface is known as D-Bus. All transmit lines of the ECRs are connected to the Receive line of the PC and all Receive lines of the ECRs are connected to the Transmit line of the PC. Up to 3 ECRs can be connected directly to the PC serial interface without any need of adapters. For connecting more than 3 ECRs or in case the distance between the PC and the last ECR is very big it is recomended to use an interface adapter “DATECS IA-500”.
The communictaion between ECRs and a PC are performed in a halfduplex mode. When the PC is transmitting, the information reaches all ECRs.
For ECR identification two numbers are used:
- “ LOGICAL NUMBER of the ECR” - 2 digits. This number is programmed in Table 2, Field 1.
- “ SERIAL NUMBER of the ECR” - 6 digits. This number is programmed during ECR production.

The PC usually sends the following information to the ECRs:
- Byte sequence for calling an ECR.
- Byte sequence for releasing an ECR
- Data block

The data from the ECR to the PC are always transmitted in blocks.

The communication between a PC and a certain ECR is performed in the following order:

a) ECR Selection - contains a sequence of several bytes for calling the ECR and an answer from the ECR ( The ECR answers only if it is in a condition, allowing it to answer)
b) Transmission of data blocks between the PC and a certain ECR
c) ECR Release - after this procedure the PC can select another ECR.

A sucsessful transmission means transmitting of a character for begining of a block, the block itself, control characters and receiving from the ECR a control character for successfull transmission.

2. COMMUNICATION MODES

There are two communication modes:
“IN-LINE” Communication
“ON-LINE” Communication

Note: Before entering any of these modes it is necessary to program the ECR for the selected Communication Mode.

2.1. IN-LINE Communication

The “In-Line” communication mode can be performed when the ECR is programmed for IN-LINE Communication. In this mode the ECR is always available for the PC.
The ECR is set in communication mode by turning the rotary switch to “OFF” position and pressing “9” from the ten keys.
In Communication mode the ECR can be in “OFF-LINE” condition when it waits a call from the PC, or in “ON-LINE” condition when it is transmitting data with the PC.
When the ECR is in OFF-Line condition on the ECR display will be displayed a message “OFF-ln”. While in this condition the ECR will accept only the input from the rotary switch.
The communication between the PC and the ECR is initiated by the PC. The PC sends a calling sequence to the ECR for “in-line” communication:

Control Character TAKE (11H or ^Q)
Control Character TAKE (11H or ^Q)
Most Significant byte from the two digit Logical number as an ASCII Symbol
Least Significant byte from the two digit Logical number as an ASCII Symbol

The ECR answers with a block containing:
Control character for beginning of a packet BEG (0AH or ^J)
Serial number of the ECR (6 DIGITS) and “;”
Control character for end of block END (0DH or ^M)
Two control bytes CRC

After this the ECR waits for confirmation from the PC. The confirmation is as follows:

Control character for confirmation ACK (06H or ^F)

After the communication is established on the ECR display will be displayed “on-ln”. In this condition the ECR will not respond to any action from the keyboard or from the rotary switch until it is relaesed from the computer or is released on time-out.
As far as the ECR is connected to the PC it will accept and execute COMMANDS, which are sent from the PC. On execution of these COMMANDS the ECR sends back to the PC data and results from the command execution. With the help of these commands the PC can program and report the ECR

3. COMMANDS IN IN-LINE MODE

When the ECR is connected in “in-line” mode it accepts and executes the commands it receives from the PC.
For some of the commands: N (nothing), P(print) and W(write) the ECR returns only the result form the execution D(Done) or E(Error).
Yet, some other commands like R(Read), T (table) and A (all) include the transmission of blocks with data from the ECR to the computer. After each block of data the PC sends a command for continuing the operation G (go) or S (stop) for discontinuing the operation. After the last block of data is sent to the PC, the ECR transmits to the PC a block D (done) for end of transmission.

The format of the commands is as follows:
- command code - a Capital letter
- command parameters
The parameters are ASCII strings, devided by delimeter “;”. The number of parameters depends on the command. The command code and the parameters are not devided by “SPACES”.


COMMAND N (nothing ) empty command

Command format:
N ;

When this command is executed the ECR will return a reply for successfull execution : D (Done).
This command is used for checking if the ECR is still connected to the PC.

COMMAND P (print) - prints a string

Command format:

P

The string is printed on the ECR printer. If the string is less than 18 characters, the remaining part will contain spaces. If the string contains more than 18 charcters only 18 are printed. The remaining are discarded.
The ECR returns a reply for successful completion of the command D (done)



COMMAND W (WRITE) - programming of the different fields from the tables.

Command format:

W tabl; record; field1; field2; ...... field p;

tabl Table number
record Record number
fieldx field contents
p Number of the programable fields in the Table

W (write) command is used for programming a certain field or fields from the specified Table with the desired content.
The number of the table should be a valid number for a table which is programable. It is not possible to change the content of a Table from the Fiscal memory (EPROM) by using this command.
For each of the programable fields from the table it is necessary to program:
- only “;” if the content of the filed does not change
- the new content of the field , followed by “;”. After the last field it is also necessary to have the delimeter “;”.

The new content of the fields must match the type of the corresponding field. This means that:
- for fields which contain characters (text) the string must be written from left to right in the field.
- for fields which contain digits the digits must be written from right.
- in the fields “price” the digits must be from the type “P.PP ;”
- in the fields “quantity” the digits must be from the type “Q.QQQ ;”.
When the contents of the fields “Price” and “Quantity” are 0, it is possible to send only “0 ;”.
The new contents of the fields are programmed only if the entire command is executed correctly. After a successful programming the ECR will return a command D (done)

The programming will be unsuccessful if:
- there is no such table or record;
- the specified table is not a programable table;
- the number of the specified field is different from the programable fields in this table.
- for some of the fields, there is a type mismatch or the length is different from the specified one.
In this case the ECR will return an error message: E (error)


COMMAND R (READ) - reading a record from a table

Command format:

R tabl ; record ;

where:

tabl Table Number
record Record Number

After executing this command the ECR will return a block, containing the data from the specified record.
This block will contain the data in the following order:

tabl ; record ; field1 ; field2 ; .......; field n;

where

tabl Table Number
record Record Number
fieldx field contents
n Number of all fields in the Table

The content of the fields containing characters is transmitted only when they are not empty. When a certain field is empty the ECR will transmit only “;”.
When a field containing characters contains spaces to fill up the field, the ECR will transmit only the characters and the spaces will be omitted.
The numbers form the filed “PRICE” are transmited as “P.PP ;” and the numbers from the fields “QUANTITY” are transmitted as “Q.QQQ ;”.
When a number field contains 0, only a “;” is transmitted.
After the ECR transmits a block with data it expects that the PC will send a permission to continue (block G (go)).
Following this the ECR will send a reply for successful completion of the command: D (done).



COMMAND T (Table) - read data from a Table

Command format:

T tabl ; beginning record ;

where

tabl Table Number
beginning record Number of the beginning record

The ECR transmits one block for each record in the Table beginning with the specified beginning record. ( For Table 1 transmits only these rows from the table which contain PLU Code and there were sales from this PLU).
The transmitted blocks contain the data in the format described by “R” command.
After transmitting each block with data the ECR expects that the PC will send a command for continuing G (go).
After transmitting the last block from the table the ECR transmits a message for successful completion of the command by D (done).
If instead of a block for continuing G (go) the PC sends a command for abortion of the transmission (S (stop)), the ECR will abort the transmission of data and will send a message for successful completion of a command D (done).

COMMAND A - Reading of a daily report from the ECR

Command format:

A ;

When receiving this command the ECR will transmit one block for each record from the tables which are necessary for forming a daily report before the ECR is cleared. The tables are transmitted in the following order - 9,0,3,10,11,12.
The format of the transmitted blocks is as described in R command. The only difference is that when executing “A” command the contents of the character fields is not transmitted.
After transmitting each block with data the ECR expects tha PC will send a comand for continuing G (go).
After transmitting the last block from the table the ECR transmits a message for successful completion of the command by D (done).
If instead of a block for continuing G (go) the PC sends a command for abortion of the transmission (S (stop)), the ECR will abort the transmission of data and will send a message for successful completion of a command D (done).

INVALID COMMAND

In all cases when the ECR receives a block containing invalid command: invalid code or incorrect number or type of parameters it will return an error message E (error).




DATA TRANSMISSION IN ON-LINE MODE

When it is necessary to exchange data in “REG” mode the ECR waits to be polled by the PC. The PC sends a calling sequence for communication in “On-Line” mode. The ECR answers by sending its ID number and the requested data.
After a successful transmission there are two possible actions:
- If the ECR does not expect any data from the PC - e.g. after reporting for a sale of an article which is programmed in the ECR memory, it will continue its normal operation in REG mode.
- If the ECR expects some data from the PC - e.g. when selling an article which is not programmed in the ECR, it will remain connected to the PC for 1 sec. During this time it must receive the requested data from the PC. After a sucessful transmission the ECR rerurns in REG mode and performs a sale with the received parameters.

Type of messages which are transmitted to the PC:

- message for a sale of an article which is programmed in the ECR memory
- request for a sale of an article which is not programmed in the ECR memory
- request for service based on a keycode
- message for %+ or %-
- message for receipt completion

Each message or request contains:
- ECR serial number
- the sequence number of the message modulo 10 - a digit from 0 to 9
- message code
The parameters in the messages are delimited by “ ; “

Message for a sale of an article which is programmed in the ECR memory

This message is transmitted if the type of communication is 2 or 3.
This message is transmitted after pressing a key for selling an article or article group ( PLU Key or any of the Keys 1-8). In this case the article must be programmed in the ECR memory. Regardless of whether the message is transmitted successfully or not the article is sold and this sale is registered in the ECR.

Message format:

ID ; sequen ; 0 ; PLU code ; price ; quantity ;

where

ID ECR serial number;
sequen sequential number of the message modulo 10;
0 a message code for an article which is programmed
in the ECR memory;
PLU code PLU code of an article;
price is the programmed price for a PLU or the price which is input
form the keyboard for an article group;
quantity is the quantity which is input from the keyboard or “1.000”
if input quantity is missing.

Reguest to sell an article which is not programmed in the ECR memory

This request is transmitted if the type of communication is 2 or 3.
This message is transmitted after pressing a key for selling an article or article group ( PLU Key). In this case the article is not programmed in the ECR memory. An article can be sold from teh ECR only if teh communication between PC and ECR was successful and ECR receives all the necessary parameters of the PLU to be sold.

The format of the request from the ECR to the PC is:

ID ; sequen ; 1 ; PLU code ; price ; quantity ;

where:

ID ECR serial number;
sequen sequential number of the message modulo 10;
1 a message code for an article which is not programmed in the ECR
memory;
PLU code PLU code of an article;
price is the price which is input form the keyboard;
quantity is the quantity which is input from the keyboard or “1.000”
if input quantity is missing.

After this request is transmitted from the ECR to the PC, the ECR is waiting to receive all the necessary parameters of the PLU which is to be sold. These parameters are as follows:
- PLU code
- PLU name
- article price
- existing quantity
- department number
- item group number
- VAT number
- flag for reporting by price (article group)
- flag for disabling sales when the quantity is zero.


Request to sell an article with code, read by barcode scanner

The format of this request is as follows:

ID ; sequen ; 7 ; barcode ; price ; quantity ;

where:

ID ECR serial number;
sequen sequential number of the message modulo 10;
7 a message code for an article for which a barcode is existing in the PC;
price is the price which is input form the keyboard;
quantity is the quantity which is input from the keyboard or “1.000” if input quan
tity is missing.

After this request is transmitted the ECR waits to receive from the PC all the necessary parameters to be able to sell this article. These parameters are as follows:

- PLU code (it is possible not to transmit it)
- article name
- article price
- existing quantity
- department number
- number of item group
- VAT number
- flag for reporting by price (article group)
- flag for disabling sales when the quantity is zero.

Message for %+ and %-

This message is transmitted only if the ECR is in communication modes 2 or 3.
The message is transmitted after one of the keys “%+” or “%-” is pressed.
Message format is as follows:

ID ; sequen ; 2 ; perc code ; amount ; percentage ;

where:
ID ECR serial number;
sequen sequential number of the message modulo 10;
2 a message code %+ or %-
perc code when 0, %+ or %- applies only for the last article sold;
when 1, %+ or %- applies for the subtotal sum up to now in
the receipt
amount the amount on which %+ or %- is applied.
percentage is the percentage which is applied. When this value is positive
it is %+ and when it is negative it is %-.

Message for completing a receipt

This message is transmitted after any of the following keys is pressed: TOTAL, CHECK, CHARGE, CARD.

The message format is as follows:

ID ; sequen ; 3 ; payment type ; operator ; bill ; table ; department/ order num ; receipt ;
Z clear ; total due ; sum A; sum B; sum C ; sum D ; sum E ; sum F ; sum G; sum H;
sum paid ;

where:

ID ECR logical ID number;
sequen sequential number of the message modulo 10;
3 code for type of payment;
payment type payment type. It is:
= 0 when TOTAL key is pressed
= 1 when CHCK key is pressed
= 2 when CHARGE key is pressed
= 4 when CARD key is pressed
operator number of operator, waitor
bill is number of bill in restaurant mode
table is number of table in restaurant mode
department/ is the number of department or order
order num number of orderd in restaurant mode
receipt number of receipt
Z clear is the number of Z and clear report to which this receipt
belongs;
Total due is the sum due for payment before pressing one of the above keys
sum A sum due according to TAX Group A
sum B sum due according to TAX Group B
sum C sum due according to TAX Group C
sum D sum due according to TAX Group D
sum E sum due according to TAX Group E
sum F sum due according to TAX Group F
sum G sum due according to TAX Group G
sum H sum due according to TAX Group H
sum paid the sum which is paid by customer

Request for srevice based on a keycode

This request is transmitted only when the communication mode is 2 or 3. The request is transmitted from the ECR to the PC after pressing a keycode (an integer number) followed by pressing key “#”. Based on the keycode the ECR will receive an information which it has to print. The information consists of 5 lines.
- Any of the lines can be omitted if the information sent from the PC does not contain any characters.
- A total of 17 characters can be printed on one line. When the transmitted characters are less then 17, spaces are added up to 17 characters. The last 18 position always contains “#”.
- To print an empty line or line feed (LF) it is enough to send only one character - space.

NOTE: for MP-500T with electronic journal the number of lines characters per line is 23.
The format of this request is as follows:

ID ; sequent ; 4 ; integer ;
where:
ID ECR serial number;
sequent equential number of the message modulo 10;
4 code for request for service;
integer an integer up to 9 digits

After sending this request for service the ECR waits for 5 lines of data:

line1 ; line2 ; line3 ; line4 ; line5 ;
where:
lineN is the data to be printed on the printer.

PAYMENT WITH CARD

After registering all sales it is possible to pay with a card. For combined payment (cash, check and card) the card payment should be the last. Always when paying with a card the total remaining sum is withdrawn from the card. When the payment is made only by card the total sum due is withdrawn from the card.
Payment with card is performed as follows:
It is recommended that the operator presses key SBTL (Sub Total). The sum due will be displayed on the display.
1. The operator presses key PY2 - credit. The display will show PIn. The ECR waits for a PIN code to be entered either from ECR keyboard or from a PIN keyboard. Then the PY2 key must be pressed.
If you do not use PIN code it is enough to press key PY2.
2. The display will show CArd
3. The operator reads the card by a card reader and on the display “cb. Card” is displayed.
3.1. Instead of performing p. 3, it is possible that the operator inputs an up to 9 digit number and then presses key pY2. In this case the message from the ECR to the PC will contain 8 instead of 9.
4. The ECR sends a message to the PC with the following format:

ID ; sequent ; 9 ; card code ; sum due ; PIN
5. There are two possible actions now:
5.1. Computer denies payment with card
The computer sends to the ECR a message as follows:
. ; line2 ; line3 ; line4 ; line 5 ;

The ECr will print 4 lines of text received by the PC.
Then it will display C on the display.
The operator has to press key “C” (clear).
After this it is possible to:
- make a new attempt to pay with card by pressing PY2 and reading the card;
- pay in other way;
- void some or all sales in the receipt.

5.2. Confirmation by the PC.
PC sends to the ECR a message with the following format:

line1 ; line2 ; line3 ; line4 ; line5 ;

The ECR will print up to 5 lines of text which were received from the PC. With the help of these 5 lines the PC forms the receipt.
After this the ECR prints “CREDIT” and the sum which was paid by card.

Any of the lines can be omitted if the information sent from the PC does not contain any characters.
A total of 17 characters can be printed on one line. When the transmitted characters are less then 17, spaces are added up to 17 characters. The last 18 position always contains “#”.
To print an empty line or line feed (LF) it is enough to send only one character - space.
%+, %- performed from the PC (messages C, D, and E)



MESSAGE C

When the ECR is programmed so that %+ and %- are disabled (table 4, record 1/2, field 1=0) it will send to the PC a message S.
In registration mode when the operator has to perform %+ or %- it is enough to press only any of the keys “%+” and “%-”.
The ECR sends to the PC the following message:

ID ; sequen ; C ; perc code ; amount ; percentage ;

ID ECR serial number;
sequen sequential number of the message modulo 10;
C a message code for %+ or %- from teh PC
perc code when 0, %+ or %- applies only for the last article sold;
when 1, %+ or %- applies for the subtotal sum up to now in the receipt
amount the amount on which %+ or %- is applied.
percentage = 100.00 when it is %+
= - 100.00 when it is %-

If the PC does not answer or answers with a message for an invalid format, the ECR will display “C”
If the PC answers as follows:
C ; xx.xx ; ; ; ;
where:
C is a capital letter C
xx.xx is percentage (up to 4 digits)

It is possible that the string “xx.xx” contains “.” or “-”. These symbols are ignored by teh ECR. Whether it is %+ or %- is decided by the operator when he/she presses key “%+” or “%-” and not by the contents of teh string.

After the ECR performs the operation it sends to the PC a message from the type 2.

MESSAGES ‘D AND ‘E’

The ECR will send messages D and E regardless of whether %+ and %- are enabled or disabled (table 4, record 1/2, field 1).
These messages are transmitted to the PC to ask for %+ or %- for a customer who is registered in a loaylty system and has his ID number in this system. The customers can be registered with ID number and PIN or with loyalty card and a pin. The input of the PIN is not obligatory.

In order to ask the PC for %+ or %- for a certain customer who is a member of the loyalty system it is necessary to press the key RA after all sales are performed.
The display will show -- pin --.
The operator inputs PIN and again presses key RA, or the customer inputs his PIN from the PIN terminal. The PIN number can be omitted by pressing directly once again key RA.
The display will show: CArD
The operator inputs the number of the loyalty card, then presses key RA and reads the card with a reader (it can be magstripe reader or a barcode reader etc.). The display will show “cb. CArD”

The ECR will send a message to the PC as follows:

ID ; sequen ; D ; card number ; amount ; pin ;
when the number of the card is input from the ECR keyboard or

ID ; sequen ; E; card number ; ammount ; pin ;
when the card is read through a reader.

If the PC does not reply or replies with a message for invalid format, the display will show “C”.

If the PC replies as follows:

C ; ; xx.xx ; ; ; ; for %+
C ; ; -xx.xx ; ; ; ; for %-
where
C is a capital letter “C”;
xx.xx is %+ or %-
It is possible that the string ‘xx.xx” contains “.” but it is ignored by the ECR. Whether it is a discount or surcharge is decided by the symbol “-” in the string.
The ECR performs a discount or surcharge on the total amount in the receipt, then prints the remaining lines in the receipt and sends a message “2” to the PC.
After a successful discount or surcharge new sales in the receipt are not allowed.

The ECR does not perform a sale, after arequest to the PC.

If the ECR requests a sale with messages 1 or 7 and the PC replies as expected but the sale is impossible due to some reason (e.g. disabled void or storno, disabled TAX group etc.), the ECR will send to the PC on the next polling a messge with:

- the next sequential number;
- type of message B (if the request was 1) or F ( if the request was 7)
- the same PLU code or barcode for the article
- the same price (if it was contained in the first message)
- and the quantity with “-” symbol.

Command WAIT from the PC to the ECR

After a successful transmission of a message from the ECR to the PC, the ECR waits for a reply from the PC for 10 sec.
After the ECR receives the requested block it returns in REG mode, where it is performing sales, payments, or printing of the data received from the PC.
If the PC is busy during this 10 sec it can send to the ECR a WAIT command. For this the PC must send a block, the first byte of which is “1F”. The remaining bytes in the block do not have any meaning.
After the block is received from the ECR, it will answer with an ACK and will remain in this state until the next polling.
When the ECR is polled again it will transmit the same block with the same sequential number.
The PC can send a reply to the request or a new command WAIT



DATA FORMAT AND COMMUNICATION SPEED

The data format is:
- 1 start bit
- 8 data bits
- no parity
- 1 stop bit

FORMAT OF THE CALLING AND RELEASING PROCEDURES

There are two calling procedures - the first is for “in-line” / OFF,9/ and “on-line” /REG mode/ for connecting during an opened receipt and the other is for “in-line” connection between the receipts /in REG mode/.
The ECR waits for a call when:
- OFF,9 mode, when the display shows “OFF-ln” and the ECR waits to be programmed or reported.
- REG mode after a receipt is completed and before opening a new receipt regardless of the content of field 8 from table 2.
NOTE: during the period of “in-line” connection the ECR display will show “on-ln”
- REG mode during an opened receipt according to the content of the field 2 from Table 2.
If the ECR is waiting for a call but the call is not received during 1 sec (there is no any byte received on the RxD line of the ECR) the ECR exits the wait state.

- Control caharacter TAKE (11 HEX or ^Q)
- Control caharacter TAKE (11 HEX or ^Q)
- ASCII symbol for the most significant digit of the logical ID number of the ECR
- ASCII symbol for the least significant digit of the logical ID number of the ECR.

It is recommended to transmit 10 bytes containing FF, which guaranties the response of the ECR.

PROCEDURE FOR RELEASING AN ECR

The procedure for releasing is used in “in-line” mode / mode OFF,9/ and mode between receipts.
For these modes the ECR is released without any procedures:
- after 10 sec if during this time on the RxD input of the ECR there were no any bytes BEG;
- after BEG is received 8 times and there was no successful transmission of a block due to:
a) transmission of NAK after finding a mismatch in the received CRC and the one calculated by the ECR;
b) pause of 6 bytes on the RxD line of the ECR;
c) overflow of the input buffer.

Procedure for releasing in “in-line” mode

Control character Restore ( 13 HEX or ^S)
Control character Restore (13 HEX or ^S)
It is recommended to send 5 bytes FF before sending the first RESTORE character.

When the connection is “on-line” /REG mode/ the ECR is released as follows:
- after the transmission of the planned data;
- if a block is transmitted unsuccessfully;
- after a blcok which requests a reply from the PC and
a) after 1 sec there was no a single byte BEG on the RxD line of the ECR;
b) after BEG is received 8 times but the block is not been received due to:
- transmission of NAK after finding a mismatch in the received CRC and the one calculated by the ECR;
- pause of 6 bytes on the RxD line of the ECR;
- overflow of the input buffer

The overflow can be caused by:
- call from another ECR
- call from the same ECR
It is recommended to transmit 5 bytes FF before the first TAKE command. This guarnties that the command will be received by the ECR.
- or with aprocedure for releasing in “in-line” mode.

It is recommended that during polling of one or several ECRs before inserting a pause in the polling cycle to use this procedure. The pause should be multiple of 55 msec and every 55 msec one byte FF should be sent to the ECR.

BLOCK FORMAT

All bytes in the block are ASCII characters except the two control bytes CRC.
A sucessful transmission of a block from the ECR includes transmitting of:
- control character for beginning of a block BEG ( 0A HEX or ^J)
- data bytes
- control symbol for end of block END ( 0D HEX or ^M)
- 2 control bytes CRC.

and receiving of a control character for acknowledging the transmission ACK ( 06 HEX or ^F)

Unsuccessful transmission of a block will occur when after the transmission of the data from the block:
- in the incoming stream there is a period of 6 bytes, when no byte is received. ( If the received symbols are not ACK, NAK or a procedure for releasing the line in in-line or on-line mode, the ECR will continue to listen to teh line).
- a character for unsuccessful transmission NAK (15 HEx or ^U) is received. After NAK is received the ECR makes up to 8 attempts to transmit the block. If all attempts fail the ECR will:

- in in-line mode discontinue the execution of the command.
- in on-line mode after an unsucessful transmission the ECR will exit the waiting state for ACK and:
- after an unsuccessful transmission type 1 the ECR will remain in the wait state for next call. During the next call the ECR will try to transmit the same block. This will be repeated up to 8 times. After the 8-th call the ECR will exit the wait state and during the next session with teh PC will transmit a new message( a block with a new sequential number).
- After an unsuccessful transmission of a block from type 2 the ECR will cancel its attempts to transmit the block. During the next session with teh PC it will transmit a new block with a new sequential number.
The block lenght depends on the transmitted data, but does not exceed 128 bytes when the block is transmitted from the PC to the ECR and 256 bytes when the block is transmitted from the ECR to the PC.

ALGORITHM FOR CRC CALCULATION

The two CRC bytes are calculated according to the formula x^15 + 1. In the calculation are included all data bytes plus the byte for block end. Every byte passes through the calculation register from teh MSB to LSB.
Three working bytes are used - S1, S0 and TR
S1 - Most significant byte from the CRC ( it is transmitted immediatelly after END)
S0 - Least significant byte from the CRC ( It is transmitted after S1)
TR - the current transmitted byte in the block.

The CRC is calculated as follows:
1. S1 and S0 are zeroed
2. TR is loaded with the current transmitted byte. The byte is transmitted.
3. Points 3.1 and 3.2 are executed 8 times:
3.1. S1, S0 and TR are shifted one bit to the left.
3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are inverted.
Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including byte END.
4. TR is loaded with 0 and point 3 is executed
5. TR is loaded with 0 and point 3 is executed
6. Byte S1 is transmitted
7. Byte S0 is transmitted

ALGORITHM FOR CRC CHECK ON RECEIVING

Three working bytes are used S1, S0 and RC

S1 - Most significant byte from the CRC ( it is received immediately after END)
S0 - Least significant byte from the CRC ( transmitted after S1)
RC - the current received byte in the block ( beginning from the first byte after BEG and ending 2 bytes after END).

The CRC is obtained as follows:
1. S1 and S0 are zeroed
2. RC is loaded with the current received byte
3. Points 3.1 and 3.2 are executed 8 times:
3.1. S1, S0 and RC are shifted 8 times to the left
3.2. if the MSB of S1 is 1 then MSB of S1 and LSB of S0 are inverted.
Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including 2 bytes after END.
S1 and S0 must be 0.


The successful receipt of a block includes the transmission of an ACK symbol after confirming the CRC.
For unsuccessful receipt of a block when the connection ECR/PC was successful the following cases can be distinguished:
- in on-line mode for 1 sec there was no any BEG ;
- in in-line mode for 10 sec there was no any BEG commands;
- 8 times BEG command is received but the receipt of a blcok was unsuccessful.

It is recommended that the PC driver transmits 4 bytes FF after transmission of a block.
If during this period there was no any interrupt from the RxD line due to ACK, it is necessary that after a period of 55 msec the block is transmitted again.

Moduri de programare si raportare din calculator Datecs

Moduri de programare si raportare din calculator

Aceste comenzi se executa daca:
-- AMEF este in modul “OFF-9” (din stare OFF tasta 9) sau
-- AMEF este in modul “REG” si este permisa “programare si raportare AMEF in mod REG ) Tabela 2 camp 8=1.
AMEF trebuie sa fie conectat la PC prin portul serial de conectare. Viteza de comunicatie este setata din Tabela 2 camp 9:
1: 4800 bps
2: 9600 bps
3: 19200 bps
4: 38400 bps (default).
Comenzile sunt valabile numai cand sunt indeplinite conditiile valabile in mod de lucru din tastatura AMEF.

1. Comenzi de citire si inregistrare in baza de date articole
In baza de date a articolelor poate sa fie de la 0 la 2400
1.1. Comanda citire parametrii articole
R0; ;
raspuns 0;; ; ; ;;;;
;;;;;;

T0; ;
raspuns 0;; ; ; ;;;;
;;;;;;

Ca raspuns al comenzii ‘T’ se transmit datele pentru articole cu codul PLU edal sau mai mare decat cel setat, care are au cantitae sau sume diferite de 0. Aceasta comenda se foloseste cand se efectueaza raport pe articole


1.2. Comanda inregistrare parametrii unui articol

W0;; ; ; ;;;;
;;;;


2. Comenzi ...

Vanzare din Calculator Datecs

Vanzare din Calculator

Aceste comenzi se lanseaza din calculator ca urmare a comenzi primite din AMEF ‘A’.
AMEF transmite catre PC comenzi ‘A’ cand se afla in modul “REG” si este setata tabela 2 camp 8 =2
AMEF trebuie sa fie conectat la PC prin portul serial de conectare. Viteza de comunicatie este setata din Tabela 2 camp 9:
1: 4800 bps
2: 9600 bps
3: 19200 bps
4: 38400 bps (default).
Comenzile sunt valabile numai cand sunt indeplinite conditiile valabile in mod de lucru din tastatura AMEF.


Format comanda ‘A’

<1>;<2>;<3>;<4>;<5>;<6>;<7>;<8>;<9>;<10>;<11>;<12>;<13>;<14>;<15>;<16>;

<1> numar de ordine al mesajului – 0...9
<2> tip mesaj = ‘A’ – din tastatura
<3> flag - = 0 – tastatura nu este blocata ( nu se foloseste)
= 1 – tastatura blocata
= 2 – tastatura blocata si 90% din JE este plin.
<4> numar operator
<5> numar bon fiscal
<6> suma intermediara (subtotal)
<7> flag = 0 – nu sunt vanzari (nu este deschisa vanzarea)
= 1 – sunt vanzari (bon fiscal deschis )
= 2 – (dieschis nefiscal )
<8> numar raport Z
<9> suma pe grupa de TVA 1
<10> suma pe grupa de TVA 2
<11> suma pe grupa de TVA 3
<12> suma pe grupa de TVA 4
<13> suma pe grupa de TVA 5
<14> suma pe grupa de TVA 6
<15> suma pe grupa de TVA 7
<16> suma pe grupa de TVA 8

• campuri <9>...<16> se transfera numai dupa ce comanda STL a fost executata

Comenzi executate de AMEF ca raspuns al comenzii “A”

1. Comanda‘L’ – vanzare articol
L;; ; ; ;;;;
;;

2. Comanda‘С’ – adaos si discount
C;;;;;;
unde:
- flag pentru % adaos sau discount
0 = pentru “%+” - adaos
1 = pentru “%-“ - discount
- valoarea procentuala a adaosului sau discountului. Daca aceasta este 0 atunci se ia in considerare valoarea deja programata in AMEF

3. Comanda‘I’ – introducere si scoatere de sume din sertar
I;;;;;;
unde:

- 0 pentru RA
- 1 pentru PO

4. Comanda ‘Е’ – inchidere vanzare(inchidere bon fiscal)
E;;;;;;
unde:
- tipul platii
- 0 = numerar 0
- 1 = plata 1 (card )
- 2 = plata 2 (card)
- 4 = STL
- 8 = plata in valuta alternativa, rest in valuta alternativa.
- 9 = plata in valuta alternativa, rest in valuta de baza.
- totalul platii sau 0 pentru totalul platii 0 ( in numerar), la plata 4 =0.

5. Comanda ‘D’ – reglare data si ora
D;;;;;;
Data nu poate sa fie mai mica decat data ultimei inregistrari in MF.

6. Comanda ‘A’ – rapoarte
А;;;;;;
unde:
- tipul raportuluiтип на отчета
- X = citire raport zilnic
- Z = raport zilnic cu golire
7. Comanda ‘X’ – deschidere bon fiscal si tiparire text
Х;;;;;;

8. Comanda ‘Y’ – deschidere bon nefiscal si tiparire text
Y;;;;;;

datecs drivers