Beispiel #1
0
        public bool openDevice()
        {
            bool opened = true;

            CastInfoEvent("Open called in Trionic7", ActivityType.ConvertingFile);
            MM_BeginPeriod(1);

            if (canUsbDevice is LPCCANDevice && m_UseFlasherOnDevice)
            {
                // connect to adapter
                LPCCANDevice lpc = (LPCCANDevice)canUsbDevice;

                if (lpc.connect())
                {
                    // get flasher object
                    flash = lpc.createFlasher();
                    logger.Debug("T7CombiFlasher object created");
                    CastInfoEvent("CombiAdapter ready", ActivityType.ConvertingFile);
                }
                else
                {
                    opened = false;
                }
            }
            else
            {
                if (kwpHandler.openDevice())
                {
                    CastInfoEvent("Canbus channel opened", ActivityType.ConvertingFile);

                    if (kwpHandler.startSession())
                    {
                        CastInfoEvent("Session started", ActivityType.ConvertingFile);
                    }
                    else
                    {
                        CastInfoEvent("Unable to start session. Wait for previous session to timeout (10 seconds) and try again!", ActivityType.ConvertingFile);
                        kwpHandler.closeDevice();
                        opened = false;
                    }
                }
                else
                {
                    CastInfoEvent("Unable to open canbus channel", ActivityType.ConvertingFile);
                    kwpHandler.closeDevice();
                    opened = false;
                }
            }

            if (!opened)
            {
                CastInfoEvent("Open failed in Trionic7", ActivityType.ConvertingFile);
                if (canUsbDevice != null)
                {
                    canUsbDevice.close();
                }
                MM_EndPeriod(1);
            }
            return(opened);
        }
Beispiel #2
0
        private bool CheckCANConnectivity()
        {
            // write log information to "CanTrace.txt"
            if (flash == null)
            {
                AddToCanTrace("Initializing CANbus interface");
                System.Windows.Forms.Application.DoEvents();
                AddToLog("Initializing CAN interface, please stand by...");
                AddToCanTrace("Creating new connection to CANUSB device!");

                if (useCombiAdapter)
                {
                    // connect to adapter
                    LPCCANDevice_T7 lpc = (LPCCANDevice_T7)this.canUsbDevice;
                    if (!lpc.connect())
                    {
                        return(false);
                    }
                    //<GS-09122010>
                    // kwpCanDevice.setCANDevice(canUsbDevice);
                    // KWPHandler.setKWPDevice(kwpCanDevice);
                    //<GS-09122010>
                    // get flasher object
                    Console.WriteLine("Created combiadpater flasher object");
                    this.flash         = lpc.createFlasher();
                    flash.EnableCanLog = checkBox1.Checked;

                    AddToCanTrace("T7CombiFlasher object created");
                    AddToLog("CombiAdapter ready");
                }
                else
                {
                    //flash = new T7.Flasher.T7Flasher();
                    //AddToCanTrace("Object T7.Flasher.T7Flasher created");
                    kwpCanDevice.setCANDevice(canUsbDevice);
                    kwpCanDevice.EnableCanLog = checkBox1.Checked;
                    KWPHandler.setKWPDevice(kwpCanDevice);
                    if (checkBox1.Checked)
                    {
                        KWPHandler.startLogging();
                    }
                    kwpHandler = KWPHandler.getInstance();
                    try
                    {
                        T7.Flasher.T7Flasher.setKWPHandler(kwpHandler);
                    }
                    catch (Exception E)
                    {
                        Console.WriteLine(E.Message);
                        AddToCanTrace("Failed to set flasher object to KWPHandler");
                    }
                    flash = T7.Flasher.T7Flasher.getInstance();
                    flash.onStatusChanged += new T7.Flasher.IFlasher.StatusChanged(flash_onStatusChanged);
                    //AddToLog("Set callback event on flasher");
                    flash.EnableCanLog = checkBox1.Checked;

                    if (kwpHandler.openDevice())
                    {
                        AddToLog("Canbus channel opened");
                    }
                    else
                    {
                        AddToLog("Unable to open canbus channel");
                        kwpHandler.closeDevice();
                        return(false);
                    }
                    if (kwpHandler.startSession())
                    {
                        AddToLog("Session started");
                    }
                    else
                    {
                        AddToLog("Unable to start session");
                        kwpHandler.closeDevice();
                        return(false);
                    }
                }
            }
            m_connectedToECU = true;
            return(m_connectedToECU);
        }