Skip to content
Extraits de code Groupes Projets
Valider fa4c74fd rédigé par Diego de Bernard de Fauconval's avatar Diego de Bernard de Fauconval
Parcourir les fichiers

uart ok

parent 38719b9c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -5,6 +5,7 @@
#include <wiringSerial.h>
#include <wiringPi.h>
#include <conio.h>
#include <iostream>
using namespace std;
......@@ -15,6 +16,9 @@ const char TURN_OFF[] = "Turn Led Off";
int main(int argc, char const *argv[])
{
int fd = serialOpen("/dev/ttyS0", 9600);
char buffer[26];
int i = 0;
if (fd == -1 || wiringPiSetup() == -1) {
printf("UART PAS OK\n");
......@@ -22,34 +26,24 @@ int main(int argc, char const *argv[])
}
serialPrintf(fd, TURN_ON);
delay(1000);
int response;
while (true) {
if (serialDataAvail(fd)) {
response = serialGetchar(fd);
break;
}
}
cout << response << endl;
printf("%c\n", response);
while (serialDataAvail(fd) > -1) {
buffer[i++] = serialGetchar(fd);
if (i == 25) break;
}
buffer[i] = '\0';
printf("%s\n", buffer);
delay(2000);
serialPrintf(fd, TURN_OFF);
while (serialDataAvail(fd) != 26) { }
delay(200);
while (true) {
if (serialDataAvail(fd) > 0) {
cout << serialDataAvail(fd) << endl;
for (int i = 0; i < serialDataAvail(fd); i++)
{
response = serialGetchar(fd);
}
break;
}
for (i = 0; i < 26; i++)
{
buffer[i] = serialGetchar(fd);
}
cout << response << endl;
cout << buffer << endl;
serialClose(fd);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter