private void J1939AddressClaim() { // J1939 "NAME" for this sample source code application (see J1939/81) // Self Configurable = 0 = NO // Industry Group = 0 = GLOBAL // Vehicle System = 0 = Non-Specific // Vehicle System Instance = 0 = First Diagnostic PC // Reserved = 0 = Must be zero // Function = 129 = Offboard Service Tool // Function Instance = 0 = First Offboard Service Tool // Manufacturer Code = 11 = Dearborn Group Technology // Manufacturer Identity = 0 = Dearborn Group Sample Source Code byte[] J1939Name = { 0, 0, 0x60, 1, 0, 0x81, 0, 0 }; byte[] TxBuffer = new byte[J1939Name.Length + 2]; //TxBuffer[0] = 129; // Source Address of the Service Tool\ TxBuffer[0] = 0; // Source Address of the Service Tool TxBuffer[1] = J1939Name[0]; TxBuffer[2] = J1939Name[1]; TxBuffer[3] = J1939Name[2]; TxBuffer[4] = J1939Name[3]; TxBuffer[5] = J1939Name[4]; TxBuffer[6] = J1939Name[5]; TxBuffer[7] = J1939Name[6]; TxBuffer[8] = J1939Name[7]; TxBuffer[9] = 0; //block until done J1939inst.RP1210_SendCommand(RP1210_Commands.RP1210_Protect_J1939_Address, new StringBuilder(Encoding.UTF7.GetString(TxBuffer)), (short)TxBuffer.Length); }
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; } } }
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; } } }
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; } } }