Thread: program using serial port to carry out a dialogue between two computers

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    1

    program using serial port to carry out a dialogue between two computers

    Hello all

    I am the new member and I just learn C programming. So, is there any body can help me writing C program in Ubuntu.

    Here is description.

    Write programs using the serial port to carry out a dialogue between two computers 1. the computers alternate in sending data 2. exit with ctrlC
    Thanks
    Attached Files Attached Files

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    You will never get any help, if you’re after for someone to write a code for you. You need be smart in asking question, instead of just dumping a bunch of source files. Ask us question which are more specific in nature, such as why the particular statement doesn’t work as intended or of anything of that nature; instead of why this doesn’t work.

    Now what exactly are you having problems with that code?

    The code you have attached should work on Ubuntu, why do you it doesn’t?

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Carry on reading the tutorial you copy/pasted the code from -> Serial Programming Guide for POSIX Operating Systems

    Though it would be useful if you learnt some programming skills along the way.
    open_port() returned an int (file descriptor), so use it.

    Code:
    int main ( ) {
      int fd = open_port();
      if ( fd != -1 ) {
          int res;
          char buf[256];
    
          res = read(fd,buf,255);
          printf("res=%d\n",res);
          if ( res > 0 ) {
                buf[res]=0;             /* set end of string, so we can printf */
                printf(":%s:%d\n", buf, res);
          }
      }
    }
    Don't just dump all the functionality into the first bit of code you find.
    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. triggering another program to run using serial port
    By infineonintern in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2009, 05:16 AM
  2. Using the serial (COM) Port
    By Bladactania in forum C Programming
    Replies: 3
    Last Post: 03-09-2009, 12:50 PM
  3. Serial Port/Quiz Program
    By quizkiwi in forum Networking/Device Communication
    Replies: 3
    Last Post: 10-25-2005, 07:47 PM
  4. Input via the serial port for a C program
    By Anthony in forum C++ Programming
    Replies: 2
    Last Post: 07-11-2005, 02:19 PM
  5. my serial port data reading program isn't working
    By gnychis in forum C Programming
    Replies: 5
    Last Post: 06-02-2005, 08:40 AM