www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/07/19/08:45:43

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Robbo" <przykre AT ale DOT nie DOT mam>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: RS232 transmission sometimes fail on AM2
Date: Thu, 19 Jul 2007 14:30:54 +0200
Organization: tp.internet - http://www.tpi.pl/
Lines: 140
Message-ID: <f7nljm$1u8$1@atlantis.news.tpi.pl>
References: <f7lfo2$bql$1 AT atlantis DOT news DOT tpi DOT pl> <nIGdnfixh_KlmwLbnZ2dnUVZ_t63nZ2d AT comcast DOT com>
NNTP-Posting-Host: doo217.neoplus.adsl.tpnet.pl
X-Trace: atlantis.news.tpi.pl 1184848311 1992 83.24.122.217 (19 Jul 2007 12:31:51 GMT)
X-Complaints-To: usenet AT tpi DOT pl
NNTP-Posting-Date: Thu, 19 Jul 2007 12:31:51 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
X-Antivirus: avast! (VPS 000757-4, 2007-07-18), Outbound message
X-Antivirus-Status: Clean
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

> > I use Free DOS.
>
> I have no idea about anything specific to any sort of DOS. However, serial
> communication in DOS apps *running under Windows* is known to be
unreliable.
> Because of that many years ago I had to change the protocol to account for
> lost or corrupt data packets.

First of all, thank you all for answers.

I don't use any dos box under Windows. I use pure DOS (but it is Free DOS,
not MS DOS).

> > One more thing: I installed special 2xRS232+1xLPT
> > expansion card in the PC and connected the electronic
> > device with RS232 to it. I found that problems with
> > loosing sent commands are more frequently than
> > when I connected RS232 cable directly to a main board.
>
> Btw, do you use BIOS to do the serial I/O or something else? The reason
for
> the question is that BIOS serial I/O is rather limited and might even be
> buggy and I don't remember any decent terminal application using it. At
the
> same time, if it's all your code, not the BIOS'es, there might be some bug
> just as well.

I don't use BIOS's serial procedures. I write and read directly to/from
ports.
Below, there are my serial procedures. I'll be glade if you could find a bit
of time
to review them and check they are correct. Thanks in advance.
I don't use interrupts.
I use presented functions to send and receive short (2 characters long,
sometimes
7 characters long) commands with '\0' at the end of each.


enum {
    RECVBUF_MAX = 32,                    /* max. size of receiving buffer
*/
    RECVBUF_USER_MAX = RECVBUF_MAX + 2,
};

unsigned int COM = 0x3f8;                /* COM do interfejsu */
unsigned long uartSpeed = 57600;         /* szybkosc transmisji */

/* initUART: initialization
 */
void initUART(unsigned int com)
{
    outportb(com + 1, 0);                        /* interrupts off */
    outportb(com + 3, 0x80 | inportb(com + 3));  /* UART programming mode */
    outportb(com, (115200 / uartSpeed) & 0xff);  /* 57600 bps */
    outportb(com + 1, (115200 / uartSpeed) >> 8);
    outportb(com + 3, 0x03);                     /* 8-bit, no parity */
    outportb(com + 3, 0x7f & inportb(com + 3));
    outportb(com + 2, 0xc7 | inportb(com + 2));  /* enable FIFO FCR */
    outportb(com + 4, 0x0);
}


char recvBuf[RECVBUF_USER_MAX] = "\0";
char *recvBufPtr = recvBuf;

/* recvTxt: check if there is data in receiving buffer and if so, copy them
to "s"
 */
int recvTxt(char *s)
{
    int p;
    unsigned char c;
    char tt[32];

    /* receiving data which eventually was sent to us */
    while ((inportb(COM + 5)) & 0x01) {
        c = inportb(COM);

        if (recvBufPtr - recvBuf < RECVBUF_MAX)
            *recvBufPtr++ = c;
    }

    /* if buffer is empty, return 0 */
    if ((recvBufPtr == recvBuf) || (*(recvBufPtr - 1) != '\0'))
        return 0;

    strncpy(s, recvBuf, p = (recvBufPtr - recvBuf));
    s[p] = '\0';

    if (debug == 1) {
        char t[128];

        sprintf(t, "recv.: \"%s\"", s);
        newState(t);
    }

    recvBufPtr = recvBuf;

    return p;
}


/* sendTxt: sends text via UART
 */
void sendTxt(const char *s)
{
    char flagTrans = 0;

    if (debug == 1) {
        char t[128];

        sprintf(t, "sent: \"%s\"", s);
        newState(t);
    }

    delay(50);

    /* waiting for completion of sending previously sent chain of characters
*/
    while (!(inportb(COM + 5) & 0x20))
        ;

    if ((s == NULL) || (s[0] == '\0'))
        return;

    /* sending */
    while (flagTrans == 0) {

        if (*s == '\0')
            flagTrans = 1;

        /* waiting for completion of sending of previous character */
        while (!(inportb(COM + 5) & 0x20))
            ;

        outportb(COM, (unsigned char)*s++);
    }
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019