//Start or Stop the selected device private void ButStartStop_Click(object sender, EventArgs e) { UInt16 handle = 0; //PCAN handles are ushorts if (ButStartStop.Text == "Start") { if (LstDevices.SelectedIndex > -1) { handle = PCAN_USB.DecodePEAKHandle(LstDevices.Items[LstDevices.SelectedIndex].ToString()); } if (handle > 0) { pCAN.PeakCANHandle = handle; pCAN.InitializeCAN(pCAN.PeakCANHandle, LstBaudRate.Items[LstBaudRate.SelectedIndex].ToString(), true); GrpMessage.Enabled = true; GrpReading.Enabled = true; ChkTrace.Enabled = true; ButStartStop.Text = "Stop"; } else { AddMessage(LstStatus, "No device selected"); } } else { pCAN.Uninitialize(); GrpMessage.Enabled = false; ButClear.Enabled = true; ChkTrace.Enabled = false; ButStartStop.Text = "Start"; } }
private void ChkIdentifyPCANUSB_CheckStateChanged(object sender, EventArgs e) { if (LstDevices.SelectedIndex >= 0) { UInt16 handle = 0; //used to check identifying state of PCAN USB device handle = PCAN_USB.DecodePEAKHandle(LstDevices.Items[LstDevices.SelectedIndex].ToString()); //set identify if (handle > 0) { PCAN_USB.SetIdentify(handle, ChkIdentifyPCANUSB.Checked); } } }
//Selecting PEAK USB device private void LstDevices_SelectedIndexChanged(object sender, EventArgs e) { //Close any open channels pCAN.Uninitialize(); //If a peak device is selected allow baud rate selection and start button UInt16 handle = 0; if (LstDevices.SelectedIndex > -1) { handle = PCAN_USB.DecodePEAKHandle(LstDevices.Items[LstDevices.SelectedIndex].ToString()); } if (handle > 0) { GrpInitialize.Enabled = true; } else { GrpInitialize.Enabled = false; } }