Salve a tutti.
Devo mandare un comando ad un controller collegato via seriale al computer (tramite adattatore usb). So che il controller è collegato e reagisce al comando perché usando una serial port terminal application funziona.
Sto programmando in Xcode su OS.
Il codice è il seguente
codice:
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
using namespace std;
int main () {
int fd;
fd = open("/dev/tty.usbserial-00001004", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{perror("open_port: Unable to open /dev/tty.usbserial-00001004 - ");}
else
{
fcntl(fd, F_SETFL, 0);
char data[]="comando da inserire";
write(fd, data, strlen(data));
perror( "--");
}
close(fd);
return (fd);
}
Non ho mai fatto prgrammazione seriale, quindi scusatemi se il codice fa schifo.
Grazie a tutti per le risposte!