internal static void Validate(this FtdiInterop.FtStatus status) { if (status != FtdiInterop.FtStatus.FT_OK) { throw new FtdiException(status); } }
public void Send(byte[] universeData) { CheckPortOpened(); // Prepare the buffer to send (MAB + universe) var bytesToSend = universeData.Length + 1; var toSend = new byte[bytesToSend]; Array.Copy(universeData, 0, toSend, 1, universeData.Length); // Purge any RX packet (useless) //FtdiInterop.Purge(_handle, 1).Validate(); // Send the BREAK signal FtdiInterop.SetBreakOn(_handle).Validate(); FtdiInterop.SetBreakOff(_handle).Validate(); // Send the MARK-AFTER-BREAK (first value with zeros) and the Universe itself if (mBufferToSend == IntPtr.Zero) { mBufferToSend = Marshal.AllocHGlobal(bytesToSend); } Marshal.Copy(toSend, 0, mBufferToSend, bytesToSend); int written; FtdiInterop.FtStatus res = FtdiInterop.Write(_handle, mBufferToSend, (uint)bytesToSend, out written); res.Validate(); //Marshal.Release(ptr); }
internal FtdiException(FtdiInterop.FtStatus status) : base(status.ToString()) { Status = status; }