Пример #1
0
        //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";
            }
        }
Пример #2
0
 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);
         }
     }
 }
Пример #3
0
        static int ErrorCount = 10; //used to display and error prompt
        private void TimerCheckForDevice_Tick(object sender, EventArgs e)
        {
            TimerCheckForDevice.Enabled = false;
            List <string> PeakUSBDevices = PCAN_USB.GetUSBDevices();

            if (PeakUSBDevices != null)
            {
                LstDevices.Items.AddRange(PeakUSBDevices.ToArray());
            }
            else
            {
                //display an error message every 10 counts
                //int remainder = ErrorCount % 10;
                if ((ErrorCount++ % 10) == 0)
                {
                    AddMessage(LstStatus, "Plug in a PEAK PCAN USB Adapter");
                }
                TimerCheckForDevice.Enabled = true;
            }
        }
Пример #4
0
        //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;
            }
        }