namespace FtdAdapter
{
///
/// Provides information about an attached FTDI USB device.
///
public struct FtdDeviceInfo
{
private readonly uint _flags;
private readonly uint _id;
private readonly string _serialNumber;
private readonly uint _type;
private readonly uint _locationId;
private readonly string _description;
internal FtdDeviceInfo(uint flags, uint type, uint id, uint locationId, string serialNumber, string description)
{
_flags = flags;
_type = type;
_id = id;
_locationId = locationId;
_serialNumber = serialNumber;
_description = description;
}
///
/// Complete device ID, comprising Vendor ID and Product ID.
///
public uint Id
{
get { return _id; }
}
///
/// Vendor ID.
///
public uint VendorId
{
get { return (_id >> 16) & 0xFFFF; }
}
///
/// Product ID
///
public uint ProductId
{
get { return _id & 0xFFFF; }
}
///
/// Serial number of device.
///
public string SerialNumber
{
get { return _serialNumber; }
}
///
/// Device flags.
///
public uint Flags
{
get { return _flags; }
}
///
/// Device type.
///
public uint Type
{
get { return _type; }
}
///
/// LocID
///
public uint LocationId
{
get { return _locationId; }
}
///
/// Description of device.
///
public string Description
{
get { return _description; }
}
///
/// Gets a value indicating if the device is already open.
///
public bool IsOpen
{
get { return (_flags & 0x01) != 0; }
}
///
/// Implements the operator ==.
///
/// The left.
/// The right.
/// The result of the operator.
public static bool operator ==(FtdDeviceInfo left, FtdDeviceInfo right)
{
return left.Equals(right);
}
///
/// Implements the operator !=.
///
/// The left.
/// The right.
/// The result of the operator.
public static bool operator !=(FtdDeviceInfo left, FtdDeviceInfo right)
{
return !left.Equals(right);
}
///
/// Indicates whether this instance and a specified object are equal.
///
/// Another object to compare to.
///
/// true if and this instance are the same type and represent the same value; otherwise, false.
///
public override bool Equals(object obj)
{
if (!(obj is FtdDeviceInfo))
return false;
FtdDeviceInfo other = (FtdDeviceInfo) obj;
return Id == other.Id &&
Flags == other.Flags &&
SerialNumber == other.SerialNumber &&
Type == other.Type &&
LocationId == other.LocationId &&
Description == other.Description;
}
///
/// Returns the hash code for this instance.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
public override int GetHashCode()
{
return Id.GetHashCode() ^
Flags.GetHashCode() ^
SerialNumber.GetHashCode() ^
Type.GetHashCode() ^
LocationId.GetHashCode() ^
Description.GetHashCode();
}
}
}