Hi all, I've a FOX Board (Linux Embedded) with RS485 port, and a Power Counter (RS485 too) that work at 9600E1.
With a USB to RS485 cable and windows i can successfully communicate with the Counter, writing a simple c# application. The rs485 linux board work too (with others devices).
I can't read always correctly between the linux board and the counter, and i don't know why. I've analyzed with an oscilloscope, and the data sent is always correct.
Sometimes i read the correct string (/EMH5\@--DMZ-F0028T) and most of times i read something like this (-\*.)TJUI&LY8T).
I've tried different settings, none worked. Thanks
Here is the code:
int OpenRS485() { int status; struct rs485_ctrl ctrl485; char dev[] = "/dev/ttyS3";
// Apre la porta seriale fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0) { flog("ERRORE! Apertura della porta fallita!", -2); printf("ERRORE! Apertura della porta fallita (%s)!\n", dev); return -1; } else { fcntl(fd, F_SETFL, FASYNC); printf("Porta seriale aperta\n"); }
//Imposta la porta seriale nel funzionamento 485 ctrl485.rts_on_send = 0; ctrl485.rts_after_sent = 1; ctrl485.delay_rts_before_send = 0; ctrl485.enabled = 1; status = ioctl(fd, TIOCSERSETRS485, &ctrl485);
if (status) { flog("ERRORE! TIOCSERSETRS485 fallita - fotomonitor.c main", -3); printf("ERRORE! TIOCSERSETRS485 fallita (%d)\n", status); close(fd); return -1; } else printf("Porta seriale impostata in RS485\n\n");
tcgetattr(fd, &ti_prev); // Salva la vecchia configurazione tcgetattr(fd, &ti); // Legge la vecchia configurazione cfsetospeed(&ti, B9600); // Imposta la velocità di trasmissione cfsetispeed(&ti, B9600); // Imposta la velocità di ricezione cfmakeraw(&ti);
ti.c_cflag = (0|B9600|CREAD|CS7|PARENB|CLOCAL);
if (tcsetattr(fd, TCSAFLUSH, &ti) != 0) // Imposta la nuova configurazione
printf("Errore nelle impostazioni RS485\n");
return 0; }