/// <summary> /// Set up the SPI device and the controller for the transfer ready pin /// </summary> public static void Init() { // Initialize TX header. This only needs to happen once Serialization.Writer.InitTransferHeader(ref _txHeader); // Initialize transfer ready pin _transferReadyPin = new InputGpioPin(Settings.GpioChipDevice, Settings.TransferReadyPin); _transferReadyPin.PinChanged += (sender, pinValue) => _transferReadyEvent.Set(); _transferReadyPin.StartMonitoring(Program.CancelSource.Token); // Initialize SPI device _spiDevice = new SpiDevice(Settings.SpiDevice, Settings.SpiFrequency); // Check if large transfers can be performed try { int maxSpiBufferSize = int.Parse(File.ReadAllText("/sys/module/spidev/parameters/bufsiz")); if (maxSpiBufferSize < Communication.Consts.BufferSize) { Console.WriteLine($"[warn] Kernel SPI buffer size is smaller than RepRapFirmware buffer size ({maxSpiBufferSize} configured vs {Communication.Consts.BufferSize} required)"); } } catch (Exception e) { Console.WriteLine("[warn] Failed to retrieve Kernel SPI buffer size:"); Console.WriteLine(e); } }
/// <summary> /// Set up the SPI device and the controller for the transfer ready pin /// </summary> public static void Init() { // Initialize TX header. This only needs to happen once Serialization.Writer.InitTransferHeader(ref _txHeader); // Initialize TX buffers for (int i = 0; i < NumTxBuffers; i++) { _txBuffers.AddLast(new byte[Communication.Consts.BufferSize]); } _txBuffer = _txBuffers.First; // Initialize transfer ready pin _transferReadyPin = new InputGpioPin(Settings.GpioChipDevice, Settings.TransferReadyPin, $"dcs-trp-{Settings.TransferReadyPin}"); _transferReadyPin.PinChanged += (sender, pinValue) => _transferReadyEvent.Set(); _ = _transferReadyPin.StartMonitoring(Program.CancelSource.Token); // Initialize SPI device _spiDevice = new SpiDevice(Settings.SpiDevice, Settings.SpiFrequency); // Check if large transfers can be performed try { int maxSpiBufferSize = int.Parse(File.ReadAllText("/sys/module/spidev/parameters/bufsiz")); if (maxSpiBufferSize < Communication.Consts.BufferSize) { _logger.Warn("Kernel SPI buffer size is smaller than RepRapFirmware buffer size ({0} configured vs {1} required)", maxSpiBufferSize, Communication.Consts.BufferSize); } } catch (Exception e) { _logger.Warn(e, "Failed to retrieve Kernel SPI buffer size"); } }
/// <summary> /// Set up the SPI device and the controller for the transfer ready pin /// </summary> public static void Initialize() { // Initialize TX header. This only needs to happen once Serialization.Writer.InitTransferHeader(ref _txHeader); // Initialize transfer ready pin _transferReadyPin = new InputGpioPin(Settings.GpioChipDevice, Settings.TransferReadyPin); _transferReadyPin.PinChanged += (sender, pinValue) => _transferReadyEvent.Set(); _transferReadyPin.StartMonitoring(Program.CancelSource.Token); // Initialize SPI device _spiDevice = new SpiDevice($"/dev/spidev{Settings.SpiBusID}.{Settings.SpiChipSelectLine}", Settings.SpiFrequency); }