/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <summary> /// Enables the SPI slave device. Will throw exceptions if it cannot open the /// device /// </summary> /// <returns>ssHandle - the handle for the Slave Device or null for fail</returns> /// <param name="spiSlaveDeviceIn">The SPI Slave Device we are configuring</param> /// <history> /// 21 Dec 14 Cynic - Originally written /// </history> public SPISlaveDeviceHandle EnableSPISlaveDevice(SPISlaveDeviceEnum spiSlaveDeviceIn) { string deviceFileName; // set up now deviceFileName = BBBDefinitions.SPIDEV_FILENAME; // set up the spi device number, this is based off the port // NOTE that SPI port 0 goes to /dev/spidev1.x and SPI port 1 // goes to /dev/spidev2.x. That is just the way it is if (SPIPort == SPIPortEnum.SPIPORT_0) { deviceFileName = deviceFileName.Replace("%device%", "1"); } else if (SPIPort == SPIPortEnum.SPIPORT_1) { deviceFileName = deviceFileName.Replace("%device%", "2"); } else { // should never happen throw new Exception("Unknown SPI Port:" + SPIPort.ToString()); } // set up the spi slave number if (spiSlaveDeviceIn == SPISlaveDeviceEnum.SPI_SLAVEDEVICE_CS0) { deviceFileName = deviceFileName.Replace("%slave%", "0"); } else if (spiSlaveDeviceIn == SPISlaveDeviceEnum.SPI_SLAVEDEVICE_CS1) { deviceFileName = deviceFileName.Replace("%slave%", "1"); } else { // should never happen throw new Exception("Unknown SPI Slave Device:" + spiSlaveDeviceIn.ToString()); } // we open the file. We have to have an open file descriptor // note this is an external call. It has to be because the // ioctl needs an open file descriptor it can use int fd = ExternalFileOpen(deviceFileName, O_RDWR | O_NONBLOCK); if (fd <= 0) { throw new Exception("Could not open spidev file:" + deviceFileName); } //Console.WriteLine("SPIPort Slave Device Enabled: "+ deviceFileName); // create a new slave device handle SPISlaveDeviceHandle outHandle = new SPISlaveDeviceHandle(spiSlaveDeviceIn, fd); // record that we opened this slave device (so we can close it later) openSlaveDevices.Add(outHandle); // return the slave device handle return(outHandle); }
public async void Init(List<int> adc_channel, SPIPort spi,int clockfrequency, SpiMode mode) { try { InitChannel(adc_channel); var settings = new SpiConnectionSettings((int)spi); settings.ClockFrequency = clockfrequency; settings.Mode = mode; string spiAqs = SpiDevice.GetDeviceSelector(Enum.GetName(typeof(SPIPort), spi)); var deviceInfo = await DeviceInformation.FindAllAsync(spiAqs); SpiDisplay = await SpiDevice.FromIdAsync(deviceInfo[0].Id, settings); } /* If initialization fails, display the exception and stop running */ catch (Exception ex) { throw new Exception("SPI Initialization Failed", ex); } }
public static int ReadAutoReceivedData(SPIPort port, uint *buffer, int numToRead, double timeout) { return(lowLevel.HAL_ReadSPIAutoReceivedData(port, buffer, numToRead, timeout)); }
public static int Read(SPIPort port, byte *buffer, int count) { return(lowLevel.HAL_ReadSPI(port, buffer, count)); }
public static void Initialize(SPIPort port) { lowLevel.HAL_InitializeSPI(port); }
public static void StartAutoTrigger(SPIPort port, int digitalSourceHandle, AnalogTriggerType analogTriggerType, int triggerRising, int triggerFalling) { lowLevel.HAL_StartSPIAutoTrigger(port, digitalSourceHandle, analogTriggerType, triggerRising, triggerFalling); }
public static void SetSpeed(SPIPort port, int speed) { lowLevel.HAL_SetSPISpeed(port, speed); }
public static void SetHandle(SPIPort port, int handle) { lowLevel.HAL_SetSPIHandle(port, handle); }
public static void ForceAutoRead(SPIPort port) { lowLevel.HAL_ForceSPIAutoRead(port); }
public static void ConfigureAutoStall(SPIPort port, int csToSclkTicks, int stallTicks, int pow2BytesPerRead) { lowLevel.HAL_ConfigureSPIAutoStall(port, csToSclkTicks, stallTicks, pow2BytesPerRead); }
public static void Close(SPIPort port) { lowLevel.HAL_CloseSPI(port); }
public static int Write(SPIPort port, byte *dataToSend, int sendSize) { return(lowLevel.HAL_WriteSPI(port, dataToSend, sendSize)); }
public static int Transaction(SPIPort port, byte *dataToSend, byte *dataReceived, int size) { return(lowLevel.HAL_TransactionSPI(port, dataToSend, dataReceived, size)); }
public static void StopAuto(SPIPort port) { lowLevel.HAL_StopSPIAuto(port); }
public static void SetAutoTransmitData(SPIPort port, byte *dataToSend, int dataSize, int zeroSize) { lowLevel.HAL_SetSPIAutoTransmitData(port, dataToSend, dataSize, zeroSize); }
public static void SetChipSelectActiveLow(SPIPort port) { lowLevel.HAL_SetSPIChipSelectActiveLow(port); }
public static void FreeAuto(SPIPort port) { lowLevel.HAL_FreeSPIAuto(port); }
public static void SetOpts(SPIPort port, int msbFirst, int sampleOnTrailing, int clkIdleHigh) { lowLevel.HAL_SetSPIOpts(port, msbFirst, sampleOnTrailing, clkIdleHigh); }
public static int GetAutoDroppedCount(SPIPort port) { return(lowLevel.HAL_GetSPIAutoDroppedCount(port)); }
public static void StartAutoRate(SPIPort port, double period) { lowLevel.HAL_StartSPIAutoRate(port, period); }
public static int GetHandle(SPIPort port) { return(lowLevel.HAL_GetSPIHandle(port)); }
public static void SPIStatusCheck(int status, SPIPort port) { StatusCheckForce(status); }
public static void InitAuto(SPIPort port, int bufferSize) { lowLevel.HAL_InitSPIAuto(port, bufferSize); }