在C#中使用ioctl

我正在尝试通过C#使用orangePi spi。下面的C中有一个代码示例。我可以使用C#DllImport属性导入open / ioctl方法。但是我不知道如何获取SPI_IOC_WR_MODE / SPI_IOC_WR_BITS_PER_WORD / SPI_IOC_WR_MAX_SPEED_HZ值。 SPI_IOC_WR_MODE定义为_IOR(SPI_IOC_MAGIC,1,__u8)。因此,它不是一个恒定值。

如何从C#中获取实际的SPI_IOC_WR_MODE值?

int wiringPiSPISetupMode (int channel,int speed,int mode)
{
  int fd ;

  mode    &= 3 ;    // Mode is 0,1,2 or 3
  channel &= 1 ;    // Channel is 0 or 1

  if ((fd = open (channel == 0 ? spiDev0 : spiDev1,O_RDWR)) < 0)
    return wiringPiFailure (WPI_ALMOST,"Unable to open SPI device: %s\n",strerror (errno)) ;

  spiSpeeds [channel] = speed ;
  spiFds    [channel] = fd ;

// Set SPI parameters.

  if (ioctl (fd,SPI_IOC_WR_MODE,&mode)            < 0)
    return wiringPiFailure (WPI_ALMOST,"SPI Mode Change failure: %s\n",strerror (errno)) ;

  if (ioctl (fd,SPI_IOC_WR_BITS_PER_WORD,&spiBPW) < 0)
    return wiringPiFailure (WPI_ALMOST,"SPI BPW Change failure: %s\n",SPI_IOC_WR_MAX_SPEED_HZ,&speed)   < 0)
    return wiringPiFailure (WPI_ALMOST,"SPI Speed Change failure: %s\n",strerror (errno)) ;

  return fd ;
}
shenghuat 回答:在C#中使用ioctl

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3138694.html

大家都在问