Arduino 보드와 통신하는 프로그램을 C#으로 설계하려고합니다. 이 프로그램은 Arduino에서 정수 데이터를 받아 값과 관련된 것을 표시해야합니다.arduino에서 int를 PC에있는 C#으로 보내는 방법
유일하게 필요한 것은 C# 및 Arduino Uno의 코드로 arduino에서 pc (노트북 통합 블루투스)의 C#으로 값 (int)을 전송하는 것입니다.
내 프로그램 코드가 필요한지 문의하십시오.
C#에서 프로그램을 완료했습니다. 올바른지 알려주세요.
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
public class travauxEncadre
{
static public void Main()
{
string data = "0";
int Consommer = int.Parse(data);
//Début Prise des valeurs manuelle
Console.Clear();
//Définition du seuil d'avertissement
Console.WriteLine("Seuil d'avertissement");
string SeuilAvertissement = Console.ReadLine();
Console.Clear();
// Définition du seuil d'exces
Console.WriteLine("Seuil d'exces");
string SeuilExces = Console.ReadLine();
Console.Clear();
//Défintion de la conso actuelle (a enlever)
// Console.WriteLine("Consommation");
// string Conso = Console.ReadLine();
// Console.Clear();
int Avertissement = int.Parse(SeuilAvertissement);
int Exces = int.Parse(SeuilExces);
// int Consommer = int.Parse(Conso);
//Fin Prise des valeurs manuelle
//Début Bluetooth
SerialPort port;
port = new SerialPort();
port.BaudRate = 9600;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.PortName = "COM4";
port.DataReceived += Port_DataReceived;
port.Open();
//Fin Bluetooth
//Début Vérification
if (Avertissement >= Exces)
{
Console.WriteLine("Impossible");
System.Threading.Thread.Sleep(1000);
}
else
{
if (Consommer < Avertissement)
{
Console.WriteLine("Vert");
Console.WriteLine(data + " Kw/H");
System.Threading.Thread.Sleep(1000);
}
else
{
if (Consommer >= Exces)
{
Console.WriteLine("Rouge");
Console.WriteLine(data + "Kw/H");
System.Threading.Thread.Sleep(1000);
}
else
{
Console.WriteLine("Jaune");
Console.WriteLine(data + "Kw/H");
System.Threading.Thread.Sleep(1000);
}
// Fin Vérification
}
}
}
private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port;
string data = string.Empty;
port = (SerialPort)sender;
data = port.ReadExisting();
int Consommer = int.Parse(data);
}
}
항상 작업중인 코드 스 니펫을 게시하십시오. http://stackoverflow.com/help/how-to-ask – matt
프랑스에서 유감스럽게 생각합니다. – Mazeo
나에게 잘 어울리 며, 특정 기기 이름이나 다른 기기를 검색해야 할 필요가있는 것처럼 보이지 않습니다. COM4. 그래, 그래서 kW 시간을 초과하면 빨간색으로 가고 그렇지 않으면 황색 (내 프랑스어는 그다지 좋지 않음). 정말 멋진 프로젝트가있는 것 같습니다. – Snoopy