这个问题在这里被问了好几千次.但实际上,你的例子和答案都不适合我.那么让我告诉你我的代码.
public class PlayList : INotifyPropertyChanged{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string name) {
var handler = PropertyChanged;
if (handler != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
private string _dl;
public string DriveLetter {
get { return _dl; }
set {
if (value != _dl) {
_dl = value;
OnPropertyChanged("DriveLetter");
}
}
}
}
public partial class MainWindow : Window {
public PlayList playlist = new PlayList();
private void Window_Loaded(object sender, RoutedEventArgs e) {
Binding bind = new …Run Code Online (Sandbox Code Playgroud) 我正在制作一个Modbus库(再次......).这次它意味着在Windows 10 IoT Core上运行.
我遇到了一个有趣的问题.这段代码:
string aqs = SerialDevice.GetDeviceSelector();
var dis = await DeviceInformation.FindAllAsync(aqs);
var port = await SerialDevice.FromIdAsync(dis[0].Id);
if (port != null) {
port.BaudRate = 9600;
port.DataBits = 8;
port.StopBits = SerialStopBitCount.One;
port.Parity = SerialParity.None;
port.Handshake = SerialHandshake.None;
port.ReadTimeout = TimeSpan.FromMilliseconds(1000);
port.WriteTimeout = TimeSpan.FromMilliseconds(1000);
}
Run Code Online (Sandbox Code Playgroud)
在通用应用程序中使用完美.当然,如果您将以下代码添加到Package.appxmanifest:
<Capabilities>
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>
Run Code Online (Sandbox Code Playgroud)在通用类库中使用(文件 - >新建项目 - > ... - > Windows - >通用 - > VS2015中的类库(通用Windows))从mscorlib.dll创建空引用异常,这与删除时相同来自Universal app的Package.appxmanifest的DeviceCapability.
我怀疑这种行为与类库没有清单文件有关,因此没有适当的权限.
我可以在类库中使用Windows.Devices.SerialCommunication吗?
是微软让我告诉用户'嘿!我为你制作了一个无用的库,你必须在你的任何应用程序中单独实现传输层.?
c# class-library serial-port win-universal-app windows-10-iot-core