C#和arduino连接 - 控制WPF应用程序 [英] C# and arduino connection - controling a WPF application
问题描述
我仍然是编程世界的新手,但如果可能,我需要一些帮助。如果没有,那也没关系。
我有这个任务,我必须在C#(WPF)和Arduino之间建立连接。现在,我设法连接了液晶显示器,因此它将电位计的值输出到液晶显示屏,如图片一旦我在Arduino和C#之间建立连接,C#必须将这些值从电位计输出到Line表单。所以,用简短的话说,我如何用电位计改变当前值,C#中的线必须像我一样移动。我非常擅长解释所以希望你明白我在说什么:P如果有人能帮助我完成这项任务,我会非常高兴。提前致谢
节目:Microsoft Visual Studio(2008-2015),Arduino(最新版)
语言:C#
应用程序:WPF(.NET Framework 4.5)
操作系统:Windows
行表单代码:
I'm still new to the world of programming but I need some help with this if it's possible. If not, that's okay too.
I have this task where I have to establish a connection between C# (WPF) and Arduino. Now, I managed to connect the LCD so it outputs the values from the potenciometer to the LCD screen like in this Picture Once I have the connection between Arduino and C#, C# must output those values from the potenciometer to the "Line" form. So, in shorter words, How I change the current value with the potenciometer, the line in C# MUST be moving as I do it. I'm very bad at explaining so hopefully You understood what I was saying :P If anyone could help me with this task, I'd be more than happy. Thanks in advance
Programs: Microsoft Visual Studio (2008-2015), Arduino (latest version)
Language: C#
Application: WPF (.NET Framework 4.5)
OS: Windows
Line Form code:
<Line
Name="TheLine"
Stretch="Fill"
X1="1" X2="1" Y1="0" Y2="1"
Width="2"
HorizontalAlignment="Center"
Stroke="Black"
>
<Line.RenderTransform>
<TransformGroup>
<RotateTransform CenterX="1" CenterY="{Binding ActualHeight, ElementName=TheLine}"
Angle="{Binding Path=Value, ElementName=AngleSlider}" />
</TransformGroup>
</Line.RenderTransform>
</Line>
<StackPanel Grid.Column="1">
<Slider Name="AngleSlider" Minimum="-90" Maximum="90" Value="0" Height="59" Width="200" />
</StackPanel>
Arduino代码:
Arduino code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Welcome!");
delay(3000);
lcd.clear();
Serial.begin(9600);
}
void loop() {
lcd.print("Current value:");
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
lcd.setCursor(0, 1);
lcd.print(sensorValue /4);
lcd.print("/255 ");
delay(10);
lcd.clear();
Serial.println(sensorValue);
delay(10);
}
我的尝试:
我设法在c#和arduino之间建立连接但是从电位计读取值并将它们带到线上就是我的奋斗。
What I have tried:
I managed to establish a connection between c# and arduino but to read the values from the potenciometer and bring them onto the line is what I struggle.
推荐答案
你很顺利。您接下来需要的只是本文。当然你使用的是Arduino而不是PIC。使用该示例作为解决方案的模板。
使用WPF,RS232和PIC通信的串行通信 [ ^ ]
You are well on the way. All you need next is in this article. Of course you are using Arduino and not PIC. Use the example as a template for your solution.
Serial Communication using WPF, RS232 and PIC Communication[^]
请参阅我对该问题的评论。 />
对于PC端,带.NET的Windows,请参阅开源项目libusb和LibUsbDotNet:
libusb ,
LibUsbDotNet 。
在Arduino方面,您可以从这里开始: Arduino - SoftwareSerial 。
-SA
Please see my comments to the question.
For PC side, Windows with .NET, please see the open-source projects libusb and LibUsbDotNet:
libusb,
LibUsbDotNet.
On Arduino side, you can start here: Arduino — SoftwareSerial.
—SA
这篇关于C#和arduino连接 - 控制WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!