Ejemplo n.º 1
0
        override public int GetNumberOfAdapters()
        {
            //char[] buff = new char[32];
            StringBuilder adapter = new StringBuilder(10);

            return(EASYSYNC.canusb_getFirstAdapter(adapter, 32));
        }
Ejemplo n.º 2
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();
            }
            // get first adapter
            //char[] adapter = new char[10];
            StringBuilder adapter = new StringBuilder(10);

            int result = EASYSYNC.canusb_getFirstAdapter(adapter, 10);

            if (result > 0)
            {
                Console.WriteLine("Number of adapters found: " + result.ToString("X8"));
                Console.WriteLine("Adapter serialnumber: " + adapter);
                m_deviceHandle = EASYSYNC.canusb_Open(null,
                                                            //"0x00:0xB9:0x07",
                                                            //"00:B9:07",
                                                      "00B907",
                                                            //"600",
                                                            //null,
                                                      null, //EASYSYNC.CANUSB_ACCEPTANCE_CODE_ALL,
                                                      null, //EASYSYNC.CANUSB_ACCEPTANCE_MASK_ALL,
                                                      EASYSYNC.CANUSB_FLAG_TIMESTAMP);
                Console.WriteLine("Handle: " + m_deviceHandle.ToString("X8"));
                if (m_deviceHandle > 0 && m_deviceHandle != 0xFFFFFFFD)
                {
                    EASYSYNC.canusb_Flush(m_deviceHandle);
                    Console.WriteLine("Creating new reader thread");

                    StringBuilder sb = new StringBuilder(100);
                    EASYSYNC.canusb_VersionInfo(m_deviceHandle, sb);
                    Console.WriteLine("Versionifo: " + sb.ToString());

                    Console.WriteLine("Status: " + EASYSYNC.canusb_Status(m_deviceHandle).ToString("X8"));

                    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);
                }
            }
            return(OpenResult.OpenError);
        }