Beispiel #1
0
        /// <summary>
        /// The open method tries to connect to both busses to see if one of them is connected and
        /// active. The first strategy is to listen for any CAN message. If this fails there is a
        /// check to see if the application is started after an interrupted flash session. This is
        /// done by sending a message to set address and length (only for P-bus).
        /// </summary>
        /// <returns>OpenResult.OK is returned on success. Otherwise OpenResult.OpenError is
        /// returned.</returns>
        override public OpenResult open()
        {
            if (m_deviceHandle != 0)
            {
                close();
            }

            m_deviceHandle = LAWICEL.canusb_Open(IntPtr.Zero,
                                                 "0x40:0x37",
                                                 LAWICEL.CANUSB_ACCEPTANCE_CODE_ALL,
                                                 LAWICEL.CANUSB_ACCEPTANCE_MASK_ALL,
                                                 LAWICEL.CANUSB_FLAG_TIMESTAMP);

            if (m_deviceHandle > 0)
            {
                LAWICEL.canusb_Flush(m_deviceHandle, 0x01);
                Console.WriteLine("Creating new reader thread");
                m_readThread = new Thread(readMessages);
                try
                {
                    m_readThread.Priority = ThreadPriority.Normal; // realtime enough
                }
                catch (Exception E)
                {
                    Console.WriteLine(E.Message);
                }
                if (m_readThread.ThreadState == ThreadState.Unstarted)
                {
                    m_readThread.Start();
                }
                return(OpenResult.OK);
            }
            else
            {
                // second try after unload of dlls?

                //close();
                return(OpenResult.OpenError);
            }
        }
Beispiel #2
0
 override public void clearReceiveBuffer()
 {
     LAWICEL.canusb_Flush(m_deviceHandle, (byte)(FlushFlags.FLUSH_DONTWAIT | FlushFlags.FLUSH_EMPTY_INQUEUE));
 }
Beispiel #3
0
 override public void clearTransmitBuffer()
 {
     LAWICEL.canusb_Flush(m_deviceHandle, (byte)FlushFlags.FLUSH_DONTWAIT);
 }
Beispiel #4
0
 public override void Flush()
 {
     LAWICEL.canusb_Flush(m_deviceHandle, 0x01);
     LAWICEL.canusb_Flush(m_deviceHandle, 0x03);
 }