Ejemplo n.º 1
0
        /// <summary>
        /// Get a list of connected devices
        /// </summary>
        /// <returns>List of devices</returns>
        public static List <string> GetUSBDevices()
        {
            //Uses the PEAK System USB1 to USB16 handles for the PCAN-USB devices
            TPCANStatus   dllRet = TPCANStatus.PCAN_ERROR_UNKNOWN; //Assume unknown state to start
            UInt32        iBuffer;                                 //Passed to PCAN dll in GetValue call
            List <string> PCANDevices = null;                      //The list of devices to return

            bool isFD;                                             //CAN Flexible Data Rate (not currently supported by PCAN_USB)

            for (int i = 0; i < handlesArray.Length; i++)
            {
                // Checks for a Plug&Play Handle and, depending upon the return value, include it
                // into the list of available hardware channels.
                dllRet = PCANBasic.GetValue(handlesArray[i], TPCANParameter.PCAN_CHANNEL_CONDITION, out iBuffer, sizeof(UInt32));
                if ((dllRet == TPCANStatus.PCAN_ERROR_OK) && ((iBuffer & PCANBasic.PCAN_CHANNEL_AVAILABLE) == PCANBasic.PCAN_CHANNEL_AVAILABLE || (iBuffer & PCANBasic.PCAN_CHANNEL_PCANVIEW) == PCANBasic.PCAN_CHANNEL_PCANVIEW))
                {
                    dllRet = PCANBasic.GetValue(handlesArray[i], TPCANParameter.PCAN_CHANNEL_FEATURES, out iBuffer, sizeof(UInt32));
                    isFD   = (dllRet == TPCANStatus.PCAN_ERROR_OK) && ((iBuffer & PCANBasic.FEATURE_FD_CAPABLE) == PCANBasic.FEATURE_FD_CAPABLE);
                    if (PCANDevices == null)
                    {
                        PCANDevices = new List <string>();
                    }
                    PCANDevices.Add(FormatChannelName(handlesArray[i], isFD));
                }
            }
            return(PCANDevices);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get identify setting from PCAN USB device
        /// </summary>
        /// <param name="PCANUSBHandle">PCAN USB device handle</param>
        /// <returns>true if identifying is on for the device, else false</returns>
        public static bool IsIdentifyOn(PCANHandle PCANUSBHandle)
        {
            TPCANStatus dllRet = TPCANStatus.PCAN_ERROR_UNKNOWN; //Assume unknown state to start
            UInt32      iBuffer;                                 //Passed to PCAN dll in GetValue call

            dllRet = PCANBasic.GetValue(PCANUSBHandle, TPCANParameter.PCAN_CHANNEL_IDENTIFYING, out iBuffer, sizeof(UInt32));
            if (dllRet == TPCANStatus.PCAN_ERROR_OK && ((iBuffer & PCANBasic.PCAN_PARAMETER_ON) == PCANBasic.PCAN_PARAMETER_ON))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }