{ struct termios tio; fd = open(device_name, O_RDWR | O_NOCTTY); //if (!fd) //{ // printf("ERROR: Could not open CashCode device."); //} bzero(&tio, sizeof(tio)); /* tio.c_iflag = IGNPAR; tio.c_oflag = 0; tio.c_lflag = 0; tio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD; tio.c_cc[VTIME] = 0; tio.c_cc[VMIN] = 0; */ tio.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); //tio.c_iflag = IGNPAR; tio.c_oflag &= ~OPOST; //tio.c_oflag = 0; tio.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); //tio.c_lflag = 0; //tio.c_cflag &= ~(CSIZE|PARENB); //tio.c_cflag |= CS8; //tio.c_cflag = CRTSCTS | CS8 | CLOCAL | CREAD; tio.c_cflag = CS8 | CLOCAL | CREAD; cfsetospeed(&tio, B9600); cfsetispeed(&tio, B9600); tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &tio);}
void cc_reset(){ int sleep_time = 20000; usleep(sleep_time); write(fd, CC_CMD_RESET, sizeof(CC_CMD_RESET)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); usleep(sleep_time); write(fd, CC_CMD_ACK, sizeof(CC_CMD_ACK)); usleep(sleep_time); write(fd, CC_CMD_POLL, sizeof(CC_CMD_POLL)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); if ((unsigned char)read_buffer[0]==19){ printf("OK");} usleep(sleep_time); write(fd, CC_CMD_ACK, sizeof(CC_CMD_ACK)); usleep(sleep_time); write(fd, CC_CMD_GET_BILL_TABLE, sizeof(CC_CMD_GET_BILL_TABLE)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); usleep(sleep_time); write(fd, CC_CMD_ACK, sizeof(CC_CMD_ACK)); usleep(sleep_time); write(fd, CC_CMD_GET_BILL_TABLE, sizeof(CC_CMD_GET_BILL_TABLE)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); usleep(sleep_time); write(fd, CC_CMD_ACK, sizeof(CC_CMD_ACK)); usleep(sleep_time); write(fd, CC_CMD_SET_SECURITY, sizeof(CC_CMD_SET_SECURITY)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); usleep(sleep_time); write(fd, CC_CMD_IDENTIFICATION, sizeof(CC_CMD_IDENTIFICATION)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); usleep(sleep_time); write(fd, CC_CMD_ACK, sizeof(CC_CMD_ACK)); }
int cc_poll(){ int sleep_time = 20000; usleep(sleep_time); write(fd, CC_CMD_POLL, sizeof(CC_CMD_POLL)); usleep(sleep_time); read(fd, control_bytes, 3); read(fd, read_buffer, control_bytes[2]-3); if ( (unsigned char)read_buffer[0] == 0x81 ) { switch ((unsigned char)read_buffer[1]) { case 0x02: if (LOG_MODE) { save_log("10 rub."); } return 10; break; case 0x03: if (LOG_MODE) { save_log("50 rub."); } return 50; break; case 0x04: if (LOG_MODE) { save_log("100 rub."); } return 100; break; case 0x05: if (LOG_MODE) { save_log("500 rub."); } return 500; break; case 0x06: if (LOG_MODE) { save_log("1000 rub."); } return 1000; break; case 0x07: if (LOG_MODE) { save_log("5000 rub."); } return 5000; break; } } // Ошибка! Вернул купюру обратно. if ( (unsigned char)read_buffer[0] == 0x1C ) { return 1; } usleep(sleep_time); write(fd, CC_CMD_ACK, sizeof(CC_CMD_ACK)); return 0;}
class BillAcceptor : public QObject{public:.... bool reset(); int polling();........private:.... }