【发布时间】:2018-10-17 02:02:02
【问题描述】:
我正在将 Xamarin 表单与 I2C 设备和 Raspberry Pi 结合使用。我用 C# 编程,Raspberry Pi 与 Windows IoT 一起安装。而且我遇到了参数访问的问题。
我在 UWP 项目中有一个微定时器,我想每 100 毫秒从模拟输入读取数据。在 OnTimedEvent 中,有一个计算需要在 PCL 项目中设置的一些参数,命名空间是“I2CADDA.MainPage.xaml.cs”。我尝试将这些参数设置为公共静态。
public static double gainFactor = 1;
public static double gainVD = 1;
而在UWP项目中,我使用了依赖服务,因为要使用微定时器,所以接口的实现是在“I2CADDA.UWP.MainPage.xaml.cs”中完成的,在函数OnTimedEvent中,我试图从 PCL 项目文件中获取参数。
public void OnTimedEvent(object sender, MicroLibrary.MicroTimerEventArgs timerEventArgs)
{
byte[] readBuf = new byte[2];
I2CDevice.ReadI2C(chan, readBuf); //read voltage data from analog to digital converter
sbyte high = (sbyte)readBuf[0];
int mvolt = high * 16 + readBuf[1] / 16;
val = mvolt / 204.7 + inputOffset;
val = val / gainFactor / gainVD; //gainFactor and gainVD shows not exist in current context
}
UWP项目似乎无法正常访问PCL项目。请问我该如何解决这个问题?非常感谢!!!
【问题讨论】:
标签: c# xamarin.forms uwp