Beispiel #1
0
        //-------------------------------------------------------------------------

        /**
         *  Default constructor.
         */
        public CanDODevice()
        {
            // create adapter object
            CANdoUSB          = new TCANdoUSB();
            CANdoUSB.OpenFlag = CLOSED;

            // Create a store for CAN receive messages
            CANDataBuffer    = new TCANdoCAN[CAN_BUFFER_LENGTH]; // Cyclic buffer data
            CANBufferControl = new TCANdoCANBufferControl();     // Cyclic buffer control

            CANDataType = typeof(TCANdoCAN);
            CANDataSize = Marshal.SizeOf(CANDataType);

            CANBufferControlType = typeof(TCANdoCANBufferControl);
            CANBufferControlSize = Marshal.SizeOf(CANBufferControlType);

            CANBufferSize               = CANDataBuffer.Length * CANDataSize + CANBufferControlSize;
            CANBufferPointer            = Marshal.AllocHGlobal(CANBufferSize); // Allocate unmanaged memory for the CAN receive message cyclic buffer
            CANBufferControlPointer     = (IntPtr)(((int)CANBufferPointer) + CANDataBuffer.Length * CANDataSize);
            CANBufferControl.WriteIndex = 0;                                   // Reset cyclic buffer
            CANBufferControl.ReadIndex  = 0;
            CANBufferControl.FullFlag   = 0;
            Marshal.StructureToPtr(CANBufferControl, CANBufferControlPointer, true); // Update unmanaged memory

            // Create a store for status message
            CANdoStatus = new TCANdoStatus();

            // create reader thread
            this.read_thread = new Thread(this.read_messages);
            Debug.Assert(read_thread != null);
        }
Beispiel #2
0
        private bool term_requested = false; ///< thread termination flag

        #endregion Fields

        #region Constructors

        //-------------------------------------------------------------------------
        /**
        Default constructor.
        */
        public CanDODevice()
        {
            // create adapter object
            CANdoUSB = new TCANdoUSB();
            CANdoUSB.OpenFlag = CLOSED;

            // Create a store for CAN receive messages
            CANDataBuffer = new TCANdoCAN[CAN_BUFFER_LENGTH];  // Cyclic buffer data
            CANBufferControl = new TCANdoCANBufferControl();  // Cyclic buffer control

            CANDataType = typeof(TCANdoCAN);
            CANDataSize = Marshal.SizeOf(CANDataType);

            CANBufferControlType = typeof(TCANdoCANBufferControl);
            CANBufferControlSize = Marshal.SizeOf(CANBufferControlType);

            CANBufferSize = CANDataBuffer.Length * CANDataSize + CANBufferControlSize;
            CANBufferPointer = Marshal.AllocHGlobal(CANBufferSize);  // Allocate unmanaged memory for the CAN receive message cyclic buffer
            CANBufferControlPointer = (IntPtr)(((int)CANBufferPointer) + CANDataBuffer.Length * CANDataSize);
            CANBufferControl.WriteIndex = 0;  // Reset cyclic buffer
            CANBufferControl.ReadIndex = 0;
            CANBufferControl.FullFlag = 0;
            Marshal.StructureToPtr(CANBufferControl, CANBufferControlPointer, true);  // Update unmanaged memory

            // Create a store for status message
            CANdoStatus = new TCANdoStatus();

            // create reader thread
            this.read_thread = new Thread(this.read_messages);
            Debug.Assert(read_thread != null);
        }