Esempio n. 1
0
        protected void AciSend(AciOpCode opCode, params byte[] data)
        {
            if (data.Length > 30)
            {
                throw new ArgumentOutOfRangeException("data", "The maximum amount of data bytes is 30.");
            }

            // Create ACI packet
            var packet = new byte[data.Length + 2];

            packet[0] = (byte)(data.Length + 1);
            packet[1] = (byte)opCode;
            Array.Copy(data, 0, packet, 2, data.Length);

            // Request transfer
            _rdy.DisableInterrupt();
            _req.Write(false);

            // Wait for RDY to go low
            while (_rdy.Read())
            {
                ;
            }

            _spi.WriteLsb(packet);

            _req.Write(true);

            // Wait for RDY to go high
            while (!_rdy.Read())
            {
                ;
            }
            _rdy.EnableInterrupt();
        }
Esempio n. 2
0
        //private void ProcessEvent(byte[] buff)
        //{
        //    // first byte is event code
        //    byte eventCode = buff[0];
        //    switch (eventCode)
        //    {
        //        case 0x81:
        //            OnDeviceStartedEvent?.Invoke(buff.Length, eventCode, buff[1], buff[2], buff[3]);
        //            break;
        //        case 0x84:
        //            OnCommandResponseEvent?.Invoke(buff.Length, eventCode, buff[1], buff[2], buff);
        //            break;
        //        default:
        //            Debug.WriteLine("Unimplemented event: 0x" + eventCode.ToString("X"));
        //            break;
        //    }
        //}
        #region ACI Interface

        protected void AciSend(AciOpCode opCode, params byte[] data)
        {
            if (data.Length > 30)
            {
                throw new ArgumentOutOfRangeException("data", "The maximum amount of data bytes is 30.");
            }

            //Create ACI packet
            var packet = new byte[data.Length + 2];

            packet[0] = (byte)(data.Length + 1);
            packet[1] = (byte)opCode;
            Array.Copy(data, 0, packet, 2, data.Length);

            // Request transfer
            _rdy.SetDriveMode(GpioPinDriveMode.OutputOpenDrainPullUp);
            _reqn.Write(GpioPinValue.Low);
            while (_rdy.Read() == GpioPinValue.High)
            {
            }
            _spi.WriteLsb(packet);
            _reqn.Write(GpioPinValue.High);
            while (_rdy.Read() == GpioPinValue.Low)
            {
            }
            _rdy.SetDriveMode(GpioPinDriveMode.InputPullUp);
        }
Esempio n. 3
0
        protected void AciSend(AciOpCode opCode, byte arg0, params byte[] data)
        {
            var buffer = new byte[data.Length + 1];

            buffer[0] = arg0;
            Array.Copy(data, 0, buffer, 1, data.Length);
            AciSend(opCode, buffer);
        }
Esempio n. 4
0
        protected void AciSend(AciOpCode opCode, byte arg0, params byte[] data)
        {
            var buffer = new byte[data.Length + 1];

            buffer[0] = arg0;
            Array.Copy(data, 0, buffer, 1, data.Length);

            AciSend(opCode, buffer);
        }
Esempio n. 5
0
        protected void AciSend(AciOpCode opCode, params byte[] data)
        {
            if (data.Length > 30)
                throw new ArgumentOutOfRangeException("data", "The maximum amount of data bytes is 30.");

            // Create ACI packet
            var packet = new byte[data.Length + 2];
            packet[0] = (byte)(data.Length + 1);
            packet[1] = (byte)opCode;
            Array.Copy(data, 0, packet, 2, data.Length);

            // Request transfer
            _rdy.DisableInterrupt();
            _req.Write(false);

            // Wait for RDY to go low
            while (_rdy.Read()) ;

            _spi.WriteLsb(packet);

            _req.Write(true);

            // Wait for RDY to go high
            while (!_rdy.Read()) ;
            _rdy.EnableInterrupt();
        }