Git Product home page Git Product logo

secs4java8's Introduction

secs4java8

Introduction

This library is SEMI-SECS-communicate implementation on Java8.

Supports

  • SECS-I (SEMI-E4)
  • SECS-II (SEMI-E5)
  • GEM (SEMI-E30, partially)
  • HSMS-SS (SEMI-E37.1)
  • SML (PEER Group)

Create Communicator instance and open

  • For use HSMS-SS Passive
    /* HSMS-SS Passive open example */
    HsmsSsCommunicatorConfig config = new HsmsSsCommunicatorConfig();
    config.protocol(HsmsSsProtocol.PASSIVE);
    config.socketAddress(new InetSocketAddress("127.0.0.1", 5000));
    config.sessionId(10);
    config.isEquip(true);
    config.timeout().t3(45.0F);
    config.timeout().t6( 5.0F);
    config.timeout().t7(10.0F);
    config.timeout().t8( 6.0F);
    config.gem().mdln("MDLN-A");
    config.gem().softrev("000001");

    SecsCommunicator passive = HsmsSsCommunicator.open(config);
  • For use HSMS-SS Active
    /* HSMS-SS Active open example */
    HsmsSsCommunicatorConfig config = new HsmsSsCommunicatorConfig();
    config.protocol(HsmsSsProtocol.ACTIVE);
    config.socketAddress(new InetSocketAddress("127.0.0.1", 5000));
    config.sessionId(10);
    config.isEquip(false);
    config.timeout().t3(45.0F);
    config.timeout().t5(10.0F);
    config.timeout().t6( 5.0F);
    config.timeout().t8( 6.0F);

    SecsCommunicator active = HsmsSsCommunicator.open(config);
  • For use SECS-I (onTcpIp)
    /* SECS-I (onTcpIp) open example */
    Secs1OnTcpIpConfig config = new Secs1OnTcpIpConfig();
    config.socketAddress(new InetSocketAddress("127.0.0.1", 10000));
    config.deviceId(10);
    config.isMaster(true);
    config.isEquip(true);
    config.timeout().t1( 1.0F);
    config.timeout().t2(15.0F);
    config.timeout().t3(45.0F);
    config.timeout().t4(45.0F);
    config.retry(3);

    SecsCommunicator secs1 = Secs1OnTcpIpCommunicator.open(config);

Send Primary-Message, and receive Reply-Message

  • Create SECS-II
    /* example */
    Secs2 secs2 = Secs2.list(               /* <L                       */
        Secs2.binary((byte)0x81)            /*   <B  0x81>              */
        , Secs2.int2(1001)                  /*   <I2 1001>              */
        , Secs2.ascii("error message")      /*   <A  "error message">   */
    );                                      /* >.                       */
  • Send Primary-Message
    /* Send S5F1 W. example */
    Optional<SecsMessage> reply = passive.send(
        5           /* Stream-Number   */
        , 1         /* Function-Number */
        , true      /* W-Bit           */
        , secs2     /* SECS-II         */
    );
  • Receive Reply-Message

    SecsCommunicator#send is blocking-method.
    Blocking until reply-message received.
    Optional has value if W-Bit is true.
    Optional is empty if W-Bit is false.
    If Timeout-T3, throw SecsWaitReplyMessageException.

Received Primary-Message, parse, and send Reply-Message

  • Add Listener
    /* Add-Listener example */
    active.addSecsMessageReceiveListener((SecsMessage msg) -> {

        int strm     = msg.getStream();     /* Stream-Number   */
        int func     = msg.getFunction();   /* Function-Number */
        boolean wbit = msg.wbit();          /* W-Bit           */
        Secs2 secs2  = msg.secs2();         /* SECS-II         */
    });
  • SECS-II parse
    /* example Receive Message */
    S5F1 W
    <L [3]
        <B  [1] 0x81>           /* ALCD (0, 0) */
        <I2 [1] 1001>           /* ALID (1, 0) */
        <A "error message">     /* ALTX (2)    */
    >. 

    byte   alcd = msg.secs2().getByte(0, 0);
    int    alid = msg.secs2().getInt(1, 0);
    String altx = msg.secs2().getAscii(2);
  • support parse method matrix
method B BOOLEAN A I1 I2 I4 I8 F4 F8 U1 U2 U4 U8
getByte
getBoolean
getAscii
getInt
getLong
getBigInteger
getFloat
getDouble
  • Send Reply-Message
    Secs2 reply = Secs2.binary((byte)0x0);  /* <B 0x0> */

    active.send(
        primaryMsg  /* Primary-Message */
        , 5         /* Stream-Number   */
        , 2         /* Function-Number */
        , false     /* W-Bit           */
        , reply     /* Reply-SECS-II   */
    );

SML

  • GetInstance SML-Parser
    SmlMessageParser parser = SmlMessageParser.getInstance();
  • Send Primary-Message
    /* Send S1F1 W. example */
    SmlMessage primarySml = parser.parse(
        "S1F1 W."
    );

    active.send(primarySml);
  • Send Reply-Message
    /* Send S1F2. example */
    SmlMessage replySml = parser.parse(
        "S1F2           " +
        "<L             " +
        "   <A 'MDLN-A'>" +
        "   <A '000001'>" +
        ">.             "
    );

    passive.send(primarySecsMsg, replySml);

GEM

Access by SecsCommunicator#gem

    /* example */
    COMMACK commack = active.gem().s1f13();
    OFLACK  oflack  = active.gem().s1f15();
    ONLACK  onlack  = acitve.gem().s1f17();

    passive.gem().s1f14(primaryMsg, COMMACK.OK);
    passive.gem().s1f16(primaryMsg);
    passive.gem().s1f18(primaryMsg, ONLACK.OK);

    passive.gem().s5f2(primaryMsg);
    passive.gem().s6f4(primaryMsg);
    passive.gem().s9f1(referenceMsg);

secs4java8's People

Contributors

kenta-shimizu avatar

Watchers

 avatar  avatar

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.