//**************************** // Bus Settings Tab //**************************** private void RetrieveBus_Click(object sender, EventArgs e) { Canlib.canStatus status; long bitrate; int tseg1; int tseg2; int sjw; int noSamp; int syncmode; int canHandle = 0; status = Canlib.canGetBusParams(canHandle, out bitrate, out tseg1, out tseg2, out sjw, out noSamp, out syncmode); toolStripStatusLabel1.Text = CommonUtils.ErrorMsg("Retrieve Bus", status); if (status == 0) { bitrateBox.Text = bitrate.ToString(); tseg1Box.Text = tseg1.ToString(); tseg2Box.Text = tseg2.ToString(); sjwBox.Text = sjw.ToString(); noSampBox.Text = noSamp.ToString(); } }
//**************************** // Transmit Settings Tab // Written by Parnian Najafi Borazjani //**************************** private void TransmitPacket_Click(object sender, EventArgs e) { CanData can = new CanData(); int number_messages = 1; string msgOutput = ""; string flag; //if (Transmit_dlc.Value>8) // MessageBox.Show("Messages can have a maximum of 8"); // For the various flags // Need to implement an enumerated keyword to replace these numbers // These numbers are from the Kvaser library documentation and may not work on other CAN systems if (Flag_Ext.Checked == true) { flag = "X"; // Extended } else if (Flag_Err.Checked == true) { flag = "E"; // Error } else if (Flag_Rtr.Checked == true) { flag = "R"; // Remote } else { flag = "S"; // Standard } if (InputTests.IsStringNumeric(Transmit_NoMsg.Text) == true) { number_messages = Convert.ToInt32(Transmit_NoMsg.Text); } else { MessageBox.Show("Error: Number of Messages is not Numeric", "Error", MessageBoxButtons.OK); } msgOutput = Transmit_id.Text + ";" + Transmit_dlc.Text + ";" + flag + ";" + Transmit_msg0.Text + "-" + Transmit_msg1.Text + "-" + Transmit_msg2.Text + "-" + Transmit_msg3.Text + "-" + Transmit_msg4.Text + "-" + Transmit_msg5.Text + "-" + Transmit_msg6.Text + "-" + Transmit_msg7.Text; if (Transmit_Hex.Checked == true) { can.format = "hex"; } else { can.format = "decimal"; } CommonUtils.ConvertStringtoCAN(can, msgOutput); can.number = number_messages; can.timeBtw = 0; try { can.hardware = TransmitInterfaceBox.SelectedItem.ToString(); if (IncrementIdentifier.Checked == true) { can.increment = true; } GenericCanBus.GenericCanTransmitMultiple(can); //bgTransmit.RunWorkerAsync(can); toolStripStatusLabel2.Text = CommonUtils.ErrorMsg("Transmit Message", can.status); ErrorLog.NewLogEntry("CAN", "Transmit Message: " + can.status); if (VerboseTransmit.Checked == true) { MessageBox.Show(CommonUtils.DisplayMsg(can)); } } catch { MessageBox.Show("No interface is turned on, please turn on the interfaces from \"Advanced Bus Control\" Window"); this.Close(); BusControl form = (BusControl)CommonUtils.GetOpenedForm <BusControl>(); if (form == null) { form = new BusControl(); form.Show(); } else { form.Select(); } } }