Exemple #1
0
        public void J1939Connect()
        {
            bool failed = false;

            if (J1939Connected)
            {
                if (J1939inst != null)
                {
                    J1939inst = null;
                }

                //Need to have a status update event here
                //cmdConnect.Text = "Connect";
                J1939Connected = false;
            }
            else
            {
                J1939inst = new RP121032(_SelectedDriver);
                try
                {
                    J1939inst.RP1210_ClientConnect(deviceInfo.DeviceId, new StringBuilder("J1939"), 0, 0, 0);

                    DataPoller = new Thread(new ThreadStart(PollingDriver));
                    DataPoller.IsBackground = true;
                    DataPoller.Start();

                    // status event here
                    //txtStatus.Text = "SUCCESS - UserDevice= " + J1939inst.nClientID;
                    try
                    {
                        J1939inst.RP1210_SendCommand(RP1210_Commands.RP1210_Set_All_Filters_States_to_Pass, new StringBuilder(""), 0);

                        try
                        {
                            J1939AddressClaim();
                        }
                        catch (Exception err)
                        {
                            failed = true;
                            throw new Exception(err.Message);
                        }
                    }
                    catch (Exception err)
                    {
                        failed = true;
                        throw new Exception(err.Message);
                    }
                }
                catch (Exception err)
                {
                    failed = true;
                    // status event here
                    //txtStatus.Text = "FAILURE - " + err.Message;
                }
                if (!failed)
                {
                    J1939Connected = true;
                }
            }
        }
Exemple #2
0
        public void J1587Connect()
        {
            bool failed = false;

            if (J1939Connected)
            {
                if (J1587inst != null)
                {
                    J1587inst = null;
                }

                //Need to have a status update event here
                //cmdConnect.Text = "Connect";
                J1939Connected = false;
            }
            else
            {
                J1587inst = new RP121032(_SelectedDevice);
                try
                {
                    J1587inst.RP1210_ClientConnect(deviceInfo.DeviceId, new StringBuilder("J1708"), 0, 0, 0);
                    //txtStatus.Text = "SUCCESS - UserDevice= " + J1587inst.nClientID;
                }
                catch (Exception err)
                {
                    failed = true;
                    //txtStatus.Text = "FAILURE - " + err.Message;
                }

                try
                {
                    J1587inst.RP1210_SendCommand(RP1210_Commands.RP1210_Set_All_Filters_States_to_Pass, new StringBuilder(""), 0);
                }
                catch (Exception err)
                {
                    failed = true;
                    //txtStatus.Text = "FAILURE - " + err.Message;
                }
                if (!failed)
                {
                    //Need to throw status event
                    //cmdConnect.Text = "Disconnect";
                    J1587Connected = true;
                }
            }
        }
Exemple #3
0
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            bool failed = false;

            if (bConnected)
            {
                if (J1587inst != null)
                {
                    J1587inst = null;
                }
                if (J1939inst != null)
                {
                    J1939inst = null;
                }

                if (RxLogger != null)
                {
                    RxLogger.Close();
                }
                if (RxLogFileStream != null)
                {
                    RxLogFileStream.Close();
                }

                chkJ1587Enable.Enabled = true;
                chkJ1939Enable.Enabled = true;
                chkLogToFile.Enabled   = true;
                cmdConnect.Text        = "Connect";
                bConnected             = false;
                tmrJ1939.Enabled       = false;
            }
            else
            {
                if (chkLogToFile.Checked)
                {
                    SaveFileDialog newLogFile = new SaveFileDialog();

                    newLogFile.Filter           = "dgd files (*.dgd)|*.dgd|All files (*.*)|*.*";
                    newLogFile.FilterIndex      = 2;
                    newLogFile.RestoreDirectory = true;

                    if (newLogFile.ShowDialog() == DialogResult.OK)
                    {
                        if ((RxLogFileStream = newLogFile.OpenFile()) != null)
                        {
                            RxLogger = new StreamWriter(RxLogFileStream);
                        }
                    }
                }

                if (chkJ1939Enable.Checked)
                {
                    J1939inst = new RP121032(cmbDriverList.SelectedItem.ToString());
                    try
                    {
                        //J1939inst.RP1210_ClientConnect((short)150, new StringBuilder("J1939"), 0, 0, 0);
                        DeviceInfo selectedDevice = (DeviceInfo)cmbDeviceList.SelectedValue;
                        J1939inst.RP1210_ClientConnect(selectedDevice.DeviceId, new StringBuilder("J1939"), 0, 0, 0);
                        txtStatus.Text = "SUCCESS - UserDevice= " + J1939inst.nClientID;
                        try
                        {
                            J1939inst.RP1210_SendCommand(RP1210_Commands.RP1210_Set_All_Filters_States_to_Pass, new StringBuilder(""), 0);

                            try
                            {
                                J1939AddressClaim();
                            }
                            catch (Exception err)
                            {
                                failed = true;
                                throw new Exception(err.Message);
                            }
                        }
                        catch (Exception err)
                        {
                            failed = true;
                            throw new Exception(err.Message);
                        }
                    }
                    catch (Exception err)
                    {
                        failed         = true;
                        txtStatus.Text = "FAILURE - " + err.Message;
                    }
                }
                if (chkJ1587Enable.Checked)
                {
                    J1587inst = new RP121032(cmbDriverList.SelectedItem.ToString());
                    try
                    {
                        J1587inst.RP1210_ClientConnect((short)cmbDeviceList.SelectedItem, new StringBuilder("J1708"), 0, 0, 0);
                        txtStatus.Text = "SUCCESS - UserDevice= " + J1587inst.nClientID;
                    }
                    catch (Exception err)
                    {
                        failed         = true;
                        txtStatus.Text = "FAILURE - " + err.Message;
                    }

                    try
                    {
                        J1587inst.RP1210_SendCommand(RP1210_Commands.RP1210_Set_All_Filters_States_to_Pass, new StringBuilder(""), 0);
                    }
                    catch (Exception err)
                    {
                        failed         = true;
                        txtStatus.Text = "FAILURE - " + err.Message;
                    }
                }

                if (!failed)
                {
                    chkJ1587Enable.Enabled = false;
                    chkJ1939Enable.Enabled = false;
                    chkLogToFile.Enabled   = false;
                    cmdConnect.Text        = "Disconnect";
                    bConnected             = true;
                    tmrJ1939.Enabled       = true;
                }
            }
        }