Thread: Serial communications problem.

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    9

    Serial communications problem.

    Hi,

    I am trying to read data from my SUN workstation's ttya port.
    I have,

    {
    int *fd;
    int n, i=0, j=0;
    char message[64, buffer[64], c;

    *fd = open("/dev/ttya", O_RDWR | O_NOCTTY | O_NDELAY);
    while(1)
    {
    if(n = read(fd, &c, 1) == 1)
    {
    buffer[i] = c;
    if((buffer[i] == '\r') || (buffer[i] == '\n'))
    {
    buffer[i] = '\0';
    memset(message, '\0', sizeof(message));
    for(j=0; j<i; j++)
    {
    message[j] = buffer[j];
    }

    printf("Buffer %s", buffer);
    i = 0;
    memset(buffer, '\0', sizeof(buffer));
    }
    else
    {
    i=i+1;
    continue;
    }
    }
    }


    Sometimes this code, fails to detect the \n or \r characters in the incoming stream. It fails to apprpriately detect them, and hence does not correctly give me the printf. It will sometimes combine two streams together, seperately detecting the \n or \r character in each of them.

    Basically my question, why would the serial driver sometimes fail to report or detect the \n, \r characters?

    Any help is greatly appreciated...

    Thanks!!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>int *fd;
    >>*fd = open("/dev/ttya", O_RDWR | O_NOCTTY | O_NDELAY);
    Where exactly is fd pointing to then? You can't (or rather, shouldn't) dereference a pointer you haven't initialised.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 05:56 PM
  3. Detect SCSI Hard Drive Serial Number
    By mercury529 in forum Windows Programming
    Replies: 3
    Last Post: 10-17-2006, 06:23 PM
  4. PC104 Serial Port Programming Problem
    By outerspace in forum C Programming
    Replies: 6
    Last Post: 11-09-2005, 07:07 PM
  5. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM