Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004

    *nix port programming in C

    this is what I need
    I need to be able to do simple port programming of my serial port I have a book that give me the basics for windows but its programs are not portable and I want to use *nix cause it give complete controll over the ports unlike XP. and co.
    any way any sites or books would be helpfull
    btw I did google for it but the thing either goes over my head or requires me to install a specific compiler and so I dont use them since I am trying to learn by removing that level of abstratction they limit what information I can get
    I have already done the basics of both serial and paralell and know a decent amount of it
    any help will be much appreciated
    thank you
    (ps: any inline asm code is acceptable for my requirements but could you please use ansi C ..? or is it not possible any way please elt me know)
    anything that doesn\'t kill you or your dreams only makes you stronger

  2. #2
    Senior Member
    Join Date
    Mar 2004

    Essentially, in Linux you can access the serial ports /dev/ttyS?
    (generic name) like a file, ie you get a filedescriptor with open(),
    you write to it with fputc(), you close it with close(). The difficulty
    lies in the proper choice of the settings and the communication
    Once, I wrote a controller program for a model railway, and
    the device specification were not complete - or I did not understand
    it properly - it took me ages to avoid the trains crashing all the time

    Since you know the basics, have a look at linux.com-HOWTO's[1,2].
    But I suggest you to analyse a serial port test program[3] step by step,
    which compiles perfectly using
    > gcc -o com com.c
    with a default installation of some linux distribution. Go through the
    source code, and try to understand what they are doing.
    You can use the program to send bit's to tty2, or you might try to
    "cp /dev/ttyS1 /dev/tty2" in a virtual console and check, whether
    the communication works (I have not tested this, but from what I
    remember...), or connect two PC's with a null-modem cable.

    Notabene: I am not going to discuss the level of abstraction in
    the approach I suggested here, nor do I comment on the "control"
    over the ports provided by various OS's. Depending on the amount
    of time you want to spend into your project, I would recommend
    to use the environment you are most familiar with.


    [1] http://www.linux.com/howtos/Serial-HOWTO.shtml#toc11
    [2] http://www.linux.com/howtos/Serial-P...TO/index.shtml
    [3] http://www.comptechdoc.org/os/linux/...pgcserial.html
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.