public byte[] Write(IDigitalOut DeviceSelect, byte[] Data, int DataLength) { DeviceSelect.SetOutput(false); byte[] DataReturn = RaspberryPi.SPIRW(BusNum, Data, DataLength); DeviceSelect.SetOutput(true); return(DataReturn); }
private void CheckDev(byte Address) { if (this.DeviceIDs[Address] < 1) { this.DeviceIDs[Address] = RaspberryPi.I2CSetup(Address); } }
public UARTBusPi(byte Device, int Baud) { if (Device == 0) { RaspberryPi.SetPinMode(8, RaspberryPi.PinMode.OUTPUT); RaspberryPi.SetPinMode(10, RaspberryPi.PinMode.INPUT); } this.DeviceID = RaspberryPi.SerialOpen(Device, Baud); }
/// <summary> Selects the register in the given device, then writes the given data. </summary> /// <param name="Address"> The address of the device to write data to. </param> /// <param name="Register"> The register to start writing data at. </param> /// <param name="Data"> The 8-bit data to write. If more than 1 byte, subsequent registers are written. </param> public void WriteRegister(byte Address, byte Register, byte[] Data) { CheckDev(Address); lock (this.BusLock) { for (int i = 0; i < Data.Length; i++) { RaspberryPi.I2CWriteRegister8(this.DeviceIDs[Address], (byte)(Register + i), Data[i]); } } }
/// <summary> Writes the data as given to the device at the specified address. </summary> /// <param name="Address"> The address of the device to write data to. </param> /// <param name="Data"> The 8-bit data to write to the device. </param> public void Write(byte Address, byte[] Data) { CheckDev(Address); lock (this.BusLock) { foreach (byte Byte in Data) { RaspberryPi.I2CWrite(this.DeviceIDs[Address], Byte); } } }
public void Write(byte Address, byte[] Data) { if (this.DeviceIDs[Address] < 1) { this.DeviceIDs[Address] = RaspberryPi.I2CSetup(Address); } foreach (byte Byte in Data) { RaspberryPi.I2CWrite(this.DeviceIDs[Address], Byte); } }
/// <summary> Requests 8-bit data from the given device at the specified register. </summary> /// <param name="Address"> The address of the device to read from. </param> /// <param name="Register"> The register to start reading data from. </param> /// <param name="DataLength"> How many bytes to read. If more than 1, subsequent registers are polled. </param> public byte[] ReadRegister(byte Address, byte Register, int DataLength) { CheckDev(Address); byte[] Data = new byte[DataLength]; lock (this.BusLock) { for (int i = 0; i < DataLength; i++) { Data[i] = RaspberryPi.I2CReadRegister8(this.DeviceIDs[Address], (byte)(Register + i)); } } return(Data); }
/// <summary> Reads 8-bit data from the device at the given address. </summary> /// <param name="Address"> The address of the device to read from. </param> /// <param name="DataLength"> How many bytes to read. </param> public byte[] Read(byte Address, int DataLength) { CheckDev(Address); byte[] Buffer = new byte[DataLength]; lock (this.BusLock) { for (int i = 0; i < DataLength; i++) { Buffer[i] = RaspberryPi.I2CRead(this.DeviceIDs[Address]); } } return(Buffer); }
public byte[] Read(byte Address, int DataLength) { if (this.DeviceIDs[Address] < 1) { this.DeviceIDs[Address] = RaspberryPi.I2CSetup(Address); } byte[] Buffer = new byte[DataLength]; for (int i = 0; i < DataLength; i++) { Buffer[i] = RaspberryPi.I2CRead(this.DeviceIDs[Address]); } return(Buffer); }
public byte[] Read(int Length) { List <byte> Data = new List <byte>(); int Avail = RaspberryPi.SerialDataAvailable(this.DeviceID); if (Avail < Length) { Length = Avail; } for (int i = 0; i < Length; i++) { Data.Add(RaspberryPi.SerialGetChar(this.DeviceID)); } return(Data.ToArray()); }
/// <summary> /// Registers an interrupt handler for the specified interrupt type. /// </summary> public void RegisterInterruptHandler(EventHandler <InputInterrupt> Handler, InterruptType Type) { switch (Type) { case InterruptType.RISING_EDGE: { if (!this.RisingInit) { RaspberryPi.AddInterrupt(this.PinNumber, 2, this.InterruptRising); this.RisingInit = true; } this.RisingHandlers += Handler; return; } case InterruptType.FALLING_EDGE: { if (!this.FallingInit) { RaspberryPi.AddInterrupt(this.PinNumber, 1, this.InterruptFalling); this.FallingInit = true; } this.FallingHandlers += Handler; return; } case InterruptType.ANY_EDGE: { if (!this.AnyInit) { RaspberryPi.AddInterrupt(this.PinNumber, 3, this.InterruptAny); this.AnyInit = true; } this.AnyHandlers += Handler; return; } } }
/// <summary> Reads data from a 16-bit register. </summary> /// <param name="Address"> The address of the device to read from. </param> /// <param name="Register"> The register to read from. </param> /// <returns> The 16-bit data in the register. </returns> public ushort ReadRegister16(byte Address, byte Register) { CheckDev(Address); lock (this.BusLock) { return(RaspberryPi.I2CReadRegister16(this.DeviceIDs[Address], Register)); } }
/// <summary> /// Gets the current logic-level input. /// </summary> public bool GetInput() { return(RaspberryPi.DigitalRead(this.PinNumber)); }
/// <summary> /// Sets the input to either have a ~50KΩ pullup resistor, pulldown resistor, or no resistor. /// </summary> public void SetResistor(ResistorState Resistor) { RaspberryPi.SetResistor(this.PinNumber, Resistor); }
public DigitalInPi(int PinNumber) { this.PinNumber = PinNumber; RaspberryPi.SetPinMode(this.PinNumber, (int)RaspberryPi.PinMode.INPUT); }
/// <summary> Writes data to a 16-bit register. </summary> /// <param name="Address"> The address of the device to write to. </param> /// <param name="Register"> The register to write data to. </param> /// <param name="Data"> The 16-bit data to write to the register. </param> public void WriteRegister16(byte Address, byte Register, ushort Data) { CheckDev(Address); lock (this.BusLock) { RaspberryPi.I2CWriteRegister16(this.DeviceIDs[Address], Register, Data); } }
public void SetBusSpeed(int Speed) { RaspberryPi.SPISetup(BusNum, Speed); }
public void Write(byte[] Data) { RaspberryPi.SerialPut(this.DeviceID, Data); }
public SPIBusPi(int Bus) { BusNum = Bus; RaspberryPi.SPISetup(Bus, DEFAULT_SPEED); }