public static int GetDeviceCount() { int numDevs = 0; Internal.Constants.FT_STATUS status = Internal.Methods.FT_ListDevices(ref numDevs, IntPtr.Zero, Internal.Constants.FT_LISTDEVICES.ListNumberOnly); FT_StatusToException(status); return(numDevs); }
public int Flush() { IntPtr ptr = Marshal.AllocHGlobal((int)mvarBuffer.Length); Marshal.Copy(mvarBuffer, 0, ptr, (int)mvarBuffer.Length); uint bytesWritten = 0; Internal.Constants.FT_STATUS status = Internal.Methods.FT_Write(mvarHandle, ptr, (uint)mvarBuffer.Length, ref bytesWritten); FT_StatusToException(status); mvarBuffer = new byte[0]; return((int)bytesWritten); }
public int Write(byte[] buffer) { // bypass the double buffering as always want to write data Marshal.Copy(buffer, 0, ptr, (int)buffer.Length); uint bytesWritten = 0; Internal.Constants.FT_STATUS status = Internal.Methods.FT_Write(mvarHandle, ptr, (uint)buffer.Length, ref bytesWritten); FT_StatusToException(status); return((int)bytesWritten); //int start = mvarBuffer.Length; //Array.Resize<byte>(ref mvarBuffer, mvarBuffer.Length + buffer.Length); //Array.Copy(buffer, 0, mvarBuffer, start, buffer.Length); //if (mvarAutoFlush) return Flush(); //return 0; }
private static void FT_StatusToException(Internal.Constants.FT_STATUS status) { switch (status) { case Internal.Constants.FT_STATUS.DeviceNotFound: { throw new DeviceNotFoundException(); } case Internal.Constants.FT_STATUS.DeviceNotOpened: { throw new DeviceNotOpenedException(); } case Internal.Constants.FT_STATUS.DeviceNotOpenedForErase: { throw new DeviceNotOpenedException(DeviceOpenPurpose.Erase); } case Internal.Constants.FT_STATUS.DeviceNotOpenedForWrite: { throw new DeviceNotOpenedException(DeviceOpenPurpose.Write); } case Internal.Constants.FT_STATUS.EEPROMEraseFailed: { throw new EEPROMOperationFailedException(DeviceOperation.Erase); } case Internal.Constants.FT_STATUS.EEPROMNotPresent: { throw new EEPROMNotPresentException(); } case Internal.Constants.FT_STATUS.EEPROMNotProgrammed: { throw new EEPROMNotProgrammedException(); } case Internal.Constants.FT_STATUS.EEPROMReadFailed: { throw new EEPROMOperationFailedException(DeviceOperation.Read); } case Internal.Constants.FT_STATUS.EEPROMWriteFailed: { throw new EEPROMOperationFailedException(DeviceOperation.Write); } case Internal.Constants.FT_STATUS.FailedToWriteDevice: { throw new DeviceOperationFailedException(DeviceOperation.Erase); } case Internal.Constants.FT_STATUS.InsufficientResources: { throw new InsufficientMemoryException(); } case Internal.Constants.FT_STATUS.InvalidArguments: { throw new ArgumentException(); } case Internal.Constants.FT_STATUS.InvalidBaudRate: { throw new ArgumentException("The baud rate is invalid", "BaudRate"); } case Internal.Constants.FT_STATUS.InvalidHandle: { throw new ArgumentException("The handle is invalid", "Handle"); } case Internal.Constants.FT_STATUS.InvalidParameter: { throw new ArgumentException("The parameter is invalid"); } case Internal.Constants.FT_STATUS.IOError: { throw new System.IO.IOException(); } case Internal.Constants.FT_STATUS.UnknownError: { throw new Exception("Unknown error occurred"); } } }
public void Open() { Internal.Constants.FT_STATUS status = Internal.Methods.FT_Open(mvarPort, ref mvarHandle); }
public void Purge(PurgeBuffer buffers = PurgeBuffer.Both) { Internal.Constants.FT_STATUS status = Internal.Methods.FT_Purge(mvarHandle, buffers); FT_StatusToException(status); }
public void ClearRTS() { Internal.Constants.FT_STATUS status = Internal.Methods.FT_ClrRts(mvarHandle); FT_StatusToException(status); }
public void SetFlowControl(FlowControl control, byte uXon, byte uXoff) { Internal.Constants.FT_STATUS status = Internal.Methods.FT_SetFlowControl(mvarHandle, control, uXon, uXoff); FT_StatusToException(status); }
public void SetDataCharacteristics(BitsPerWord bits, StopBits stopBits, Parity parity) { Internal.Constants.FT_STATUS status = Internal.Methods.FT_SetDataCharacteristics(mvarHandle, bits, stopBits, parity); FT_StatusToException(status); }
public void SetBaudRate(int baudRate) { Internal.Constants.FT_STATUS status = Internal.Methods.FT_SetDivisor(mvarHandle, (char)baudRate); // set baud rate FT_StatusToException(status); }
public void Reset() { Internal.Constants.FT_STATUS status = Internal.Methods.FT_ResetDevice(mvarHandle); FT_StatusToException(status); }