miércoles, 13 de julio de 2016

Bill Acceptors Apex 5000/7000 Simple Driver gcc (Raspberry Pi /Banana Pi/ PC Linux)


Apex 5000/7000 Simple Driver (gcc) 

 Bill Acceptor Apex 7000
 
Aquí se ha usado de la librería WiringPI los archivos wiringSerial.c, wiringSerial.h ademas de la función Delay(), pero el código funciona en ambos (Raspberry Pi / Banana Pi/ PC Linux).

En el caso de la librería wiringSerial, esta debería trabajar para 7 bits de datos, 1 bit de paridad EVEN.
Por lo que se ha modificado la función serialOpen ;


options.c_cflag |= PARENB; // Paridad activada.
options.c_cflag &= ~PARODD; // Paridad EVEN.
options.c_cflag |= CS7; // 7 bits de datos.

Este simple driver consta de 5 archivos; main.c, apex.c, apex.h, wiringSerial.c, wiringSerial.h. Para compilarlos;
---------------------------------------------------------+
 Descargar Código Fuente

Disculpen si no respondí antes, password: "sydbernard", "sydbernard1", "maniacmansion" ,"maniacmanison1". Alguno ha de servir.
---------------------------------------------------------+
$ gcc -Wall -c main.c wiringSerial.c apex.c
$ gcc -o apex main.o wiringSerial.o apex.o -l pthread
$ rm main.o wiringSerial.o apex.o
---------------------------------------------------------+
 
makefile;

apex: main.o wiringSerial.o apex.o
gcc -o apex main.o wiringSerial.o apex.o -l pthread

wiringSerial.o: wiringSerial.c
gcc -Wall -c wiringSerial.c

main.o: main.c
gcc -Wall -c main.c

apex.o: apex.c
gcc -Wall -c apex.c

clean:
rm main.o wiringSerial.o apex.o
----------------------------------------------------------+
  
Para este ejemplo en la función loop_apex se indica que cuando haya un billete valido, este sea aceptado automáticamente, una vez almacenado el billete se envia el mensaje: Accept bill: #billete
Ademas de los BYTE 0, BYTE1, BYTE2 enviados por el billetero.

Simple driver Apex bill acceptor (Linux Mint, x86)

Raspberry Pi
 
Conexión Rpi - Apex (conector 18 pin)

conector 18 pin (verde-Tx, rojo/blanco-Rx)

Pyramid Bill Acceptors Apex 5000/7000

Los billeteros (Bill Acceptors) Pyramid APEX 5000/7000 :

Comunicación:
Baud rate- 9600
1 start and 1 stop bit
7 data bits (bit 0 = sent first (LSB))
1 parity bit ( even parity)

Inactive Timing – Si el Bill Acceptor no detecta comunicación con el Host dentro de un lapso de 5 segundos, iniciando desde la última comunicación enviada por el host, el bill acceptor:

 
1 – rechazara cualquier billete mantenido en escrow.
2 – Dejará de aceptar billetes hasta que el master inicie la comunicación nuevamente.


Formato común para la transmisión:

| STX | Length | MSG Type and Ack Number | Data Fields | ETX | Checksum |

STX- 0x02 El inicio del mensaje es indicado por 1 byte.

Length- Número de bytes en cada mensaje (binary), incluyendo STX, ETX y Checksum.

Tipo de MSG y número Ack – Un byte de dato.

Tipo de MSG - (Bits 4, 5 y 6 de este byte)

1- Mensajes De Maestro a esclavo (Bill Acceptor).
2- Mensajes de esclavo (Bill Acceptor) a Maestro.

Número ACK - 0 ó 1 (bits 0-3) (Revisar RS-232 Serial Interface Specification

ApexSeries Acceptors para mayor información.

Data- Porción de mensaje, el data consiste de múltiple campos;
Data Fields para los mensajes enviados por el Master. (Byte 0 es enviado primero)
ETX- 03H Byte Fin del mensaje.
Checksum- (1 byte checksum). El cheksum es calculado con todos los bytes (except: STX, ETX y
el checksum mismo). Haciendo (XOR) a todos los bytes.

/* ***************************************************************** */


Campo de datos para el mensaje enviado por el Master

BYTE 0
BIT 0- $1 Accept Enable (Set to a “1” to accept a bill)
BIT 1- $2 Accept Enable (Not used on Apex series acceptors)
BIT 2- $5 Accept Enable
BIT 3- $10 Accept Enable
BIT 4- $20 Accept Enable
BIT 5- $50 Accept Enable
BIT 6- $100 Accept Enable

BYTE 1
BIT 0- Reserved for future use. (Set to 0)
BIT 1- SECURITY (Reserved for future use.)
BIT 2- ORIENTATION (Reserved for future use.)
BIT 3- ORIENTATION (Reserved for future use.)
BIT 4- Escrow (Set = 1 to enable escrow)
BIT 5- Stack (Set = 1 causes bill to be stacked)
BIT 6- Return (Set = 1 causes bill to be returned)

BYTE 2
BIT 0- 6 - Reserved for future use.



Ejemplo (-->):  
02 08 11 7F 00 00 03 66 (Todas las denominaciones activadas)
02 08 10 7F 00 00 03 67 (Todas las denominaciones activadas)




 
Campo de dato enviado por el Slave (Bill Acceptor)

BYTE 0
Bit 0- Idling (Set = 1 if acceptor is in idle state)
Bit 1- Accepting (Set = 1 if accepting a bill)
Bit 2- Escrowed (Set =1 if a bill is in escrow)
Bit 3- Stacking (Set = 1 if a bill is being stacked)
Bit 4- Stacked (Set = 1 if a bill was stacked, Idle (Bit 0) also set during this state)
Bit 5- Returning (= 1 if a bill is being returned)
Bit 6- Returned (Set = 1 if the bill has been returned, Idle (Bit 0) also set during this state)

BYTE 1
Bit 0- Cheated (Set = 1 if acceptor suspects cheating)
Bit 1- Bill rejected (Set = 1 if a bill was rejected)
Bit 2- Bill jammed (Set = 1 if a bill is jammed)
Bit 3- Stacker full (Set = 1 if the stacker is full)
Bit 4- Bill cassette present (Set = 1 if cassette is present)
Bit 5- Reserved for future use (Set to 0)
Bit 6- Reserved for future use (Set to 0)

BYTE 2
Bit 0- Power up (Set = 1 if acceptor is initializing)
Bit 1- Invalid command (Set = 1 if an invalid command was received)
Bit 2- Failure (Set = 1 if acceptor has failed)
Bit 3-5 Bill value field
000 = None/unknown bill or note
001 = $1 or 1 st note type
010 = $2 or 2 nd note type
011 = $5 or 3 rd note type
100 = $10 or 4 th note type
101 = $20 or 5 th note type
110 = $50 or 6 th note type
111 = $100 or 7 th note type
Bit 6- Reserved for future use.

BYTE 3
Reserved for future use.
BYTE 4
Model number (00-7FH)
BYTE 5
Revision of firmware (00-7FH)


Ejemplo (<--):  
02 0B 21 01 10 00 00 14 07 03 28 (Idling, Stacker Presente)
02 0B 20 01 10 00 00 14 07 03 29 (Idling, Stacker Presente)


/* ****************************************************************** */
BYTE 0
typedef union {
    uint8_t byte;
    struct {
        uint8_t idling:1;
        uint8_t accepting:1;
        uint8_t escrowed:1;
        uint8_t stacking:1;
        uint8_t stacked:1;
        uint8_t returning:1;
        uint8_t returned:1;
    };
} rxbyte0;

BYTE 1
typedef union {
    uint8_t byte;
    struct {
        uint8_t cheated:1;
        uint8_t bill_rejected:1;
        uint8_t bill_jammed:1;
        uint8_t stacker_full:1;
        uint8_t bill_cassette_present:1;
    };
} rxbyte1;

BYTE 2
typedef union {
    uint8_t byte;
    struct {
        uint8_t power_up:1;
        uint8_t invalid_command:1;
        uint8_t failure:1;
        uint8_t bill_value_field:3;
    };
} rxbyte2;

Simple Driver Apex 7000(LinuxMint x86)


 

5 comentarios:

  1. ¿puedes detallar la conexion de los pines tanto del apex como en la placa programadora (raspberry pi)?

    ResponderEliminar
  2. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  3. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  4. No tuviste problemas con el ground? en mi caso la lectora se activa pero el serial recive muchos null, que tipo de fuente estas usando para los 12v

    ResponderEliminar
  5. Ha pasado un año desde que vi tu post y nunca pude hacer funcionar mi apex 5000 :( lo conecto como indicas habilito el uart en la raspberry pi 3 ya pase incluso el card config al apex pero cuando lo conecto y ejecturo el shell es como si no pasara nada como si no hubiera comunicacion con la raspberry

    ResponderEliminar