[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

read fra comport



Jeg har lavet et lille loop, hvori jeg læser min com port. Men det virke

til, at read hænger indtil der kommer noget i port bufferen. Kan det
være rigtigt ?? Jeg ville mene den bare skulle returner EOT, hvis ikke
der nogle data.

Her er hvordan jeg gør


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>

#include <string.h>

struct termios CommDCB;


int main()
{
char comPort[9];
int port;
char tekst[11] ;
ssize_t counter;

  strcpy (comPort, "/dev/cua2");

  while (1)
  {
    strcpy (tekst, "Hello World");

    if ((port = open (comPort, O_RDWR)) == -1)
      perror ("open error : ");


    CommDCB.c_iflag = 0;
    CommDCB.c_iflag |= INPCK;     //Enable parity checking
    CommDCB.c_iflag |= IXON;      //enable XON/XOFF flow control on
output
    CommDCB.c_iflag |= IXOFF;     //enable XON/XOFF flow control on
input
//  CommDCB.c_iflag |= IXANY;     //enable any char tp restart output

    CommDCB.c_oflag = 0;

    CommDCB.c_cflag = 0;
    CommDCB.c_cflag |= CS8;       // 8 bit bytesize
    CommDCB.c_cflag |= CREAD;     // enable receiver
    CommDCB.c_cflag |= PARENB;    // enable parity generation on output
and parity checking for input
  //CommDCB.c_cflag |= CLOCAL;    // ignore moden control lines

    CommDCB.c_lflag = 0;


    printf ("setospeed\n");
    if (cfsetospeed(&CommDCB, B9600) == -1)   // set output baudrate
      perror ("cfsetospeed error");

    printf ("setispeed\n");
    if (cfsetispeed(&CommDCB, B9600) == -1)   // set input baudrate
      perror ("cfsetispeed error");

    counter = 11;
    counter = write (port, tekst, counter);

    printf ("writed %d chars.\n%s\n", counter, tekst);

    strcpy (tekst, "           ");
    counter = 1;

//********* HER HÆNGER DEN ***************
    if ((counter = read (port, tekst, (size_t) counter)) == -1)
      perror ("read error");

    printf ("Antal byte modtaget : %d\n", counter);
    printf ("byte modtaget : %s\n", tekst);

    if (close(port) == -1)
      perror ("close error : ");
  }
}

Hvad gør jeg galt ??

mvh
Kasper




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *