我试图动态列出连接到计算机的USB与某个UsbDeviceClass匹配
有关我尝试在设备管理器中列出的USB类的信息如下
理想情况下它应该能够列出Com端口,因为我希望列出的设备特别是Arduinos.
DeviceInformationCollection usbDeviceInfoCollection = await DeviceInformation.FindAllAsync(UsbDevice.GetDeviceClassSelector(new UsbDeviceClass()
{
ClassCode = 0x02,
SubclassCode = 0x02,
ProtocolCode = 0x01
}));
Debug.WriteLineIf(usbDeviceInfoCollection.Count == 1, "1 USB device found");
Debug.WriteLineIf(usbDeviceInfoCollection.Count != 1, usbDeviceInfoCollection.Count + " USB devices found");
for (int i = 0; i < usbDeviceInfoCollection.Count; i++)
{
Debug.WriteLine("USB Device " + (i + 1));
Debug.WriteLine("ID: " + usbDeviceInfoCollection[i].Id);
Debug.WriteLine("Name: " + usbDeviceInfoCollection[i].Name);
Debug.WriteLine("Properties: " + usbDeviceInfoCollection[i].Properties);
Debug.WriteLine("");
}
Run Code Online (Sandbox Code Playgroud)
上面的代码显示了我一直在努力实现这一目标,但到目前为止,我没有运气.这是因为当程序运行时,它会在连接了设备时返回0个设备.
我也尝试使用预定义的类UsbDeviceClasses.CdcControl,但是,也没有达到我想要的结果.
我很欣赏任何关于如何正确实现这一目标的指导.
此外,由于这是一个UWP项目,我已经包含了下面的功能,因此它应该能够检测到我想要的设备.
<DeviceCapability Name="serialcommunication">
<Device …Run Code Online (Sandbox Code Playgroud) 我正在C#/ .Net 4.5中编写一个服务器端控制台应用程序,它可以获取一些数据并创建保存以供Web服务器显示的静态图表图像.
我主要使用这里描述的方法:http: //lordzoltan.blogspot.com/2010/09/using-wpf-to-render-bitmaps.html
但是,我添加了一个mainContainer.UpdateLayout(); 在Arrange()之后,数据绑定会更新并在渲染图像中可见,以及在它之前的一个Measure()......啊,我不会去那里.
以下是执行渲染的方法:
void RenderAndSave(UIElement target, string filename, int width, int height)
{
var mainContainer = new Grid
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch
};
mainContainer.Children.Add(target);
mainContainer.Measure(new Size(width, height));
mainContainer.Arrange(new Rect(0, 0, width, height));
mainContainer.UpdateLayout();
var encoder = new PngBitmapEncoder();
var render = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
render.Render(mainContainer);
encoder.Frames.Add(BitmapFrame.Create(render));
using (var s = File.Open(filename, FileMode.Create))
{
encoder.Save(s);
}
}
Run Code Online (Sandbox Code Playgroud)
该方法的目标参数将是我所做的WPF/XAML UserControl的一个实例 - 此时相当简单,只是一个网格,其中一些文本数据绑定到我分配给DataContext的ViewModel对象.
对于OxyPlot Plot对象,磁盘上保存的图像看起来很好 - 它完全是白色的.
现在,当我在Visual Studio 2013中担任设计师时,我可以看到它.我添加了一个设计时DataContext,它与我在运行时使用的对象相同(这是我正在做的一个尖峰 …
所以我有以下代码为我的TableView动态创建ViewCells :
XAML:
<StackLayout>
<TableView Intent="Settings">
<TableView.Root>
<TableSection x:Name="tableSection"></TableSection>
</TableView.Root>
</TableView>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
C#:
categories = getCategories();
foreach (var category in categories)
{
var viewCell = new ViewCell
{
View = new StackLayout()
{
Padding = new Thickness(20, 0, 20, 0),
HorizontalOptions = LayoutOptions.FillAndExpand,
Children = {
new StackLayout() {
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.CenterAndExpand,
Children = {
new StackLayout() {
HorizontalOptions = LayoutOptions.StartAndExpand,
Children = {
new Label { Text = category.Name}
},
new StackLayout() {
HorizontalOptions …Run Code Online (Sandbox Code Playgroud) 我是.NET Core 2.0的新手,所以我可能做错了,如果是这样,请告诉我.
我有一个应该是跨平台的.NET核心2.0应用程序,因此该应用程序是一个.dll控制台应用程序,它在所有平台上都可以正常工作.
我正在尝试实现一种看门狗,如果必要的过程会复制自己,并以同样的方式被调用
> $ dotnet process.dll
Run Code Online (Sandbox Code Playgroud)
我的代码是:
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "path\release\PublishOutput\proces.dll"
UseShellExecute = true,
RedirectStandardOutput = false,
RedirectStandardError = false,
CreateNoWindow = true
}
};
process.Start();
Run Code Online (Sandbox Code Playgroud)
问题是,当进程运行此代码时,我得到以下异常
未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集'System.Runtime,Version = 4.2.0.0,Culture = neutral,PublicKeyToken = sometoken'或其依赖项之一.该系统找不到指定的文件.
我在代码中找不到任何破坏dotnet的提法,即使这可能,我也不知道?
可能吗?.NET核心流程能够复制自己吗?
谢谢
我在C#WPF应用程序中实现了一些实时图表,但我使用的是WinForms图表,因为它们通常很容易使用,而且性能令人惊讶.
无论如何,我已经把图表工作得很好,除了一个我无法解决的重大问题:

当我向图表添加数据时,它有时只会自行调整大小.有时它会做很多事情,给自己带来摆动,使图表超级阅读和处理烦人.
我的问题是:如何防止这个该死的图表不断调整自己?!
一些其他信息:
该图表包含在我的XAML中:
<WindowsFormsHost Grid.Row="1" Grid.ColumnSpan="2" Margin="5">
<winformchart:Chart Dock="Fill" x:Name="Session0Chart">
<winformchart:Chart.ChartAreas>
<winformchart:ChartArea/>
</winformchart:Chart.ChartAreas>
</winformchart:Chart>
</WindowsFormsHost>
Run Code Online (Sandbox Code Playgroud)
通过以下方式初始化:
// initialize it!
chart.Palette = ChartColorPalette.Bright;
// setup the labels
Font monoSpaceFont = new Font("Consolas", 10);
chart.ChartAreas[0].AxisX.LabelStyle.Font = monoSpaceFont;
chart.ChartAreas[0].AxisY.LabelStyle.Font = monoSpaceFont;
// set the axis limits appropriately
chart.ChartAreas[0].AxisY.Maximum = 600;
chart.ChartAreas[0].AxisY.Minimum = -200;
// set up grid lines and axis styles
chart.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dash;
chart.ChartAreas[0].AxisX.MinorGrid.LineColor = System.Drawing.Color.Gray;
chart.ChartAreas[0].AxisX.MinorGrid.Interval = 0.04;
chart.ChartAreas[0].AxisX.LabelStyle.Format = "F2";
chart.ChartAreas[0].AxisX.LabelAutoFitStyle = …Run Code Online (Sandbox Code Playgroud) 目前我有一个日期时间轴,其中日期与点一致,无论如何都要让这个日期出现在中心,例如条形图上.
<Style x:Key="DateTimeAxisLabelStyle2" TargetType="chartingToolkit:DateTimeAxisLabel">
<Setter Property="DaysIntervalStringFormat" Value="{}{0:dd-MMM}" />
<Setter Property="HoursIntervalStringFormat" Value="{}{0:hh:mm tt}" />
<!--<Setter Property="RenderTransformOrigin" Value="1,0.5" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="-45" />
</Setter.Value>
</Setter>-->
<!--<Setter Property="Margin" Value="30,0,-10,0" />-->
</Style>
<chartingToolkit:DateTimeAxis IntervalType="Days"
Interval="1"
Minimum="{Binding StartDate}"
Maximum="{Binding EndDate}"
Orientation="X"
VerticalContentAlignment="Center"
Title="Day"
AxisLabelStyle="{StaticResource DateTimeAxisLabelStyle2}" />
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
我有这个XAML代码:
<StackLayout Grid.Row="0" Grid.Column="0" Padding="15,10,20,10" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="tapFavorites" NumberOfTapsRequired="1" />
</StackLayout.GestureRecognizers>
<Label x:Name="faveLabel" FontFamily="FontAwesome" XAlign="Center" FontSize="23">
<Label.Triggers>
<DataTrigger TargetType="Label" Binding="{Binding Favorite}" Value="true">
<Setter Property="TextColor" Value="Red" />
</DataTrigger>
<DataTrigger TargetType="Label" Binding="{Binding Favorite}" Value="false">
<Setter Property="TextColor" Value="Gray" />
</DataTrigger>
</Label.Triggers>
</Label>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
在我的C#代码中,我很熟悉设置标签的Text属性,只需指定如下:
sampleLabel.Text = "ABC"
Run Code Online (Sandbox Code Playgroud)
但这种情况有所不同.有人可以告诉我如何在单击标签时从C#更改标签的颜色.
我试图DBMS_OUTPUT.PUT_LINE()通过C#从我的匿名PL/SQL块中获取方法的输出.我在这里看了几个其他相关的问题,但我仍然遇到麻烦.执行匿名块的返回代码正在返回-1,根据文档应该是正确的.
我正在设置DBMS_OUTPUT.ENABLE()to NULL以便不设置特定的缓冲区大小,然后使用该DBMS_OUTPUT.GET_LINES()方法从该缓冲区获取行.
它在缓冲区中返回任何内容(空OracleString[])并返回0行.我的匿名PL/SQL块很简单,但应该适用于任何.
DECLARE
lvsName VARCHAR2(6) := 'Oracle';
BEGIN
DBMS_OUTPUT.PUT_LINE('Do you see me?');
DBMS_OUTPUT.PUT_LINE('My name is: ' || lvsName);
END;
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
using (OracleDataAdapter oda = new OracleDataAdapter())
using (OracleCommand cmd = new OracleCommand(sql, _connection))
{
// Execute anonymous PL/SQL block
cmd.CommandType = CommandType.Text;
var res = cmd.ExecuteNonQuery();
// Set output Buffer
cmd.CommandText = "BEGIN DBMS_OUTPUT.ENABLE(NULL); END;";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
// Get output
cmd.CommandText …Run Code Online (Sandbox Code Playgroud) 我无法用清楚的语言向自己解释为什么由Timer生成的Task工作得很好但是由Task生成的Timer不会.
所有相关代码都包含在下面,因此您可以轻松地重现它.
Form.cs:
private void Form1_Load(object sender, EventArgs e)
{
ProcessDelayList list = new ProcessDelayList();
foreach (ProcessDelay p in list)
{
//this works
p.Start();
//this does NOT work
//Task.Factory.StartNew(() => p.Start());
}
}
Run Code Online (Sandbox Code Playgroud)
ProcessDelayList.cs:
public class ProcessDelayList : List<ProcessDelay>
{
public ProcessDelayList()
{
Add(new ProcessDelay("Process 1", 2000));
Add(new ProcessDelay("Process 2", 4000));
Add(new ProcessDelay("Process 3", 6000));
Add(new ProcessDelay("Process 4", 8000));
Add(new ProcessDelay("Process 5", 10000));
}
}
Run Code Online (Sandbox Code Playgroud)
ProcessDelay.cs:
public class ProcessDelay
{
private string name;
private int delay;
private Timer timer;
public …Run Code Online (Sandbox Code Playgroud) 我有一个简单的UIElement,我想将其转换为MarkupExtension:
[MarkupExtensionReturnType(typeof(FrameworkElement))]
public class PinkRectangle : MarkupExtension
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return new Rectangle {Height = 100, Width = 300, Fill = Brushes.HotPink };
}
}
Run Code Online (Sandbox Code Playgroud)
在大多数情况下,它的效果都很好。唯一的例外是在列表中:
<local:WindowEx x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.winfx/200x/xaml"
xmlns:local="clr-namespace:WpfApp1"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
MyProperty="{Binding local:PinkRectangle}"> <!--this one works.-->
<local:WindowsEx.MyList>
<!--<Grid/> If I comment this line in, it works-->
<local:PinkRectangle/>
</local:WindowsEx.MyList>
<ContentPresenter Content="{Binding MyProperty}"/>
</local:WindowEx>
Run Code Online (Sandbox Code Playgroud)
在Collection Syntax中,它说:
如果属性的类型是集合,则不需要在标记中将推断的集合类型指定为对象元素。而是将要成为集合中项目的元素指定为property元素的一个或多个子元素。每个此类项目在加载过程中都会被评估为一个对象,然后通过调用隐式集合的Add方法将其添加到集合中。
但是,xaml将上面的语法解释为,MyList = PinkRectangle而不是MyList.Add(PinkRectangle)But。但是,如果我先放入Grid,它会正确调用MyList.Add()。两种情况下告诉xaml调用MyList.Add()的正确语法是什么?
这是其余的代码,以创建一个最小的,可复制的示例:
namespace WpfApp1
{
// I …Run Code Online (Sandbox Code Playgroud)