ciao a tutti,
ho un problema nell'invio e nella ricezione dei dati tramite protocollo usb in ambiente linux (precisamente ubuntu) con un microcontrollore.
in pratica ho trovato e poi leggermente modificato questo codice in rete:
codice:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
int main()
{
int fd; /* File descriptor for the port */
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyUSB0 - ");
}
else
fcntl(fd, F_SETFL, 0);
struct termios options;
/*
* Get the current options for the port...
*/
tcgetattr(fd, &options);
/*
* Set the baud rates to 9600...
*/
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_oflag &= ~OPOST; //raw output
/*
* Enable the receiver and set local mode...
*/
options.c_cflag |= (CLOCAL | CREAD);
/*
* Set the new options for the port...
*/
tcsetattr(fd, TCSANOW, &options);
int n = write(fd, "f", 1);
if (n < 0)
fputs("write() of 1 byte failed!\n", stderr);
close(fd);
}
il problema è molto probabilmente nel codice perchè se gli invio dei caratteri da hyperterminal su windows funziona perfettamente (e riesco anche a leggere le cose che mi interessano dalla porta)...qualcuno ha qualche idea? grazie