Example #1
0
        public void SendOnChannel(Frame frame, byte channelIndex, bool blocking = false)
        {
            var nativeFrame = new NativeFunctions.candle_frame_t();

            nativeFrame.can_id = frame.Identifier;
            if (frame.Extended)
            {
                nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED;
            }
            if (frame.RTR)
            {
                nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_RTR;
            }
            if (frame.Error)
            {
                nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_ERR;
            }

            nativeFrame.data    = new byte[8];
            nativeFrame.can_dlc = (byte)frame.Data.Length;
            Buffer.BlockCopy(frame.Data, 0, nativeFrame.data, 0, frame.Data.Length);

            var lengthOnBus = frame.LengthOnBus;

            this.PerformInRightThread(() =>
            {
                if (!NativeFunctions.candle_frame_send(this.FDeviceHandle, channelIndex, ref nativeFrame))
                {
                    NativeFunctions.throwError(this.FDeviceHandle);
                }
                this.Channels[channelIndex].IncrementTx(lengthOnBus);
            }, blocking);
        }
        public void Send(Frame frame)
        {
            var nativeFrame = new NativeFunctions.candle_frame_t();

            nativeFrame.can_id = frame.Identifier;
            if (frame.Extended)
            {
                nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED;
            }
            if (frame.RTR)
            {
                nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_RTR;
            }
            if (frame.Error)
            {
                nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_ERR;
            }

            nativeFrame.data    = new byte[8];
            nativeFrame.can_dlc = (byte)frame.Data.Length;
            Buffer.BlockCopy(frame.Data, 0, nativeFrame.data, 0, frame.Data.Length);

            this.FDevice.Perform(() =>
            {
                if (!NativeFunctions.candle_frame_send(this.FDevice.Handle, this.FChannelIndex, ref nativeFrame))
                {
                    NativeFunctions.throwError(this.FDevice.Handle);
                }
            });
        }