Oui,
voici mon c++ sur le Pico
#include <HardwareSerial.h>
#define LED LED_BUILTIN
#define SORTIE 18
byte buffer_recoi[2];
String texte = "c'est pas bon";
void setup() {
pinMode(SORTIE, OUTPUT);
pinMode(LED, OUTPUT);
_UART_USB_.begin(115200, SERIAL_8N1);
}
void loop()
{
if(SerialUSB.available())
{
SerialUSB.readBytes(buffer_recoi, 2);
if (buffer_recoi[0] == 97)
{
if (buffer_recoi[1] == 97)
{
digitalWrite(LED, HIGH);
digitalWrite(SORTIE, HIGH);
}
else if (buffer_recoi[1] == 122)
{
digitalWrite(LED, LOW);
digitalWrite(SORTIE, LOW);
}
}
SerialUSB.print(".");
SerialUSB.flush();
}
}
et voici le c# pour mon winform,
public SerialPort Pico = new SerialPort("COM5", 115200, Parity.None, 8, StopBits.One);
Mon programme bloque sur cette ligne : Pico.Write(pins[id].Allumer(), 0, 2);
Voici la classe dans lequel le programme va chercher le pins[i].allumer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace Testeur_RTE
{
internal class Pin
{
public byte[] trame = new byte[2]; //premier byte = id ; deuxième byte = fonction
public Button Bouton;
public Pin(byte id, Button bouton) //créer un pin avec un id défini
{
this.trame[0] = id;
this.Bouton = bouton;
}
public byte[] Allumer() //Envoyer 48 V sur la broche
{
trame[1] = 0x00;
return trame;
}
public byte[] Eteindre() //Envoyer 0V sur la broche
{
trame[1] = 0x01;
return trame;
}
public void Allumer_bouton()
{
Bouton.Location = new Point(Bouton.Left, Bouton.Top + 20);
Bouton.BackColor = Color.FromArgb(0, 116, 167);
}
public void Eteindre_bouton()
{
Bouton.Location = new Point(Bouton.Left, Bouton.Top - 20);
Bouton.BackColor = Color.FromArgb(0x00, 0xA6, 0xD9);
}
public byte Recup_ID(object sender) //Récupère l'id associé au bouton et au pin à partir du tabindex donné en sender
{
string sended;
char[] tab;
if (sender.ToString().ToCharArray().Length == 36)
{
sended = sender.ToString() + "0";
tab = sended.ToCharArray();
sended = tab[35].ToString();
}
else
{
sended = sender.ToString();
tab = sended.ToCharArray();
sended = tab[35] + tab[36].ToString();
}
return (Convert.ToByte(sended));
}
}
}
Je précise que dans le winform général, j’ai en effet fait un Serial.open()
Je reste à votre disposition pour plus de questions, merci de m’aider, cela fait 3 jours que je suis dessus