예제 #1
0
 void serialPort_DataReceived(GTI.Serial sender, System.IO.Ports.SerialData data)
 {
     byte[] readData = new byte[rs232.serialPort.BytesToRead];
     rs232.serialPort.Read(readData, 0, readData.Length);
 }
예제 #2
0
 private void _input_Interrupt(GTI.InterruptInput input, bool value)
 {
     this.OnButtonEvent(this, value ? ButtonState.Released : ButtonState.Pressed);
 }
예제 #3
0
 void serialPort_LineReceived(GTI.Serial sender, string line)
 {
     byte[] readData = new byte[rs232.serialPort.BytesToRead];
     rs232.serialPort.Read(readData, 0, readData.Length);
 }
예제 #4
0
        // instructs the sensor to take a single reading and returns the result
        // this function blocks while the reading is being taken so may take up to 30-40ms to return
        private int takeRange(GTI.I2CBus sensor)
        {
            // send a single byte to the device, telling it to start range finding
            byte[] writeBuffer = new byte[1];
            writeBuffer[0] = 81;
            sensor.Write(writeBuffer, timeout);

            // the device now doesn't answer to read requests until it's done,
            // we'll know it's done once it returns something other than 0
            int range = 0;
            while (range == 0)
            {
                // output is given as a 16bit integer,
                // the most significant byte comming first
                byte[] readBuffer = new byte[2];
                sensor.Read(readBuffer, timeout);
                range = readBuffer[0] * 256 + readBuffer[1];
            }

            return range;
        }
예제 #5
0
        // This fires when new data is ready to be read
        void dataReady_Interrupt(GTI.InterruptInput sender, bool value)
        {
            int rawX, rawY, rawZ;

            // Read all the registers at once

            Read(Register.DXRA, readBuffer48);

            rawX = (readBuffer48[0] << 8) | readBuffer48[1];
            rawZ = (readBuffer48[2] << 8) | readBuffer48[3];
            rawY = (readBuffer48[4] << 8) | readBuffer48[5];

            rawX = (((rawX >> 15) == 1) ? -32767 : 0) + (rawX & 0x7FFF);
            rawZ = (((rawZ >> 15) == 1) ? -32767 : 0) + (rawZ & 0x7FFF);
            rawY = (((rawY >> 15) == 1) ? -32767 : 0) + (rawY & 0x7FFF);

            if (rawX == -4096 || rawY == -4096 || rawZ == -4096)
            {
                DebugPrint("Invalid data read. Measurement discarded.");
                return;
            }

            double angle = Atan2((double)rawY, (double)rawX) * (180 / 3.14159265) + 180;

            SensorData sensorData = new SensorData(angle, rawX, rawY, rawZ);

            OnMeasurementCompleteEvent(this, sensorData);
        }
예제 #6
0
        private void pinIRQ_Interrupt(GTI.InterruptInput sender, bool value)
        {
            IsEnabled = false;

            GetStatus();

            //bool isDataReady = status.DataReady;
            //bool isResendLimitReached = status.ResendLimitReached;
            //bool isDataSent = status.DataSent;

            SetReceiveMode();
            //ResetStatus();

            if (Interrupt != null)
                Interrupt(status);

            var payloads = new byte[3][];
            byte payloadIdx = 0;
            var payloadCorrupted = false;

            if (status.DataReady)
            {
                while (!status.RxEmpty)
                {
                    // Read payload size
                    var payloadLength = GetDynamicPayloadSize();
                    if (payloadLength > 32) // this indicates corrupted data
                    {
                        payloadCorrupted = true;
                        FlushRX(); // Flush anything that remains in buffer
                    }
                    else
                    {
                        // Read payload data
                        payloads[payloadIdx] = ReadPayload(payloadLength);
                        payloadIdx++;
                    }
                    GetStatus();
                WriteRegisterBit(Registers.STATUS, Bits.RX_DR, true); // Clear RX_DR bit in status register
                }

            }
            if (status.ResendLimitReached)
            {
                FlushTX();
                WriteRegisterBit(Registers.STATUS, Bits.MAX_RT, true); // Clear MAX_RT bit in status register
            }
            if (status.TxFull)
                FlushTX();
            if (status.DataSent)
                WriteRegisterBit(Registers.STATUS, Bits.TX_DS, true); // Clear TX_DS bit in status register

            IsEnabled = true;

            if (payloadCorrupted)
                Debug.Print("Corrupted data received");
            else if (payloadIdx > 0)
            {
                for (var i = 0; i < payloadIdx; i++)
                    DataReceived(payloads[i]);
            }
            else if (status.DataSent)
            {
                if (TransmitSuccess != null)
                    TransmitSuccess(this, EventArgs.Empty);
            }
            else
            {
                if (TransmitFailed != null)
                    TransmitFailed(this, EventArgs.Empty);
            }
        }
예제 #7
0
 private void daisyLinkInterruptPort_OnInterrupt(GTI.InterruptInput sender, bool value)
 {
     for (byte moduleIndex = 0; moduleIndex < NodeCount; moduleIndex++)
     {
         if (0 != (0x80 & ReadRegister((byte)(moduleIndex + StartAddress), (byte)DaisyLinkRegister.Config)))       // If this is the interrupting module
         {
             byte[] data = new byte[] { (byte)DaisyLinkRegister.Config, 0 };
             Write((byte)(moduleIndex + StartAddress), data);                    // Clear the interrupt on the module
             if (socketModuleList[moduleIndex] != null)
             {
                 socketModuleList[moduleIndex].OnDaisyLinkInterrupt(socketModuleList[moduleIndex]);              // Kick off user event (if any) for this module instance
             }
         }
     }
     //daisyLinkInterruptPort.ClearInterrupt();
 }
예제 #8
0
 private void _input_Interrupt(GTI.InterruptInput input, bool value)
 {
     this.OnPiezoModuleEvent(this, value ? PiezoModuleState.Low : PiezoModuleState.High);
 }