Things used in this project

Code

CONTROLLER.csC#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Devices.Gpio;
using Windows.Devices.I2c;
using Windows.Devices.SerialCommunication;
using Windows.Devices.Spi;
using Windows.Networking;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;

namespace IoTController
{
    class CONTROLLER
    {
        private List<I2cDevice> i2cDeviceList;

        public CONTROLLER(string remoteHostname, string localPortName, string remotePortName)
        {
            var now = DateTime.Now;
            Debug.WriteLine(now + " : " + " Controller Unit CONSTRUCTOR");
            i2cDeviceList = new List<I2cDevice>();
            
            RemoteHostname = remoteHostname;
            LocalPortName = localPortName;
            RemotePortName = remotePortName;
            InitGPIOController();
            InitNetworkUPD();
        }

        public string RemoteHostname
        {
            get; set;
        }

        public string LocalPortName
        {
            get; set;
        }

        public string RemotePortName
        {
            get; set;
        }

        private HostName remoteHostname;
        private DatagramSocket socket = new DatagramSocket();
        private DatagramSocket listenerSocket = new DatagramSocket();

        private DataWriter writer;
        private IOutputStream outputStream;

        public async void InitNetworkUPD()
        {
            remoteHostname = new HostName(RemoteHostname);
            listenerSocket.MessageReceived += UDPMessageReceived;
            //listenerSocket.Control.MulticastOnly = true;
            // Start listen operation.

            try
            {
                await listenerSocket.BindServiceNameAsync(LocalPortName); //ServiceName.Text
                //listenerSocket.JoinMulticastGroup(remoteHostname);  //RemoteAddress.Text
            }
            catch (Exception exception)
            {
                listenerSocket.Dispose();
                listenerSocket = null;

                // If this is an unknown status it means that the error is fatal and retry will likely fail.
                if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                {
                    throw;
                }

                Debug.WriteLine("Start listening failed with error: " + exception.Message);
            }

            try
            {
                // UPD SENDING SETUP ======================================================
                outputStream = await socket.GetOutputStreamAsync(remoteHostname, RemotePortName);
                // Send out some multicast or broadcast data. Datagrams generated by the IOutputStream will use
                // <source host, source port> information obtained from the parent socket (i.e., 'listenSocket' in
                // this case).
                writer = new DataWriter(outputStream);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("outputStream error: " + exception.Message);
            }
        }

        private void UDPMessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs eventArguments)
        {
            try
            {
                // Interpret the incoming datagram's entire contents as a string.
                uint stringLength = eventArguments.GetDataReader().UnconsumedBufferLength;
                string receivedMessage = eventArguments.GetDataReader().ReadString(stringLength);


                Debug.WriteLine(
                    "Received data from remote peer (Remote Address: " +
                    eventArguments.RemoteAddress.CanonicalName +
                    ", Remote Port: " +
                    eventArguments.RemotePort + "): \"" +
                     receivedMessage + "\"");
            }
            catch (Exception exception)
            {
                SocketErrorStatus socketError = SocketError.GetStatus(exception.HResult);

                if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                {
                    Debug.WriteLine($"Unknown UDPMessageReceived Error: {exception}");
                }

                Debug.WriteLine("Error happened when receiving a datagram:" + exception.Message);
            }
        }

        public async void Send_UDP(byte[] ReadBuf) //MPUDATA mpudata
        {
            try
            {
                // GetOutputStreamAsync can be called multiple times on a single DatagramSocket instance to obtain
                // IOutputStreams pointing to various different remote endpoints. The remote hostname given to
                // GetOutputStreamAsync can be a unicast, multicast or broadcast address.


                //Array.Copy(ReadBuf, 0, updData, 1, ReadBuf.Length-1);
                writer.WriteBytes(ReadBuf);

                //writer.WriteString(sOut);
                await writer.StoreAsync();
            }
            catch (Exception exception)
            {
                // If this is an unknown status it means that the error is fatal and retry will likely fail.
                if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                {
                    Debug.WriteLine($"Unknown Sending UPD Error: {exception}");
                }
            }
        }


        public async Task<I2cDevice> InitI2cCommunication(DEVICE device)
        {
            string aqs = I2cDevice.GetDeviceSelector();                     /* Get a selector string that will return all I2C controllers on the system */
            var dis = await DeviceInformation.FindAllAsync(aqs);            /* Find the I2C bus controller device with our selector string           */

            /* Checking number of I2C ports available
            for (int i=0;i<dis.Count;i++)
            {
                Debug.WriteLine(dis[i].Id.ToString());
            }
            */

            if (dis.Count == 0)
            {
                Debug.WriteLine("No I2C controllers were found on the system");
                return null;
            }

            int I2CPort = (int)device.I2CPort;

            var settings = new I2cConnectionSettings(device.I2C_ADDRESS);
            settings.BusSpeed = I2cBusSpeed.FastMode;
            
            device.I2cCommunication = await I2cDevice.FromIdAsync(dis[I2CPort].Id, settings);    /* Create an I2cDevice with our selected bus controller and I2C settings */

            if (device.I2cCommunication != null)
            {
                i2cDeviceList.Add(device.I2cCommunication); //Debug.WriteLine("i2C List Count: " + i2cDeviceList.Count.ToString());
            }

            else
            {
                Debug.WriteLine($"Slave address {settings.SlaveAddress} on I2C Controller {dis[I2CPort].Id} is currently in use by another application.");
                return null;
            }

            return device.I2cCommunication;
        }

        public async Task<SpiDevice> InitSPICommunication(DEVICE device)
        {
            const string SPI_CONTROLLER_NAME = "SPI0";  /* For DragonBoard, use SPI0                                */
            const Int32 SPI_CHIP_SELECT_LINE = 0;       /* Line 0 maps to physical pin number 12 on the DragonBoard */
            try
            {
                var settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
                settings.ClockFrequency = 4800000;                              /* 5MHz is the rated speed of the ADXL345 accelerometer                     */
                settings.Mode = SpiMode.Mode3;                                  /* The accelerometer expects an idle-high clock polarity, we use Mode3    
                                                                                 * to set the clock polarity and phase to: CPOL = 1, CPHA = 1         
                                                                                 */

                string aqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);                     /* Get a selector string that will return all SPI controllers on the system */
                var dis = await DeviceInformation.FindAllAsync(aqs);            /* Find the SPI bus controller devices with our selector string             */
                device.SPICommunication = await SpiDevice.FromIdAsync(dis[0].Id, settings);    /* Create an SpiDevice with our bus controller and SPI settings             */
                if (device.SPICommunication == null)
                {
                    Debug.WriteLine($"SPI Controller {dis[0].Id} is currently in use by another application.");
                    return null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("SPI Initialization failed. Exception: " + ex.Message);
                return null;
            }

            return device.SPICommunication;
        }

        public async Task<SerialDevice> InitUARTCommunication(DEVICE device)
        {
            string aqs = SerialDevice.GetDeviceSelector();
            var dis = await DeviceInformation.FindAllAsync(aqs);

            int UARTPort = -1;
            for (int i = 0; i < dis.Count; i++)
            {
                //string stest = dis[i].Id.ToString();
                if (dis[i].Id.ToString().Contains(device.UARTPort))
                {
                    UARTPort = i;
                    break;
                }
            }
            //Debug.WriteLine(dis[UARTPort].Id.ToString());

            if (UARTPort != -1)
            {
                try
                {
                    device.UARTCommunication = await SerialDevice.FromIdAsync(dis[UARTPort].Id);
                    device.UARTCommunication.WriteTimeout = TimeSpan.FromMilliseconds(device.UARTWriteTimeout);
                    device.UARTCommunication.ReadTimeout = TimeSpan.FromMilliseconds(device.UARTReadTimeout);
                    device.UARTCommunication.BaudRate = device.UARTBaudRate;
                    device.UARTCommunication.Parity = SerialParity.None;
                    device.UARTCommunication.StopBits = SerialStopBitCount.One;
                    device.UARTCommunication.DataBits = 8;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }

            return device.UARTCommunication;
        }

        public GpioController IoController
        {
            get; set;
        }

        public void InitGPIOController()
        {
            IoController = GpioController.GetDefault(); /* Get the default GPIO controller on the system */

            if (IoController == null)
            {
                throw new Exception("GPIO does not exist on the current system.");
            }
        }

        public void InitGPIOInterruptPin(DEVICE device)
        {
            try
            {
                device.IoInterruptPin = IoController.OpenPin(device.IoInterruptPinID);
                //Check if input pull-up resistors are supported
                if (device.IoInterruptPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                    device.IoInterruptPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                else
                    device.IoInterruptPin.SetDriveMode(GpioPinDriveMode.Input);

                // Set a debounce timeout to filter out switch bounce noise from a button press
                device.IoInterruptPin.DebounceTimeout = TimeSpan.FromMilliseconds(0);
                //Debug.WriteLine("GPIO pins " + sensor.IoInterruptPinID.ToString() + " initialized correctly.");
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Fail to Open INTERRUPT Pin: {ex}");
            }            
        }

        public void InitGPIOControlPin(DEVICE device)
        {
            try
            {
                device.IoControlPin = IoController.OpenPin(device.IoControlPinID);
                if (device.IoControlPin == null)
                {
                    return;
                }
                device.IoControlPin.SetDriveMode(GpioPinDriveMode.Output);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Fail to Open CONTROL Pin: {ex}");
            }
        }
    }
}
Device.csC#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Gpio;
using Windows.Devices.I2c;
using Windows.Devices.SerialCommunication;
using Windows.Devices.Spi;
using Windows.Storage.Streams;

namespace IoTController
{
    public enum I2CPortID { I2C0, I2C1 };

    abstract class DEVICE
    {
        public DEVICE()
        {
            this.DeviceName = "Device Name";
            this.DeviceID = 0;
            this.DeviceDescription = " Device Description";
            this.DeviceAvailable = false;
        }

        #region Device Info

        public int DeviceID
        {
            get; set;
        }

        public string DeviceDescription
        {
            get; set;
        }

        public string DeviceName
        {
            get; set;
        }

        public bool DeviceAvailable
        {
            get; set;
        }
        #endregion

        #region SPI-Communication
        public SpiDevice SPICommunication
        {
            get; set;
        }

        public void SPIWriteByte(byte regAddr, byte data)
        {
            byte[] buffer = new byte[2];
            buffer[0] = regAddr;
            buffer[1] = data;
            SPICommunication.Write(buffer);
        }
        #endregion

        #region I2C Communication

        public I2CPortID I2CPort
        {
            get; set;
        }

        public byte I2C_ADDRESS
        {
            get; set;
        }

        public I2cDevice I2cCommunication
        {
            get; set;
        }

        byte[] i2CWriteByte_writeBuffer = new byte[2];
        public void I2CWriteByte(byte regAddr, byte data)
        {
            i2CWriteByte_writeBuffer[0] = regAddr;
            i2CWriteByte_writeBuffer[1] = data;
            I2cCommunication.Write(i2CWriteByte_writeBuffer);
        }

        byte[] i2cReadByte_writeBuffer = new byte[1];
        byte[] i2cReadByte_readBuffer = new byte[1];
        public byte I2CReadByte(byte regAddr)
        {
            i2cReadByte_writeBuffer[0] = regAddr;
            I2cCommunication.WriteRead(i2cReadByte_writeBuffer, i2cReadByte_readBuffer);
            return i2cReadByte_readBuffer[0];
        }

        #endregion

        #region Serial Communication- UART

        public SerialDevice UARTCommunication
        {
            get; set;
        }

        public string UARTPort
        {
            get; set;
        }

        public uint UARTBaudRate
        {
            get; set;
        }

        public int UARTWriteTimeout
        {
            get; set;
        }

        public int UARTReadTimeout
        {
            get; set;
        }

        public DataWriter UARTDataWriteObject
        {
            get; set;
        }
        public DataReader UARTDataReaderObject
        {
            get; set;
        }
        #endregion

        #region GPIO

        public int IoInterruptPinID
        {
            get; set;
        }

        public int IoControlPinID
        {
            get; set;
        }

        public GpioPin IoInterruptPin
        {
            get; set;
        }

        public GpioPin IoControlPin
        {
            get; set;
        }
        #endregion
    }
}
MPU_925x_I2C.csC#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IoTController
{
    class MPU_925x_I2C: MPU_925x
    {

        public MPU_925x_I2C()
        {
            var now = DateTime.Now;
            Debug.WriteLine(now + " MPU_I2C Constructor : ");
        }

        public async void InitializeMPU()
        {
            try
            {
                await Task.Delay(3); // wait 3ms power up sequence

                I2CWriteByte(MPUREG_PWR_MGMT_1, 0x80);// reset the device (1000 0000)
                await Task.Delay(100);

                I2CWriteByte(MPUREG_PWR_MGMT_1, 0x02); // !!!!!!!! (0000 0010) It doesn't run without this
                I2CWriteByte(MPUREG_USER_CTRL, 0x04); //reset fifo (0000 0100)

                I2CWriteByte(MPUREG_PWR_MGMT_1, 0x01); // clock source = gyro X for reference, which is slightly better than the default internal clock source.

                I2CWriteByte(MPUREG_GYRO_CONFIG, (byte)GyroscopeScale); // +/- ex: 250 degrees sec 

                I2CWriteByte(MPUREG_ACCEL_CONFIG, (byte)AccelerometerScale); // +/- 2g, 4g, 8g, 16g  

                // Digital Low Pass Filter Bandwidth Setting
                I2CWriteByte(MPUREG_CONFIG, (byte)CutOffFreq); // 184 Hz, 2ms delay 

                byte smplrt_div = (byte)((1000 / SampleRate) - 1);
                I2CWriteByte(MPUREG_SMPLRT_DIV, smplrt_div);  // = 19: set rate 50Hz, 99 ~ 10Hz

                //I2CWriteByte(MPUREG_FIFO_EN, 0x78); // (0111 1000) enable accel and gyro to read into fifo
                //I2CWriteByte(MPUREG_FIFO_EN, 0xF8); // (1111 1000) enable temperature,accel and gyro to read into fifo
                //I2CWriteByte(MPUREG_FIFO_EN, 0x08); // (0000 1000) enable only accel to read into fifo
                //I2CWriteByte(MPUREG_USER_CTRL, 0x40); // (0100 0000) reset and enable fifo
                I2CWriteByte(MPUREG_INT_ENABLE, 0x01); // (0000 0001)  DATA_RDY_EN , enables the Data Ready interrupt
                //I2CWriteByte(MPUREG_INT_ENABLE, 0x10); // (0001 0000)  FIFO_OVERFLOW_EN , enables the fifo overflow interrupt
            }
            /* If the write fails display the error and stop running */
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to communicate with device: " + ex.Message);
                return;
            }
        }

        public async void InitializeMPUHighSpeed()
        {
            try
            {
                await Task.Delay(3); // wait 3ms power up sequence

                I2CWriteByte(MPUREG_PWR_MGMT_1, 0x80);// reset the device (1000 0000)
                await Task.Delay(100);

                I2CWriteByte(MPUREG_PWR_MGMT_1, 0x02); // !!!!!!!! (0000 0010) It doesn't run without this
                I2CWriteByte(MPUREG_USER_CTRL, 0x04); //reset fifo (0000 0100)

                I2CWriteByte(MPUREG_PWR_MGMT_1, 0x01); // clock source = gyro X for reference, which is slightly better than the default internal clock source.

                // Configure Gyro and Accelerometer
                // Disable FSYNC and set accelerometer and gyro bandwidth to 44 and 42 Hz, respectively; 
                // DLPF_CFG = bits 2:0 = 010; this sets the sample rate at 1 kHz for both
                // Maximum delay is 4.9 ms which is just over a 200 Hz maximum rate
                I2CWriteByte(MPUREG_CONFIG, 0x03);

                // 2g "0000 0000" = 0x00
                // 4g "0000 1000" = 0x08 ;
                // 8g "0001 0000" = 0x10;
                // 16g "0001 1000" = 0x18;

                I2CWriteByte(MPUREG_ACCEL_CONFIG, 0x00); //2g

                // Set accelerometer sample rate configuration
                // It is possible to get a 4 kHz sample rate from the accelerometer by choosing 1 for
                // accel_fchoice_b bit [3]; in this case the bandwidth is 1.13 kHz
                byte c = I2CReadByte(MPUREG_ACCEL_CONFIG_2); // get current ACCEL_CONFIG2 register value                
                c = (byte)(c & ~0x0F); // Clear accel_fchoice_b (bit 3) and A_DLPFG (bits [2:0])  
                c = (byte)(c | 0x03);  // Set accelerometer rate to 1 kHz and bandwidth to 41 Hz
                I2CWriteByte(MPUREG_ACCEL_CONFIG_2, c); // Write new ACCEL_CONFIG2 register value

                // Digital Low Pass Filter Bandwidth Setting
                //I2CWriteByte(MPUREG_CONFIG, (byte)CutOffFreq); // 184 Hz, 2ms delay 

                //byte smplrt_div = (byte)((1000 / SampleRate) - 1);
                //I2CWriteByte(MPUREG_SMPLRT_DIV, smplrt_div);  // = 19: set rate 50Hz, 99 ~ 10Hz
                //I2CWriteByte(MPUREG_FIFO_EN, 0x78); // (0111 1000) enable accel and gyro to read into fifo
                //I2CWriteByte(MPUREG_FIFO_EN, 0xF8); // (1111 1000) enable temperature,accel and gyro to read into fifo
                //I2CWriteByte(MPUREG_FIFO_EN, 0x08); // (0000 1000) enable only accel to read into fifo
                //I2CWriteByte(MPUREG_USER_CTRL, 0x40); // (0100 0000) reset and enable fifo
                I2CWriteByte(MPUREG_INT_ENABLE, 0x01); // (0000 0001)  DATA_RDY_EN , enables the Data Ready interrupt
                //I2CWriteByte(MPUREG_INT_ENABLE, 0x10); // (0001 0000)  FIFO_OVERFLOW_EN , enables the fifo overflow interrupt
            }
            /* If the write fails display the error and stop running */
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to communicate with device: " + ex.Message);
                return;
            }
        }

        public async void ResetMPU()
        {
            I2CWriteByte(MPUREG_PWR_MGMT_1, 0x80);// reset the device (1000 0000)
            await Task.Delay(100);
        }

        byte[] RegAddrBuf = new byte[] { MPUREG_ACCEL_XOUT_H }; /* Register address we want to read from                                         */
        byte[] ReadBuf = new byte[20];                   /* We read 6 bytes sequentially to get all 3 two-byte axes registers in one read */

        public byte[] MPU_ReadDataRAW()
        {
            //Stopwatch watch = Stopwatch.StartNew();
            //interrupt_status = I2CReadByte(MPUREG_INT_STATUS);
            try
            {
                I2cCommunication.WriteRead(RegAddrBuf, ReadBuf);
            }

            catch (Exception ex)
            {
                Debug.WriteLine("Failed to read MPU4Labview" + ex.Message);
            }
            //Debug.WriteLine(string.Format("** Duration (ms): {0}", watch.ElapsedMilliseconds));
            return ReadBuf;
        }

        public static byte MPU_I2C_ADDRESS_SECONDARY = 0x69;  // Device address when ADO = 1

        public static byte MPU_I2C_ADDRESS_PRIMARY = 0x68;  // Device address when ADO = 0


        protected const byte MPU_I2C_ADDR = 0x68;                     /* I2C address of the MPU */

        
    }
}
LIDAR_LITEv2.csC#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Gpio;

namespace IoTController
{
    class LIDAR_LITEv2: DEVICE, IDisposable
    {
        public LIDAR_LITEv2()
        {
            this.DeviceName = "Lidar Lite";
            this.DeviceID = 22;
            this.DeviceDescription = "Laser Sensor";
            this.DeviceAvailable = true;

            I2C_ADDRESS = LIDAR_I2C_ADDR;
        }

        public byte LIDAR_I2C_ADDRESS
        {
            get { return LIDAR_I2C_ADDR; }
        }

        public void EnableLidar()
        {
            IoControlPin.Write(GpioPinValue.High);
        }

        public void DisableLidar()
        {
            IoControlPin.Write(GpioPinValue.Low);
        }

        public async void ResetLidar()
        {
            I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_COMMAND_CONTROL, 0x00 });
            await Task.Delay(100);
        }

        public async void InitializeDistanceReading()
        {
            try
            {
                //I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_COMMAND_CONTROL, 0x00 }); // Reset LIDAR Sensor
                // equivelent to writing 0x00 to 0x00, i.e. full reset of sensor, if you write nothing for configuration or 0, the sensor will initiate normally

                //Task.Delay(100);

                I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_READING_INTERVAL, 0xC8 }); //  Register 0x45 sets the time between measurements. 0xc8 corresponds to 10Hz
                                                                                             //  while 0x13 corresponds to 100Hz. Minimum value is 0x02 for proper
                                                                                             //  operation.
                await Task.Delay(10);

                I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_ACQUISITION_MODE, 0x21 }); //0x21 - modePinLow--------------------------0x80 - Switch to Velocity Mode)

                await Task.Delay(10);

                I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_NUMBER_OF_READINGS, 0xFF }); //0xFF = continuous readings

                await Task.Delay(10);

                I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_COMMAND_CONTROL, 0x04 });    /* Write 0x04 to initiate an aquisition. */

            }

            catch (Exception ex)
            {
                Debug.WriteLine("Failed to communicate with device: " + ex.Message);
                return;
            }

        }

        public void InitializeVelocityReading()
        {
            try
            {
                I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_COMMAND_CONTROL, 0x04 });   //  Write 0x04 to register 0x00 to start getting distance readings
                I2cCommunication.Write(new byte[] { LIDAR_I2C_REG_ACQUISITION_MODE, 0x80 });  //  Write 0x80 to 0x04 to switch on velocity mode
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to communicate with device: " + ex.Message);
                return;
            }
        }

        public void ReadDistance_RAW()
        {
            I2cCommunication.Write(Reg_LIDAR_I2C_DISTANCE);
            I2cCommunication.Read(Read_LIDAR_Distance_Output_Buf);
        }


        public void ReadDataRAW()
        {
            // Read Lidar Distance
            I2cCommunication.Write(Reg_LIDAR_I2C_DISTANCE);
            I2cCommunication.Read(Read_LIDAR_Distance_Output_Buf);

            // Read Lidar Signal Strength
            I2cCommunication.Write(Reg_LIDAR_I2C_SIGNAL_STRENGTH);
            I2cCommunication.Read(Read_LIDAR_Signal_Strength_Buf);
        }

        public short Distance
        {
            get
            {
                return (short)(Read_LIDAR_Distance_Output_Buf[0] << 8 | Read_LIDAR_Distance_Output_Buf[1]);
            }
        }

        public byte[] DistanceRAW
        {
            get
            {
                return Read_LIDAR_Distance_Output_Buf;
            }
        }

        public void ReadSignalStrength_RAW()
        {
            I2cCommunication.Write(Reg_LIDAR_I2C_SIGNAL_STRENGTH);
            I2cCommunication.Read(Read_LIDAR_Signal_Strength_Buf);
        }

        public byte SignalStrength
        {
            get
            {
                return Read_LIDAR_Signal_Strength_Buf[0];
            }
        }

        public void ReadLidarVelocityRAW()
        {
            I2cCommunication.Write(Reg_LIDAR_I2C_REG_VELOCITY);
            I2cCommunication.Read(Read_LIDAR_Velocity_Buf);
        }

        public byte Velocity
        {
            get
            {
                return Read_LIDAR_Velocity_Buf[0];
            }
        }


        private byte[] dataLabview = new byte[3];
        public byte[] Lidar4Labview()
        {
            // Read Lidar Distance
            I2cCommunication.Write(Reg_LIDAR_I2C_DISTANCE);
            I2cCommunication.Read(Read_LIDAR_Distance_Output_Buf);

            // Read Lidar Signal Strength
            I2cCommunication.Write(Reg_LIDAR_I2C_SIGNAL_STRENGTH);
            I2cCommunication.Read(Read_LIDAR_Signal_Strength_Buf);

            Array.Copy(Read_LIDAR_Distance_Output_Buf, 0, dataLabview, 0, 2);
            Array.Copy(Read_LIDAR_Signal_Strength_Buf, 0, dataLabview, 2, 1);
            //Debug.WriteLine(dataLabview[2].ToString());
            return dataLabview;
        }

        public void Dispose()
        {
            if (I2cCommunication !=null)
            {
                Debug.WriteLine("Dispose LIDARLITE I2C Communication");
                ResetLidar();
                DisableLidar();
                I2cCommunication.Dispose();
                I2cCommunication = null;
            }

            GC.SuppressFinalize(this);
        }

        private byte[] Reg_LIDAR_I2C_DISTANCE = new byte[] { LIDAR_I2C_DISTANCE_OUTPUT }; /* Register address we want to read from                                         */
        private byte[] Read_LIDAR_Distance_Output_Buf = new byte[2];

        private byte[] Reg_LIDAR_I2C_SIGNAL_STRENGTH = new byte[] { LIDAR_I2C_REG_SIGNAL_STRENGTH };
        private byte[] Read_LIDAR_Signal_Strength_Buf = new byte[1];

        private byte[] Reg_LIDAR_I2C_REG_VELOCITY = new byte[] { LIDAR_I2C_REG_VELOCITY_OUTPUT };
        private byte[] Read_LIDAR_Velocity_Buf = new byte[1];

        // =======================================================================
        private const byte LIDAR_I2C_ADDR = 0x62;                   /*  Default: 0x62, the default LIDAR-Lite address. */
        private const byte LIDAR_I2C_REG_COMMAND_CONTROL = 0x00;    /* default or 0 = equivelent to writing 0x00 to 0x00, i.e. full reset of sensor, if you write nothing for configuration or 0, the sensor will initiate normally
                                                                        1 = high speed setting, set the aquisition count to 1/3 the default (works great for stronger singles) can be a little noisier 
                                                                        Write 0x04 to register 0x00 to begin taking measurements */
        private const byte LIDAR_I2C_REG_READING_INTERVAL = 0x45;   // set the time between measurements, default is 0x04

        private const byte LIDAR_I2C_REG_ACQUISITION_MODE = 0x04;

        private const byte LIDAR_I2C_REG_NUMBER_OF_READINGS = 0x11; /*sets the number of readings to take before stopping 
                                                                    (Note: even though the sensor will stop taking new readings, 0x8f will still read back the last recorded value), 
                                                                    default value is 0xFF (which sets the sensor to take infinite readings without stopping). Minimum value for operation is 0x02. */
        private const byte LIDAR_I2C_REG_SYSTEM_STATUS = 0x01;     // Read register 0x01 (this is handled in the read() command)
                                                                   // if the first bit is "1" then the sensor is busy, loop until the first bit is "0"
                                                                   // if the first bit is "0" then the sensor is ready


        private const byte LIDAR_I2C_DISTANCE_OUTPUT = 0x8F;

        private const byte LIDAR_I2C_REG_VELOCITY_OUTPUT = 0x09;
        private const byte LIDAR_I2C_REG_ACQUISITION_STATUS = 0x47;

        private const byte LIDAR_I2C_REG_SIGNAL_STRENGTH = 0x0E; //Received"signal"strength"(typical"range"10 min"! 128 maximum)

        private const byte LIDAR_I2C_REG_VELOCITY_SCALING = 0x68; // or REG-Processing"range"gate"(high"byte)"

    }
}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Physical Computing - Scratch 2.0 for Raspberry Pi
Easy
  • 157
  • 5

Full instructions

This is my 3rd tutorial with a focus on Scratch and Physical Computing using RPi. Here we will explore the new version of Scratch, the 2.0.

Break your heart - IoT Project - IoT Blocky
Easy
  • 70
  • 2

Full instructions

Using this project to control the LEDs on the Raspberry Pi Sense HAT

Hey Mycroft, Where Is the International Space Station?
Easy
  • 1,909
  • 37

Full instructions

Developing my first skill with the Mycroft.ai open source voice assistant on a Raspberry Pi 3 - aka Picroft!

Break your heart - IoT Project - Blinky - 2 LEDs
Easy
  • 23
  • 1

Full instructions

The Blinky project with two leds

Break your heart - IoT Project - Hello World
Easy
  • 34
  • 1

Full instructions

Hello World sample

Break your heart - IoT Project - Blinky
Easy
  • 41
  • 1

Full instructions

Break your heart project with IoT project: Blinky app!!!!!!!!!!!

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog