ts-7000
[Top] [All Lists]

[ts-7000] troubleshooting COM2 code

To:
Subject: [ts-7000] troubleshooting COM2 code
From: "lerougegorge" <>
Date: Thu, 19 Jul 2007 22:01:18 -0000
I wrote the C program below to echo characters received on COM2 (19200 8N1) to the standard out, but I seem to be having the following problems:

1. It always drops the first character.
2. It only echoes about 15 - 20 characters (it varies).
3. It then outputs some random looking data (e.g. 0x1842C202) and then stops echoing.

I tested this by connecting via telnet and connecting COM2 to my computers' serial ports.  I tried this on both a windows machine with hyperterm and an Ubuntu machine with Minicom.  Anyone have any idea what is wrong?

#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
    printf("Echo program starting\n");
    
    //Open COM2
    int fd = open("/dev/ttyAM1", O_RDWR | O_NOCTTY | O_ND! ELAY);
    
    if(fd <= 0)
    {
        printf("Error, failed to open COM2\n");
        return 0;
    }
    
    //Set for COM2 19200 8N1, non-blocking reads
    struct termios options;
    tcgetattr(fd, &options);
 
    options.c_cflag     = CS8 | CLOCAL | CREAD;
    options.c_iflag     = IGNPAR;    
    options.c_oflag     = 0;
    options.c_lflag     = 0;
     options.c_cc[VTIME] = 0;
     options.c_cc[VMIN]  = 0;   

    cfsetispeed(&options, B19200);
    cfsetospeed(&options, B19200);
 &! nbsp;  
       tcflush(fd, TC! IFLUSH);
     tcsetattr(fd, TCSANOW, &options);
    
    //Loop indefinitely and echo
    while(1)
    {
        char c;
        if(read(fd, &c, 1) > 0)
            printf("received %c\n", c);
    }
}

__._,_.___


SPONSORED LINKS
Single board computer Hardware Computer running slow
Linux os Single board

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU