Example #1
0
        public void ControlResponse(Guid activity, uint sequence_no, ProfinetIO.BlockTypes block_type, ProfinetIO.ControlCommands control)
        {
            //Create RPC packet
            long         body_length_position;
            long         NDRDataHeader_position;
            MemoryStream mem = new MemoryStream();

            RPC.Encodings encoding             = RPC.Encodings.ASCII | RPC.Encodings.LittleEndian | RPC.Encodings.IEEE_float;
            Guid          destination_instance = RPC.GenerateObjectInstanceUUID(1, 0, m_device_id.DeviceId, m_device_id.VendorId);

            RPC.EncodeHeader(mem, RPC.PacketTypes.Response, RPC.Flags1.LastFragment | RPC.Flags1.NoFragmentAckRequested, 0, encoding, 0, destination_instance, RPC.UUID_IO_DeviceInterface, activity, 0, sequence_no, RPC.Operations.Control, 0, 0, out body_length_position);
            RPC.EncodeNDRDataHeader(mem, encoding, 0, 0, 0, 0, 0, out NDRDataHeader_position);

            //Create IO Packet
            ProfinetIO.ControlBlockConnect ctrl = new ProfinetIO.ControlBlockConnect();
            ctrl.BlockType      = block_type;
            ctrl.ARUUID         = m_aruuid;
            ctrl.SessionKey     = 1;
            ctrl.ControlCommand = control;
            ProfinetIO.EncodeControlResponse(mem, ctrl);

            //re-encode rpc lengths
            RPC.ReEncodeHeaderLength(mem, encoding, body_length_position);
            RPC.ReEncodeNDRDataHeaderLength(mem, encoding, NDRDataHeader_position, false);

            //send
            Trace.TraceInformation("Sending Control response");
            SendResponse(mem);
        }
Example #2
0
        public IAsyncResult BeginControlRequest(ProfinetIO.BlockTypes block_type, ProfinetIO.ControlCommands control)
        {
            //Create RPC packet
            long         body_length_position;
            long         NDRDataHeader_position;
            MemoryStream mem = new MemoryStream();

            RPC.Encodings encoding             = RPC.Encodings.ASCII | RPC.Encodings.LittleEndian | RPC.Encodings.IEEE_float;
            Guid          destination_instance = RPC.GenerateObjectInstanceUUID(1, 0, m_device_id.DeviceId, m_device_id.VendorId);

            RPC.EncodeHeader(mem, RPC.PacketTypes.Request, RPC.Flags1.Idempotent, 0, encoding, 0, destination_instance, RPC.UUID_IO_DeviceInterface, m_activity, 0, m_sequence_no++, RPC.Operations.Control, 0, 0, out body_length_position);
            RPC.EncodeNDRDataHeader(mem, encoding, 0, 0, 0, 0, 0, out NDRDataHeader_position);

            //Create IO Packet
            ProfinetIO.ControlBlockConnect ctrl = new ProfinetIO.ControlBlockConnect();
            ctrl.BlockType      = block_type;
            ctrl.ARUUID         = m_aruuid;
            ctrl.SessionKey     = 1;
            ctrl.ControlCommand = control;
            ProfinetIO.EncodeControlRequest(mem, ctrl);

            //re-encode rpc lengths
            RPC.ReEncodeHeaderLength(mem, encoding, body_length_position);
            RPC.ReEncodeNDRDataHeaderLength(mem, encoding, NDRDataHeader_position, true);

            //send
            Trace.TraceInformation("Sending Control message");
            return(new ProfinetAsyncRPCResult(this, mem));
        }
Example #3
0
        public IAsyncResult BeginReleaseRequest()
        {
            //Create RPC packet
            long         body_length_position;
            long         NDRDataHeader_position;
            MemoryStream mem = new MemoryStream();

            RPC.Encodings encoding             = RPC.Encodings.ASCII | RPC.Encodings.LittleEndian | RPC.Encodings.IEEE_float;
            Guid          destination_instance = RPC.GenerateObjectInstanceUUID(1, 0, m_device_id.DeviceId, m_device_id.VendorId);

            RPC.EncodeHeader(mem, RPC.PacketTypes.Request, RPC.Flags1.Idempotent, 0, encoding, 0, destination_instance, RPC.UUID_IO_DeviceInterface, m_activity, 0, m_sequence_no++, RPC.Operations.Release, 0, 0, out body_length_position);
            RPC.EncodeNDRDataHeader(mem, encoding, 0, 0, 0, 0, 0, out NDRDataHeader_position);

            //Create IO Packet
            ProfinetIO.EncodeReleaseRequest(mem, m_aruuid, 1);

            //re-encode rpc lengths
            RPC.ReEncodeHeaderLength(mem, encoding, body_length_position);
            RPC.ReEncodeNDRDataHeaderLength(mem, encoding, NDRDataHeader_position, true);

            //send
            Trace.TraceInformation("Sending Release message");
            return(new ProfinetAsyncRPCResult(this, mem));
        }
Example #4
0
        public IAsyncResult BeginConnectRequest()
        {
            //create new activity id
            m_activity = Guid.NewGuid();
            m_aruuid   = Guid.NewGuid();

            //Create RPC packet
            long         body_length_position;
            long         NDRDataHeader_position;
            MemoryStream mem = new MemoryStream();

            RPC.Encodings encoding             = RPC.Encodings.ASCII | RPC.Encodings.LittleEndian | RPC.Encodings.IEEE_float;
            Guid          destination_instance = RPC.GenerateObjectInstanceUUID(1, 0, m_device_id.DeviceId, m_device_id.VendorId);

            RPC.EncodeHeader(mem, RPC.PacketTypes.Request, RPC.Flags1.Idempotent, 0, encoding, 0, destination_instance, RPC.UUID_IO_DeviceInterface, m_activity, 0, m_sequence_no++, RPC.Operations.Connect, 0, 0, out body_length_position);
            RPC.EncodeNDRDataHeader(mem, encoding, 0, 0, 0, 0, 0, out NDRDataHeader_position);

            //Create IO Packet (I have no idea what most of this is)
            ProfinetIO.ARBlockRequest ar_block_req = new ProfinetIO.ARBlockRequest();
            ar_block_req.Type                             = ProfinetIO.ARTypes.IOCARSingle;
            ar_block_req.UUID                             = m_aruuid;
            ar_block_req.SessionKey                       = 1;
            ar_block_req.CMInitiatorMac                   = m_source_mac;
            ar_block_req.CMInitiatorObjectUUID            = m_object_instance;
            ar_block_req.Properties                       = ProfinetIO.ARProperties.State_Active | ProfinetIO.ARProperties.ParameterizationServer_CMInitiator;
            ar_block_req.CMInitiatorActivityTimeoutFactor = 600;
            ar_block_req.CMInitiatorUDPRTPort             = 0x8892;
            ar_block_req.CMInitiatorStationName           = "ProfinetExplorer";
            ProfinetIO.IOCRBlockRequest[] iocr_block_req = new ProfinetIO.IOCRBlockRequest[2] {
                new ProfinetIO.IOCRBlockRequest(), new ProfinetIO.IOCRBlockRequest()
            };

            iocr_block_req[0].Type                   = ProfinetIO.IOCRTypes.Input;
            iocr_block_req[0].Reference              = 1;
            iocr_block_req[0].Properties             = ProfinetIO.IOCRProperties.RT_CLASS1;
            iocr_block_req[0].DataLength             = 216;
            iocr_block_req[0].FrameID                = 0xc000;
            iocr_block_req[0].SendClockFactor        = 32; //clock cycle is 1 ms
            iocr_block_req[0].ReductionRatio         = m_input_cycle_time_ms;
            iocr_block_req[0].Phase                  = 1;
            iocr_block_req[0].Sequence               = 0;
            iocr_block_req[0].FrameSendOffset        = 0xFFFFFFFF;
            iocr_block_req[0].DataHoldFactorA        = 3;
            iocr_block_req[0].DataHoldFactorB        = 3;
            iocr_block_req[0].TagHeader              = ProfinetIO.IOCRTagHeaders.IOUserPriority_CR;
            iocr_block_req[0].MulticastMAC           = new System.Net.NetworkInformation.PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
            iocr_block_req[0].APIs                   = new ProfinetIO.IOC_API[1];
            iocr_block_req[0].APIs[0]                = new ProfinetIO.IOC_API();
            iocr_block_req[0].APIs[0].No             = 0;
            iocr_block_req[0].APIs[0].DataObjects    = new ProfinetIO.IOC_DataObject[5];
            iocr_block_req[0].APIs[0].DataObjects[0] = new ProfinetIO.IOC_DataObject(0, 0x8000, 0);
            iocr_block_req[0].APIs[0].DataObjects[1] = new ProfinetIO.IOC_DataObject(0, 0x8001, 1);
            iocr_block_req[0].APIs[0].DataObjects[2] = new ProfinetIO.IOC_DataObject(0, 0x8002, 2);
            iocr_block_req[0].APIs[0].DataObjects[3] = new ProfinetIO.IOC_DataObject(0, 1, 3);
            iocr_block_req[0].APIs[0].DataObjects[4] = new ProfinetIO.IOC_DataObject(1, 1, 5);
            iocr_block_req[0].APIs[0].IOCS           = new ProfinetIO.IOC_DataObject[1];
            iocr_block_req[0].APIs[0].IOCS[0]        = new ProfinetIO.IOC_DataObject(1, 1, 4);

            iocr_block_req[1].Type                   = ProfinetIO.IOCRTypes.Output;
            iocr_block_req[1].Reference              = 2;
            iocr_block_req[1].Properties             = ProfinetIO.IOCRProperties.RT_CLASS1;
            iocr_block_req[1].DataLength             = 40;
            iocr_block_req[1].FrameID                = 0xc001;
            iocr_block_req[1].SendClockFactor        = 32; //clock cycle is 1 ms
            iocr_block_req[1].ReductionRatio         = m_output_cycle_time_ms;
            iocr_block_req[1].Phase                  = 1;
            iocr_block_req[1].Sequence               = 0;
            iocr_block_req[1].FrameSendOffset        = 0xFFFFFFFF;
            iocr_block_req[1].DataHoldFactorA        = 3;
            iocr_block_req[1].DataHoldFactorB        = 3;
            iocr_block_req[1].TagHeader              = ProfinetIO.IOCRTagHeaders.IOUserPriority_CR;
            iocr_block_req[1].MulticastMAC           = new System.Net.NetworkInformation.PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
            iocr_block_req[1].APIs                   = new ProfinetIO.IOC_API[1];
            iocr_block_req[1].APIs[0]                = new ProfinetIO.IOC_API();
            iocr_block_req[1].APIs[0].No             = 0;
            iocr_block_req[1].APIs[0].DataObjects    = new ProfinetIO.IOC_DataObject[1];
            iocr_block_req[1].APIs[0].DataObjects[0] = new ProfinetIO.IOC_DataObject(1, 1, 5);
            iocr_block_req[1].APIs[0].IOCS           = new ProfinetIO.IOC_DataObject[5];
            iocr_block_req[1].APIs[0].IOCS[0]        = new ProfinetIO.IOC_DataObject(0, 0x8000, 0);
            iocr_block_req[1].APIs[0].IOCS[1]        = new ProfinetIO.IOC_DataObject(0, 0x8001, 1);
            iocr_block_req[1].APIs[0].IOCS[2]        = new ProfinetIO.IOC_DataObject(0, 0x8002, 2);
            iocr_block_req[1].APIs[0].IOCS[3]        = new ProfinetIO.IOC_DataObject(0, 0x1, 3);
            iocr_block_req[1].APIs[0].IOCS[4]        = new ProfinetIO.IOC_DataObject(1, 0x1, 4);

            ProfinetIO.AlarmCRBlockRequest alarm_cr_block_req = new ProfinetIO.AlarmCRBlockRequest();
            alarm_cr_block_req.Properties           = ProfinetIO.AlarmCRProperties.RTA_CLASS_1 | ProfinetIO.AlarmCRProperties.UserPriority;
            alarm_cr_block_req.RTATimeoutFactor     = 1;
            alarm_cr_block_req.RTARetries           = 3;
            alarm_cr_block_req.LocalAlarmReference  = 1;
            alarm_cr_block_req.MaxAlarmDataLength   = 256;
            alarm_cr_block_req.AlarmCRTagHeaderHigh = 0xC000;
            alarm_cr_block_req.AlarmCRTagHeaderLow  = 0xA000;

            ProfinetIO.ExpectedSubmoduleBlockRequest[] expected_submodule_block_req = new ProfinetIO.ExpectedSubmoduleBlockRequest[2] {
                new ProfinetIO.ExpectedSubmoduleBlockRequest(), new ProfinetIO.ExpectedSubmoduleBlockRequest()
            };
            expected_submodule_block_req[0].APIs                                       = new ProfinetIO.Submodule_API[1];
            expected_submodule_block_req[0].APIs[0]                                    = new ProfinetIO.Submodule_API();
            expected_submodule_block_req[0].APIs[0].No                                 = 0;
            expected_submodule_block_req[0].APIs[0].SlotNumber                         = 0;
            expected_submodule_block_req[0].APIs[0].ModuleIdentNumber                  = 1;
            expected_submodule_block_req[0].APIs[0].SubModules                         = new ProfinetIO.Submodule[4];
            expected_submodule_block_req[0].APIs[0].SubModules[0]                      = new ProfinetIO.Submodule();
            expected_submodule_block_req[0].APIs[0].SubModules[0].SubslotNumber        = 0x8000;
            expected_submodule_block_req[0].APIs[0].SubModules[0].SubmoduleIdentNumber = 0xA;
            expected_submodule_block_req[0].APIs[0].SubModules[0].SubmoduleProperties  = ProfinetIO.SubmoduleProperties.Type_NO_IO | ProfinetIO.SubmoduleProperties.SharedInput_IOControllerOnly | ProfinetIO.SubmoduleProperties.ReduceInputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.ReduceOutputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.DiscardIOXS_Expected;
            expected_submodule_block_req[0].APIs[0].SubModules[0].DataDescription      = new ProfinetIO.DataDescription[1];
            expected_submodule_block_req[0].APIs[0].SubModules[0].DataDescription[0]   = new ProfinetIO.DataDescription(ProfinetIO.DataDescription.Types.Input, 0, 1, 1);
            expected_submodule_block_req[0].APIs[0].SubModules[1]                      = new ProfinetIO.Submodule();
            expected_submodule_block_req[0].APIs[0].SubModules[1].SubslotNumber        = 0x8001;
            expected_submodule_block_req[0].APIs[0].SubModules[1].SubmoduleIdentNumber = 0xB;
            expected_submodule_block_req[0].APIs[0].SubModules[1].SubmoduleProperties  = ProfinetIO.SubmoduleProperties.Type_NO_IO | ProfinetIO.SubmoduleProperties.SharedInput_IOControllerOnly | ProfinetIO.SubmoduleProperties.ReduceInputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.ReduceOutputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.DiscardIOXS_Expected;
            expected_submodule_block_req[0].APIs[0].SubModules[1].DataDescription      = new ProfinetIO.DataDescription[1];
            expected_submodule_block_req[0].APIs[0].SubModules[1].DataDescription[0]   = new ProfinetIO.DataDescription(ProfinetIO.DataDescription.Types.Input, 0, 1, 1);
            expected_submodule_block_req[0].APIs[0].SubModules[2]                      = new ProfinetIO.Submodule();
            expected_submodule_block_req[0].APIs[0].SubModules[2].SubslotNumber        = 0x8002;
            expected_submodule_block_req[0].APIs[0].SubModules[2].SubmoduleIdentNumber = 0xC;
            expected_submodule_block_req[0].APIs[0].SubModules[2].SubmoduleProperties  = ProfinetIO.SubmoduleProperties.Type_NO_IO | ProfinetIO.SubmoduleProperties.SharedInput_IOControllerOnly | ProfinetIO.SubmoduleProperties.ReduceInputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.ReduceOutputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.DiscardIOXS_Expected;
            expected_submodule_block_req[0].APIs[0].SubModules[2].DataDescription      = new ProfinetIO.DataDescription[1];
            expected_submodule_block_req[0].APIs[0].SubModules[2].DataDescription[0]   = new ProfinetIO.DataDescription(ProfinetIO.DataDescription.Types.Input, 0, 1, 1);
            expected_submodule_block_req[0].APIs[0].SubModules[3]                      = new ProfinetIO.Submodule();
            expected_submodule_block_req[0].APIs[0].SubModules[3].SubslotNumber        = 1;
            expected_submodule_block_req[0].APIs[0].SubModules[3].SubmoduleIdentNumber = 1;
            expected_submodule_block_req[0].APIs[0].SubModules[3].SubmoduleProperties  = ProfinetIO.SubmoduleProperties.Type_NO_IO | ProfinetIO.SubmoduleProperties.SharedInput_IOControllerOnly | ProfinetIO.SubmoduleProperties.ReduceInputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.ReduceOutputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.DiscardIOXS_Expected;
            expected_submodule_block_req[0].APIs[0].SubModules[3].DataDescription      = new ProfinetIO.DataDescription[1];
            expected_submodule_block_req[0].APIs[0].SubModules[3].DataDescription[0]   = new ProfinetIO.DataDescription(ProfinetIO.DataDescription.Types.Input, 0, 1, 1);

            expected_submodule_block_req[1].APIs                                       = new ProfinetIO.Submodule_API[1];
            expected_submodule_block_req[1].APIs[0]                                    = new ProfinetIO.Submodule_API();
            expected_submodule_block_req[1].APIs[0].No                                 = 0;
            expected_submodule_block_req[1].APIs[0].SlotNumber                         = 1;
            expected_submodule_block_req[1].APIs[0].ModuleIdentNumber                  = 2;
            expected_submodule_block_req[1].APIs[0].SubModules                         = new ProfinetIO.Submodule[1];
            expected_submodule_block_req[1].APIs[0].SubModules[0]                      = new ProfinetIO.Submodule();
            expected_submodule_block_req[1].APIs[0].SubModules[0].SubslotNumber        = 1;
            expected_submodule_block_req[1].APIs[0].SubModules[0].SubmoduleIdentNumber = 2;
            expected_submodule_block_req[1].APIs[0].SubModules[0].SubmoduleProperties  = ProfinetIO.SubmoduleProperties.Type_INPUT_OUTPUT | ProfinetIO.SubmoduleProperties.SharedInput_IOControllerOnly | ProfinetIO.SubmoduleProperties.ReduceInputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.ReduceOutputSubmoduleDataLength_Expected | ProfinetIO.SubmoduleProperties.DiscardIOXS_Expected;
            expected_submodule_block_req[1].APIs[0].SubModules[0].DataDescription      = new ProfinetIO.DataDescription[2];
            expected_submodule_block_req[1].APIs[0].SubModules[0].DataDescription[0]   = new ProfinetIO.DataDescription(ProfinetIO.DataDescription.Types.Input, 210, 1, 1);
            expected_submodule_block_req[1].APIs[0].SubModules[0].DataDescription[1]   = new ProfinetIO.DataDescription(ProfinetIO.DataDescription.Types.Output, 4, 1, 1);
            ProfinetIO.EncodeConnectRequest(mem, ar_block_req, iocr_block_req, alarm_cr_block_req, expected_submodule_block_req, null, null, null, null, null, null, null);

            //re-encode rpc lengths
            RPC.ReEncodeHeaderLength(mem, encoding, body_length_position);
            RPC.ReEncodeNDRDataHeaderLength(mem, encoding, NDRDataHeader_position, true);

            //send
            Trace.TraceInformation("Sending Connect message");
            HasConnected = true;
            return(new ProfinetAsyncRPCResult(this, mem));
        }