C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 06-30-2009, 06:12 AM   #1
Registered User
 
Join Date: Jun 2009
Posts: 1
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:
Code:
#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
    open_port(void)
    {
      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 - ");
      }
      else
	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?

Thanks.
aSpareName is offline   Reply With Quote
Old 06-30-2009, 06:50 AM   #2
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,941
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...
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Old 06-30-2009, 09:35 AM   #3
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
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.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Reply

Tags
communication, file transfer, serial port

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file won't close despite calling the function TiffClose(image) caggles C Programming 1 05-27-2009 12:46 PM
FTP program jakemott Linux Programming 14 10-06-2008 01:58 PM
help with text input Alphawaves C Programming 8 04-08-2007 04:54 PM
Reading and writing to a serial port SwarfEye C Programming 2 08-18-2006 12:28 AM
send zip file via socket WaterNut C Programming 11 05-24-2005 11:49 AM


All times are GMT -6. The time now is 04:27 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22