[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem_receaving_data_via_serial_port



Hi all!
yep, the topic really says it all. I have written a small test program in C
to send a receive data through the serial port (below). It works in the
devboard-computer direction, but not at the reversed direction, then it
stops at the read-instruction. I have checked that I really have an output
signal from the computer with an oscilloscope, so it must be the devboard
thats failing. Im really greatful if anyone can help me with this!

C-prog (the read program is very similar)

// TEST PROGRAM TO SEND DATA VIA COM1
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <fcntl.h>
//#include <termios.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>


void main(void)
{
  printf("sending...\n");
  const int message_s = 8;
  FILE *f;
  FILE *fd;
  unsigned char data[message_s];
  int j;
  
  data[0]=10;
  data[1]=1;
  data[2]=1;
  data[3]=1;
  data[4]=1;
  data[5]=10;
  data[6]=1;
  data[7]=1;
  
  fd = fopen("/dev/ttyS0", "wb");
  if (fd==NULL) {
    printf("Cant open %s\n","/dev/ttyS0");
    exit(0);
  }
  
  fwrite(data, 1, message_s, fd);         
  
  //fdatasync(f);
  //fclose(f);
  
}

regards
Petter