示例#1
0
        /** Creates a packet to read data from S7. */
        public static byte[] makeReadPacket(S7Data[] s7)
        {
            TPKT     tpkt    = new TPKT();
            COTP     cotp    = new COTP(COTP.type_data);
            S7Header header  = new S7Header();
            S7Params _params = new S7Params();

            byte[] data;

            _params.makeRead(s7);
            int size = tpkt.size() + cotp.size() + header.size() + _params.size();

            data = new byte[size];
            int dataoff = 0;

            tpkt.write(data, dataoff, (short)size);
            dataoff += tpkt.size();
            cotp.write(data, dataoff);
            dataoff += cotp.size();
            header.write(data, dataoff, (short)_params.size(), (short)0);
            dataoff += header.size();
            _params.write(data, dataoff);
            return(data);
        }
示例#2
0
        /** Creates a packet to write data to S7. */
        public static byte[] makeWritePacket(S7Data type)
        {
            TPKT     tpkt    = new TPKT();
            COTP     cotp    = new COTP(COTP.type_data);
            S7Header header  = new S7Header();
            S7Params _params = new S7Params();

            byte[] data;

            _params.makeWrite(type.block_type, type.block_number, type.data_type, type.offset, type.length, type.data);
            int size = tpkt.size() + cotp.size() + header.size() + _params.size();

            data = new byte[size];
            int dataoff = 0;

            tpkt.write(data, dataoff, (short)size);
            dataoff += tpkt.size();
            cotp.write(data, dataoff);
            dataoff += cotp.size();
            header.write(data, dataoff, (short)(_params.size() - 4 - type.length), (short)(4 + type.length));
            dataoff += header.size();
            _params.write(data, dataoff);
            return(data);
        }