Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tcdrain problem

19 views
Skip to first unread message

Giampaolo Bellini

unread,
Sep 19, 2000, 3:00:00 AM9/19/00
to

Hello....


I have a problem using a PC104 card (mitac MSC-6540A) with 4 serial
ports.
I set (by jumper) ttyS3 to work as a RS485 (38400 bps, n,8,1) and
control the TX/RX by the RTS signal.

the question is: how can I know when the last caracter is sent ?

I've tryed with the tcdrain functions but it's too slow and I lost the
response from the device I'm driving.

here is my subroutine:

int RS485_Send(char *buf, int n)
{

int br;
int bcount;
int iostatus; // Stato delle uscite di
controllo (RTS, CTS etc) del device seriale
unsigned int checksum; // checksum da trasmettere
unsigned char ch, scheck[5]; // carattere letto dal buffer,
checksum convertito in ESA
unsigned char frame[BUFFSIZETX];
unsigned char temps[BUFFSIZETX+20];

br=0;
checksum = 0;

frame[br++] = STX;

checksum+=STX;

for (bcount = 0; bcount<n; bcount++)
{

ch = buf[bcount];
checksum+=ch;

if (ch == ETX || ch == STX || ch == DLE)
{
frame[br++] = DLE;
frame[br++] = ch + 0x40;
checksum=checksum+DLE+0x40;
}
else
{
frame[br++] = ch;
}
}

frame[br++] = ETX;
checksum+=ETX;

sprintf(scheck, "%04X", checksum%65536);

frame[br++] = scheck[0];
frame[br++] = scheck[1];
frame[br++] = scheck[2];
frame[br++] = scheck[3];
frame[br] = 0x00;

n=br;
br=0;
bcount=0;

// Attenzione! Setto il numero di caratteri che il ricevitore
seriale deve trascurare in caso la 485 si
// autoriceve

if (AUTORECEIVE) AnnoyRX=n;

// Alzo la portante

ioctl(serialfd, TIOCMGET, &iostatus);
iostatus |= TIOCM_RTS;
ioctl(serialfd, TIOCMSET, &iostatus);

strcpy(temps, "RS485 TX: ");
memcpy(temps+10, frame, n);

DEBUG(D_TXF, DBGLev, temps, n+10);

while (bcount<n)
{
if ((br=write(serialfd, frame+bcount, n-bcount))>0)
{
bcount += br;
}
else
{
if (br<0)
{
bcount=-1;
break;
}
}
}

// Attendo la fine della trasmissione

// with this line, I can't see any responses from the device, if I
replace this with a usleep I see the responses only when the frame I
transmit is not too long (100 byte)
while (tcdrain(serialfd));
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^

// Abbasso la portante

ioctl(serialfd, TIOCMGET, &iostatus);
iostatus &= ~TIOCM_RTS;
ioctl(serialfd, TIOCMSET, &iostatus);

return(bcount);

}

73 de iw2lsi, Paolo


--
Posted from [212.110.6.101]
via Mailgate.ORG Server - http://www.Mailgate.ORG

0 new messages