Giter Site home page Giter Site logo

lan-4gatelibrary's Introduction

Реализация кассового протокола LAN-4Gate

badge

Release

!!!ВНИМАНИЕ: Текущая версия библиотеки несовместима с версией 0.9.4 и ниже!!!

Для миграции прочтите файл

Содержание

  1. Описание
  2. Требования
  3. Зависимости
  4. Подключение к проекту
  5. Использование

Описание

Библиотека реализует протокол кассового взаимодействия LAN-4Gate компании ЛАНТЕР.

Подробная документация сгенерирована Javadoc. Доступна по ссылке и в шапке файла

Библиотека находится в процессе миграции на Android SDK

Требования

  • Java 1.8
  • Gradle 6.1.1

Зависимости

Подключение к проекту

Для подключения библиотеки необходимо:

  1. добавить в репозитории репозиторий jitpack
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Добавить библиотеку в зависимости проекта.
dependencies {
    implementation 'com.github.LanterECR:LAN-4GateLibrary:v1.1.0'
}

Использование

Ниже приведены фрагменты кода в качестве примера.

  1. Реализовать интерфейсы колбэков:
  • ICommunicationCallback
import org.lanter.lan4gate.Callbacks.ICommunicationCallback;

class CommunicationCallback implements ICommunicationCallback {
    public void communicationStarted(ILan4Gate initiator) {
        //Реакция на событие запуска соединения
    }

    public void communicationStopped(ILan4Gate initiator) {
        //Реакция на событие остановки соединения
    }

    public void connected(ILan4Gate initiator) {
        //Реакция на подключение к терминалу
    }

    public void disconnected(ILan4Gate initiator) {
        //Реакция на отключение от терминала
    }
} 
  • IResponseCallback
import org.lanter.lan4gate.Callbacks.IResponseCallback;

class ResponseCallback implements IResponseCallback {
    public void newResponseMessage(IResponse response, ILan4Gate initiator) {
        //Реакция на получение ответа от терминала
    }
} 
  • INotificationCallback
import org.lanter.lan4gate.Callbacks.INotificationCallback;

class NotificationCallback implements INotificationCallback {
    public void newNotificationMessage(INotification notification, ILan4Gate initiator) {
        //Реакция на получение уведомления
    }
} 
  1. Создать соединение
  • TCP сервер, обслуживающий одно соединение по заданному порту 20500. Без указания параметра, будет использован порт по умолчанию - 20501. Порт взаимодействия согласуется при интеграции. Необходима возможность задавать вручную.
import org.lanter.lan4gate.Communication.CommunicationFactory;
import org.lanter.lan4gate.Communication.ICommunication;

ICommunication communication = CommunicationFactory.getSingleTCPServer(20500);
  • TCP клиент на с портом и адресом по умолчанию. Без указания параметров, будет использован порт и адрес по умолчанию - 127.0.0.1:20501. Порт и адрес взаимодействия согласуется при интеграции. Необходима возможность задавать вручную.
import org.lanter.lan4gate.Communication.CommunicationFactory;
import org.lanter.lan4gate.Communication.ICommunication;

ICommunication communication = CommunicationFactory.getTCPClient();
  • Декоратор, обслуживающий TCP сервер предыдущего пункта. Используется для определения длины сообщений. Использование данного параметра согласуется при интеграции
import org.lanter.lan4gate.Communication.CommunicationFactory;
import org.lanter.lan4gate.Communication.ICommunication;

ICommunication control = CommunicationFactory.getSizeControlDecorator(communication);
  1. Создать менеджер библиотеки ILan4Gate
import org.lanter.lan4gate.Lan4GateFactory;
import org.lanter.lan4gate.ILan4Gate;

int ecrNumber = 1;

ILan4Gate gate = Lan4GateFactory.getLan4Gate(ecrNumber, control);
  1. Привязать колбэки к менеджеру
gate.addCommunicationCallback(new CommunicationCallback());
gate.addResponseCallback(new ResponseCallback());
gate.addNotificationCallback(new NotificationCallback());
  1. Запустить менеджер
gate.start();
  1. Остановить менеджер.
gate.stop();
gate = null;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.