/// <summary> /// Get the versions of the chipset and dll /// </summary> /// <returns>Both the chipset and dll versions</returns> public static (Version?Chip, Version?Dll) GetVersions() { // First, let's find a device var devices = GetDevices(); if (devices.Count == 0) { return(null, null); } // Check if the first not open device int idx = 0; for (idx = 0; idx < devices.Count; idx++) { if ((devices[idx].Flags & FtFlag.PortOpened) != FtFlag.PortOpened) { break; } } if (idx == devices.Count) { throw new InvalidOperationException($"Can't find any open device to check the versions"); } SafeFtHandle ftHandle = new SafeFtHandle(); var ftStatus = FtFunction.FT_OpenEx(devices[idx].LocId, FtOpenType.OpenByLocation, out ftHandle); if (ftStatus != FtStatus.Ok) { throw new IOException($"Can't open the device to check chipset version, status: {ftStatus}"); } FtVersion ftVersion; ftStatus = FtFunction.FT4222_GetVersion(ftHandle, out ftVersion); if (ftStatus != FtStatus.Ok) { throw new IOException($"Can't find versions of chipset and FT4222, status: {ftStatus}"); } ftStatus = FtFunction.FT_Close(ftHandle); if (ftStatus != FtStatus.Ok) { throw new IOException($"Can't close the device to check chipset version, status: {ftStatus}"); } Version chip = new Version((int)(ftVersion.ChipVersion >> 24), (int)((ftVersion.ChipVersion >> 16) & 0xFF), (int)((ftVersion.ChipVersion >> 8) & 0xFF), (int)(ftVersion.ChipVersion & 0xFF)); Version dll = new Version((int)(ftVersion.DllVersion >> 24), (int)((ftVersion.DllVersion >> 16) & 0xFF), (int)((ftVersion.DllVersion >> 8) & 0xFF), (int)(ftVersion.DllVersion & 0xFF)); return(chip, dll); }
/// <inheritdoc/> protected override void Dispose(bool disposing) { _ftHandle?.Dispose(); _ftHandle = null !; }
/// <inheritdoc/> public void Dispose() { _ftHandle?.Dispose(); _ftHandle = null !; }