Пример #1
0
 /// <summary>
 /// Search the serial ports for a device that conforms to the expected MindWave behaviour.
 /// </summary>
 /// <param name="format">    </param>
 /// <param name="filterType"></param>
 /// <returns></returns>
 public static MindWaveAdapter FindAdapter(SerialDataFormat format, FilterType filterType = DEFAULT_MAINS_FILTER)
 {
     return(FindAdapter(DEFAULT_BAUD_RATE, format, filterType));
 }
Пример #2
0
 public static int TG_Connect(int connectionId, string serialPortName, Baudrate baudrate,
     SerialDataFormat format)
 {
     return TG_Connect(connectionId, serialPortName, (int)baudrate, (int)format);
 }
Пример #3
0
        /// <summary>
        /// Search the serial ports for a device that conforms to the expected MindWave behaviour.
        /// </summary>
        /// <param name="baudrate">  </param>
        /// <param name="format">    </param>
        /// <param name="filterType"></param>
        /// <returns></returns>
        public static MindWaveAdapter FindAdapter(Baudrate baudrate = DEFAULT_BAUD_RATE, SerialDataFormat format = DEFAULT_SERIAL_FORMAT, FilterType filterType = DEFAULT_MAINS_FILTER)
        {
            foreach (var portName in System.IO.Ports.SerialPort.GetPortNames())
            {
                try
                {
                    return(new MindWaveAdapter(portName, baudrate, format, filterType));
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch
                {
                }
#pragma warning restore CA1031 // Do not catch general exception types
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// Connect to a device.
        /// </summary>
        /// <param name="serialPortName"></param>
        /// <param name="baudrate"></param>
        /// <param name="format"></param>
        /// <exception cref="InvalidOperationException">
        /// Thrown when a valid connection ID hasn't been allocated, or when <paramref name="baudrate"/> is invalid for the device, or when <paramref name="format"/> is invalid for the device.
        /// </exception>
        /// <exception cref="Exception">
        /// Thrown when <paramref name="serialPortName"/> can't be opened for communication.
        /// </exception>
        public void Connect(string serialPortName, Baudrate baudrate = DEFAULT_BAUD_RATE, SerialDataFormat format = DEFAULT_SERIAL_FORMAT)
        {
            if (connected)
            {
                Disconnect();
            }

            switch (TG_Connect(connectionId, serialPortName, (int)baudrate, (int)format))
            {
            case -1:
                throw new InvalidOperationException($"Invalid connection ID: {connectionId.ToString(CultureInfo.CurrentCulture)}");

            case -2:
                throw new Exception(serialPortName + " could not be opened as a serial communication port. Check that the name is a valid COM port on your system.");

            case -3:
                throw new InvalidOperationException($"{nameof(baudrate)} is not a valid TG_BAUD_* value.");

            case -4:
                throw new InvalidOperationException($"{nameof(format)} is not a valid TG_STREAM_* type.");
            }

            this.baudrate = baudrate;
            connected     = true;
        }
Пример #5
0
 /// <summary>
 /// Connect to a device.
 /// </summary>
 /// <param name="serialPortName"></param>
 /// <param name="format"></param>
 public void Connect(string serialPortName, SerialDataFormat format)
 {
     Connect(serialPortName, SerialBaudRate, format);
 }
Пример #6
0
 /// <summary>
 /// Setups up a new connection to the MindWave device.
 /// </summary>
 /// <param name="serialPortName"></param>
 /// <param name="format"></param>
 /// <param name="filterType"></param>
 /// <exception cref="IndexOutOfRangeException">
 /// Thrown when too many connections have been made to the device.
 /// </exception>
 /// <exception cref="OutOfMemoryException">
 /// Thrown when there isn't enough memory on the device to allocate a new connection.
 /// </exception>
 public MindWaveAdapter(string serialPortName, SerialDataFormat format, FilterType filterType = DEFAULT_MAINS_FILTER)
     : this(serialPortName, DEFAULT_BAUD_RATE, format, filterType)
 {
 }
Пример #7
0
 /// <summary>
 /// Setups up a new connection to the MindWave device.
 /// </summary>
 /// <param name="serialPortName"></param>
 /// <param name="baudrate"></param>
 /// <param name="format"></param>
 /// <param name="filterType"></param>
 /// <exception cref="IndexOutOfRangeException">
 /// Thrown when too many connections have been made to the device.
 /// </exception>
 /// <exception cref="OutOfMemoryException">
 /// Thrown when there isn't enough memory on the device to allocate a new connection.
 /// </exception>
 public MindWaveAdapter(string serialPortName, Baudrate baudrate = DEFAULT_BAUD_RATE, SerialDataFormat format = DEFAULT_SERIAL_FORMAT, FilterType filterType = DEFAULT_MAINS_FILTER)
     : this()
 {
     Connect(serialPortName, baudrate, format);
     MainsFrequency = filterType;
 }