Exemple #1
0
        /// <summary>
        /// PEAK format text for a PCAN-Basic channel handle
        /// </summary>
        /// <param name="handle">PCAN-Basic Handle to format</param>
        /// <param name="isFD">If the channel is FD capable</param>
        /// <returns>The formatted text for a channel</returns>
        private static string FormatChannelName(PCANHandle handle, bool isFD)
        {
            TPCANDevice devDevice;
            byte        byChannel;

            // Gets the owner device and channel for a
            // PCAN-Basic handle
            if (handle < 0x100)
            {
                devDevice = (TPCANDevice)(handle >> 4);
                byChannel = (byte)(handle & 0xF);
            }
            else
            {
                devDevice = (TPCANDevice)(handle >> 8);
                byChannel = (byte)(handle & 0xFF);
            }
            // Constructs the PCAN-Basic Channel name and return it
            if (isFD)
            {
                return(string.Format("{0}:FD {1} ({2:X2}h)", devDevice, byChannel, handle));
            }
            else
            {
                return(string.Format("{0} {1} ({2:X2}h)", devDevice, byChannel, handle));
            }
        }
Exemple #2
0
 /// <summary>
 /// Initialise the given PEAK USB device
 /// </summary>
 /// <param name="CANHandle">PEAK USB handle</param>
 /// <param name="CANBaudRate">Baud rate as displayed</param>
 /// <returns>Device operation status</returns>
 public TPCANStatus InitializeCAN(PCANHandle CANHandle, string CANBaudRate, bool EnableRead)
 {
     LastOperationStatus = PCANBasic.Initialize(CANHandle, CANBaudRateToPeakCANBaudRate(CANBaudRate), (TPCANType)0, 0, 0);
     InitializeMessage();
     //Setup receive
     if (EnableRead)
     {
         SetCANMessageRead();
     }
     return(LastOperationStatus);
 }
Exemple #3
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);
            }
        }
Exemple #4
0
 /// <summary>
 /// Returns the PCAN USB handle for a given PEAK displayed handle
 /// </summary>
 /// <param name="PEAKListHandle">Displayed handle string</param>
 /// <returns>PCAN USB handle, 0 if no string provided or if string incorrect</returns>
 public static PCANHandle DecodePEAKHandle(string PEAKListHandle)
 {
     if (!(string.IsNullOrEmpty(PEAKListHandle) || PEAKListHandle.Trim() == string.Empty))
     {
         // Get the handle from the text being shown
         PEAKListHandle = PEAKListHandle.Substring(PEAKListHandle.IndexOf('(') + 1, 3);
         PEAKListHandle = PEAKListHandle.Replace('h', ' ').Trim(' ');
         PCANHandle handle = 0;
         if (!PCANHandle.TryParse(PEAKListHandle, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out handle))
         {
             handle = 0;
         }
         return(handle);
     }
     else
     {
         return(0);
     }
 }
Exemple #5
0
        /// <summary>
        /// Set the identify setting for a PCAN USB device
        /// </summary>
        /// <param name="PCANUSBHandle">PCAN USB device handle</param>
        /// <param name="OnOff">identify on or off</param>
        /// <returns>true if setting was made correctly, else false if it failed</returns>
        public static bool SetIdentify(PCANHandle PCANUSBHandle, bool OnOff)
        {
            TPCANStatus dllRet = TPCANStatus.PCAN_ERROR_UNKNOWN; //Assume unknown state to start
            UInt32      iBuffer;                                 //Passed to PCAN dll in GetValue call

            if (OnOff)
            {
                iBuffer = PCANBasic.PCAN_PARAMETER_ON;
            }
            else
            {
                iBuffer = PCANBasic.PCAN_PARAMETER_OFF;
            }

            dllRet = PCANBasic.SetValue(PCANUSBHandle, TPCANParameter.PCAN_CHANNEL_IDENTIFYING, ref iBuffer, sizeof(UInt32));
            if (dllRet == TPCANStatus.PCAN_ERROR_OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }