RS232 Expert help needed 
Author Message
 RS232 Expert help needed

Hi all!

I am writing a C program at a SCO Unix system that implements the
following MS-DOS settings of a serial port (The program communicates
with a handheld portable directly connectied to COM2):

/*--------config RS232 (COM2)--------*/
#define RBR     0X2F8
#define HCON    0X2F9
#define MODR    0X2FB
#define MCR     0X2FC
#define LSR     0X2FD
#define CTS     0X2FE

outportb(MODR, 0x83);          /*  { Set the DLAB }            */
outportb(RBR, 0x30);           /*  { Bit rate is   }           */
outportb(HCON, 0);             /*  {    2400 bps }             */
outportb(MODR, 3);             /*  { 8 dta, 1 stp, no par }    */
outportb(HCON, 0);             /*     { No interrupts }        */
outportb(MCR, 3);              /*     { RTS and DTR on }       */

/*-------RECEIVE A BYTE-------*/
int rx_byte(void)
{
        int c, byte=255;
        double dly=3000000;
                c=inportb(LSR) & 0x01;
                while(c!=1)
                {
                        dly=dly-1;
                        if(dly==0)
                                {
                                return(456);
                                }
                        c=inportb(LSR) & 0x01;
                }

                byte=inportb(RBR);
        return(byte & 255);

Quote:
}

/*-------TRANSMIT A BYTE------*/
void tx_byte(int byte)
{
        int c;

        c=inportb(LSR) & 64;
        while (c == 0)
        {
                c=inportb(LSR) & 64;
        }
        outportb(RBR,byte);

Quote:
}

Could someone please help me on what tty settings implement these MS-DOS
settings ? I don't know what the DLAB, the MCR and LSR do, and I just
guess what to do with RBR, HCON, etc. So far, I have set up a tty at
noncanonical mode, ignored interrupts, breaks, s/w flow control, CR-NL
mapppings, parity, CSTOPB, and enabled the CLOCAL and CREAD flags. I can
succesfully send data to the handheld, but cannot receive, and my
deadline is in 2 days. In short, please help me, I am desperate.

Thanks, everyone




Sun, 09 Jul 2000 03:00:00 GMT  
 RS232 Expert help needed

[followups narrowed]

[please turn off HTML when posting]

 Katsianis> I am writing a C program at a SCO Unix system that
 Katsianis> implements the following MS-DOS settings of a serial port
 Katsianis> (The program communicates with a handheld portable
 Katsianis> directly connectied to COM2):
[...]

 Katsianis> Could someone please help me on what tty settings
 Katsianis> implement these MS-DOS settings ? I don't know what the
 Katsianis> DLAB, the MCR and LSR do, and I just guess what to do with
 Katsianis> RBR, HCON, etc.

Don't worry too much about what the hardware registers do. You have the
important info there: the baud rate, parity and framing.

 Katsianis> So far, I have set up a tty at noncanonical mode, ignored
 Katsianis> interrupts, breaks, s/w flow control, CR-NL mapppings,
 Katsianis> parity, CSTOPB, and enabled the CLOCAL and CREAD flags. I
 Katsianis> can succesfully send data to the handheld, but cannot
 Katsianis> receive, and my deadline is in 2 days. In short, please
 Katsianis> help me, I am desperate.

Did you set VMIN and VTIME, and if so, what did you set them to?
(If not, try setting VMIN to 1 and VTIME to either 0 or your desired
timeout in 10ths of a second.)

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>



Sun, 09 Jul 2000 03:00:00 GMT  
 RS232 Expert help needed

Andrew Gierth> Don't worry too much about what the hardware registers
do.
Andrew Gierth> You have the important info there: the baud rate, parity
and framing.
Andrew Gierth> [...]
Andrew Gierth> Did you set VMIN and VTIME, and if so, what did you set
them to?
Andrew Gierth> [...]

Andrew,

  Thanks for your assistance. I have VMIN set to 0 and VTIME to 10 (1
sec timeout)
I managed to make the program work and communicate over the COM2
(dev/tty2a in SCO). The program itself is an interface to a portable
handheld device for registering parking tickets. However, I am getting a
really peculiar behaviour. When run from a telnet session (the device is
connected on the SCO system COM2), and with extensive use of printf's,
the program works fine (uploads and downloads data). Eliminating the
printf's results in a program that does not work, and so does running
the program from the console (with or without the printf's). I haven't
seen anything like this before, and I can only guess that it has to do
with timing issues, since if I 'm not mistaken , the use of printf's
makes the next command in sequence to wait for I/O to complete (which
would take longer over a telnet session). That is my best idea so far,
and I would really appreciate it if someone could point me in the right
direction.


--
Thanks,
Vangelis



Sat, 15 Jul 2000 03:00:00 GMT  
 RS232 Expert help needed

Quote:

> Andrew Gierth> Don't worry too much about what the hardware registers
> do.
> Andrew Gierth> You have the important info there: the baud rate, parity
> and framing.
> Andrew Gierth> [...]
> Andrew Gierth> Did you set VMIN and VTIME, and if so, what did you set
> them to?
> Andrew Gierth> [...]

> Andrew,
> When run from a telnet session (the device is
> connected on the SCO system COM2), and with extensive use of printf's,
> the program works fine (uploads and downloads data). Eliminating the
> printf's results in a program that does not work, and so does running
> the program from the console (with or without the printf's). I haven't
> seen anything like this before, and I can only guess that it has to do
> with timing issues, since if I 'm not mistaken , the use of printf's
> makes the next command in sequence to wait for I/O to complete (which
> would take longer over a telnet session). That is my best idea so far,
> and I would really appreciate it if someone could point me in the right
> direction.

My experience with printf statements making a difference is memory
related (e.g. over stepping bounds). printf() statements change the
layout of your code and can mean the difference between a memory
related bug causing mysterious failures and going unnoticed. My
advice is to carefully examine your code.

Jeff S.{*filter*}son



Tue, 18 Jul 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help needed retrieving data with RS232

2. Newbie needs help: How can I access the RS232 under MFC

3. Compile Error=> Need help from expert

4. Needed help from Expert to slove my error

5. Inexplicable System call failure - HELP - expert needed

6. Inexplicable system call failure! HELP-Expert Needed

7. Recursive experts -- I need help!

8. Newbie Need Helps from you C expert !!!

9. Beginner needs expert help~pointers

10. Need expert help!

11. C Experts, i really need help here :)

12. Expert help needed: Heap problem

 

 
Powered by phpBB® Forum Software