Beispiel #1
0
        public void write(byte[] data, int offset, ABContext abcontext)
        {
            session = abcontext.session;
            context = abcontext.context;
            abcontext.increment();
            LE.setuint16(data, offset, cmd); offset     += 2;
            LE.setuint16(data, offset, len); offset     += 2;
            LE.setuint32(data, offset, session); offset += 4;
            LE.setuint32(data, offset, status); offset  += 4;
            LE.setuint64(data, offset, context); offset += 8;
            LE.setuint32(data, offset, options); offset += 4;
            switch (cmd)
            {
            case CMD_RR_DATA:
                LE.setuint32(data, offset, ihandle); offset += 4;
                LE.setuint16(data, offset, timeout); offset += 2;
                LE.setuint16(data, offset, count); offset   += 2;
                LE.setuint16(data, offset, type_1); offset  += 2;
                LE.setuint16(data, offset, len_1); offset   += 2;
                LE.setuint16(data, offset, type_2); offset  += 2;
                LE.setuint16(data, offset, len_2); offset   += 2;
                break;

            case CMD_GET_SESSION:
                LE.setuint16(data, offset, protocol); offset += 2;
                LE.setuint16(data, offset, flags); offset    += 2;
                break;
            }
        }
Beispiel #2
0
        public static byte[] makeConnectPacket(ABContext context)
        {
            byte[] packet;
            ENIP   ip = new ENIP(ENIP.CMD_GET_SESSION);

            ip.setSizes(0);
            int size = ip.size();

            packet = new byte[size];
            int offset = 0;

            try {
                ip.write(packet, offset, context); offset += ip.size();
                return(packet);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Beispiel #3
0
        public static byte[] makeWritePacket(String tag, byte type, byte[] data, ABContext context)
        {
            byte[]      packet;
            ENIP        ip  = new ENIP(ENIP.CMD_RR_DATA);
            CIP_Request cip = new CIP_Request();

            cip.setWrite(tag, type, data);
            ip.setSizes(cip.size());
            int size = ip.size() + cip.size();

            packet = new byte[size];
            int offset = 0;

            try {
                ip.write(packet, offset, context); offset += ip.size();
                cip.write(packet, offset);
                return(packet);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }