/// <summary>
        /// Manager for sensors implemented with UDP protocol.
        /// </summary>
        /// <param name="ipAddress">The IP address of the sensor to connect to.</param>
        /// <param name="port">The UDP port to use for data transfer.</param>
        /// <param name="channelSize">The number of sensor channels available.</param>
        /// <param name="deviceName">The device name.</param>
        /// <param name="udpType">The type of UDP connection to use (Asynchronous or Synchronous).</param>
        public UDPSensorManager(string ipAddress, int port, int channelSize, string deviceName, UDPType udpType)
        {
            // Set sensor data
            if (channelSize <= 0)
            {
                throw new System.ArgumentException("The given channel size is invalid. It should be greater than zero.");
            }
            this.channelSize = channelSize;
            this.deviceName  = deviceName;

            // Set WiFi data
            this.udpType = udpType;
            ip           = IPAddress.Parse(ipAddress);
            this.port    = port;
            sensorValues = new List <float>(channelSize);

            // init sensor values
            for (int i = 0; i < channelSize; i++)
            {
                sensorValues.Add(0.0f);
            }

            // Connect
            EstablishConnection();

            // Create and start communication thread
            thread = new Thread(new ThreadStart(GetDataFromDevice));
            thread.Start();
        }
        /// <summary>
        /// Manager for sensors implemented with UDP protocol.
        /// </summary>
        /// <param name="ipAddress">The IP address of the sensor to connect to.</param>
        /// <param name="port">The UDP port to use for data transfer.</param>
        /// <param name="deviceName">The device name.</param>
        public UDPSensorManager(string ipAddress, int port, string deviceName)
        {
            channelSize     = 1;
            this.deviceName = deviceName;

            // Set WiFi data
            udpType      = UDPType.UDP_Async;
            ip           = IPAddress.Parse(ipAddress);
            this.port    = port;
            sensorValues = new List <float>(channelSize);
            sensorValues.Add(0.0f);

            // Connect
            EstablishConnection();

            // Create and start communication thread
            thread = new Thread(new ThreadStart(GetDataFromDevice));
            thread.Start();
        }
Exemplo n.º 3
0
        public UDPDeviceManager(string ipAddress, int port, string deviceName, UDPDeviceType deviceType, UDPType udpType = UDPType.UDP_Async)
        {
            this.deviceName = deviceName;
            this.deviceType = deviceType;

            // Set UDP data
            this.udpType = udpType;
            ip           = IPAddress.Parse(ipAddress);
            this.port    = port;

            // Connect
            EstablishConnection();

            // Start listening when listener type
            if (deviceType == UDPDeviceType.Listener || deviceType == UDPDeviceType.Dual)
            {
                // Create and start communication thread
                thread = new Thread(new ThreadStart(ListenForData));
                thread.Start();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Writes data through a UDP connection
 /// </summary>
 /// <param name="ipAddress">The remote IP address.</param>
 /// <param name="port">The remote port.</param>
 /// <param name="deviceName">The remote device name.</param>
 /// <param name="udpType">The type of UDP connection (sync/async).</param>
 public UDPWriter(string ipAddress, int port, string deviceName, UDPType udpType = UDPType.UDP_Async) : base(ipAddress, port, deviceName, UDPDeviceType.Writer, udpType)
 {
 }