Re: [crisos] Set serial port RS485

[ Thread Index | Date Index | More lists.tuxfamily.org/crisos Archives ]


Thanks Jan, i forgot it!


Jan Kardell ha scritto:


2009/2/20 Andrea Russi <andrearussi@xxxxxxxxx>
Hi,
I want to set the serial port (RS485) in this way: 1 start, 7 bit, 1 parity (even), 1 stop
With the code below i read corrupted data (some negative value of byte, impossible in 7 bit trasnfer), i don't understand why...
Can someone help me?
Thanks,
Andrea Russi

It's a bit field, you have to clear unwanted bits. See below.


int status;
struct rs485_ctrl ctrl485;
char dev[] = "/dev/ttyS3";
int baudrate = B9600;

// Apre la porta seriale
fd = open(dev, O_RDWR | O_NONBLOCK);
if (fd < 0) return -1;

// 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) return -1;

tcgetattr(fd, &ti);          // Legge la vecchia configurazione
cfsetospeed(&ti, baudrate);   // Imposta la velocità di trasmissione
cfsetispeed(&ti, baudrate);   // Imposta la velocità di ricezione
//cfmakeraw(&ti); (non so se cambia qualcosa...)
 
 ti.c_flag &= ~CSIZE;
ti.c_cflag |= CS7;
ti.c_cflag |= PARENB;
ti.c_cflag &= ~PARODD;
ti.c_cflag &= ~CSTOPB;

if (tcsetattr(fd, TCSANOW, &ti) != 0) return -1;


//Jan


begin:vcard
fn:Andrea Russi
n:Russi;Andrea
org:;Ingegneria dell'Automazione
adr:;;;Roma;Roma;;Italia
email;internet:andrearussi@xxxxxxxxx
title:Dottore
x-mozilla-html:TRUE
version:2.1
end:vcard



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/