Beispiel #1
0
        public void WriteFrame()
        {
            uint handle = 0;
            uint canId  = 0xFF;

            /*** Config ***/
            uint[] AttrIdList    = { NiCan.NC_ATTR_BAUD_RATE, NiCan.NC_ATTR_START_ON_OPEN };
            uint[] AttrValueList = { Baudrate, NiCan.NC_FALSE };
            uint   NumAttrs      = 2;
            int    status        = NiCan.ncConfig(new StringBuilder(Interface), NumAttrs, AttrIdList, AttrValueList);

            Assert.AreEqual(0, status, NiCanTools.StatusToString(status));

            /*** Open Object ***/
            status = NiCan.ncOpenObject(new StringBuilder(Interface), ref handle);
            Assert.AreEqual(0, status, NiCanTools.StatusToString(status));

            /*** Start ***/
            status = NiCan.ncAction(handle, NiCan.NC_OP_START, 0);
            Assert.AreEqual(0, status, NiCanTools.StatusToString(status));

            /*** Frame ***/
            var frame = new NiCan.NCTYPE_CAN_FRAME();

            frame.ArbitrationId = canId | NiCan.NC_FL_CAN_ARBID_XTD;
            frame.IsRemote      = NiCan.NC_FALSE;
            frame.DataLength    = 8;
            frame.Data0         = 0;
            frame.Data1         = 1;
            frame.Data2         = 2;
            frame.Data3         = 3;
            frame.Data4         = 4;
            frame.Data5         = 5;
            frame.Data6         = 6;
            frame.Data7         = 7;

            /*** Write ***/
            status = NiCan.ncWrite(handle, NiCan.CanFrameSize, ref frame);
            Assert.AreEqual(0, status, NiCanTools.StatusToString(status));

            /*** Stop ***/
            status = NiCan.ncAction(handle, NiCan.NC_OP_STOP, 0);
            Assert.AreEqual(0, status, NiCanTools.StatusToString(status));

            /*** Close ***/
            status = NiCan.ncCloseObject(handle);
            Assert.AreEqual(0, status, NiCanTools.StatusToString(status));
        }