Thread: Send image (.jpg) file over serial port

  1. #1
    Registered User
    Join Date
    Jun 2009

    Question Send image (.jpg) file over serial port

    We are trying to interface one of our devices with our machines by having the device send a file over the serial port. The code for the external device is written in C. However, we have not been able to successfully compile any of our code to do this. This is one of the code snippets we used to try to open the serial port and send data:
    #include <stdio.h>   /* Standard input/output definitions */
        #include <string.h>  /* String function definitions */
        #include <unistd.h>  /* UNIX standard function definitions */
        #include <fcntl.h>   /* File control definitions */
        #include <errno.h>   /* Error number definitions */
        #include <termios.h> /* POSIX terminal control definitions */
         * 'open_port()' - Open serial port 1.
         * Returns the file descriptor on success or -1 on error.
          int fd; /* File descriptor for the port */
          fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
          if (fd == -1)
    	* Could not open the port.
    	perror("open_port: Unable to open /dev/ttyS0 - ");
    	fcntl(fd, F_SETFL, 0);
          return (fd);
    Source: Serial Programming Guide for POSIX Operating Systems - Michael R Sweet

    However, when we try to compile this code, we get an error that O_NDELAY is an undeclared variable. We think it has something to do with termios.h, but we have not been able to fix this. We also tried using FileOutputStream.h (Source: fileoutputstream.c File Reference) but we got a file not found error. Can someone point us in the right direction here?


  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    This might help:

    Quote Originally Posted by GNU
    Macro: int O_NDELAY

    This is an obsolete name for O_NONBLOCK, provided for compatibility with BSD. It is not defined by the POSIX.1 standard.
    So try O_NONBLOCK instead...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well you could mention which actual OS/Compiler you're using.
    The code you posted won't work everywhere.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-27-2009, 12:46 PM
  2. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 12:28 AM
  5. send zip file via socket
    By WaterNut in forum C Programming
    Replies: 11
    Last Post: 05-24-2005, 11:49 AM

Tags for this Thread