Example #1
0
        public FT_STATUS Open(FT_DEVICE_INFO_NODE device)
        {
            lock (lockObj) {
                if (device.ftHandle != IntPtr.Zero)
                {
                    this.lastBaudRate = 0;
                    this.handle       = device.ftHandle;
                    return(FT_STATUS.FT_OK);
                }

                var status = FT_OpenEx(device.SerialNumber, 0x00000001, out this.handle);
                if (status == FT_STATUS.FT_OK)
                {
                    // Initialise port data characteristics
                    var wordLength = FT_DATA_BITS.FT_BITS_8;
                    var stopBits   = FT_STOP_BITS.FT_STOP_BITS_1;
                    var parity     = FT_PARITY.FT_PARITY_NONE;
                    status = FT_SetDataCharacteristics(handle, wordLength, stopBits, parity);

                    // Initialise to no flow control
                    var  flowControl = FT_FLOW_CONTROL.FT_FLOW_NONE;
                    byte Xon         = 0x11;
                    byte Xoff        = 0x13;
                    status = FT_SetFlowControl(handle, flowControl, Xon, Xoff);

                    // Initialise Baud rate
                    uint baudRate = 9600;
                    status = FT_SetBaudRate(handle, baudRate);
                }
                return(status);
            }
        }
Example #2
0
 public FT_STATUS GetDeviceList(out FT_DEVICE_INFO_NODE[] devicelist)
 {
     lock (lockObj) {
         var status = FT_CreateDeviceInfoList(out var deviceCount);
         devicelist = new FT_DEVICE_INFO_NODE[deviceCount];
         for (uint i = 0; i < (uint)deviceCount; i++)
         {
             byte[] serialNoBytes    = new byte[16];
             byte[] descriptionBytes = new byte[64];
             status = FT_GetDeviceInfoDetail(i, out var flags, out var device, out var id, out var locationId, serialNoBytes, descriptionBytes, out var handle);
             var serialNo = Encoding.ASCII.GetString(serialNoBytes);
             var nullIdx  = serialNo.IndexOf("\0");
             if (nullIdx > -1)
             {
                 serialNo = serialNo.Substring(0, nullIdx);
             }
             var description = Encoding.ASCII.GetString(descriptionBytes);
             nullIdx = description.IndexOf("\0");
             if (nullIdx > -1)
             {
                 description = description.Substring(0, nullIdx);
             }
             devicelist[i] = new FT_DEVICE_INFO_NODE()
             {
                 ID           = id,
                 Flags        = flags,
                 ftHandle     = handle,
                 SerialNumber = serialNo.Trim(),
                 LocId        = locationId,
                 Description  = description.Trim(),
                 Type         = device
             };
         }
         return(status);
     }
 }