ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I just want to write a little piece of software in C to communicate with a "special" device over serial Port. Will I have to use fopen() or are there any better ways to realize this? I want to write and read to/from the serial device. Last but not least a second question: How can I distribute parts of my Code in several files and compile them that I get one Binary? I'm currently writing functions into an header file, is this the right way?
In Linux, devices (like serial ports), are abstracted as files. To use them, you use the same paradigm as used for accessing files: open(), read() write(), close(), etc. For serial ports, you also use the termios interface to set parameters such as bit rate, word size, parity, and especially terminal oriented processing performed by the device driver, such as end-of-line processing.
For more good information on serial port programming, and useful sample code: Serial HOWTO Serial Programming HOWTO Serial Programming Guide for POSIX Operating Systems
As a general rule, you can compile individual source files to object code, and then link them into a single runtime binary executable.
gcc can perfom the linkage phase, as well. There are many many options that can be applied, many of which are normally required, such as supplying directives to allow the compiler and linker to locate header files and libraries. See the gcc man page for a start.
Your use of English puts many native English writers to shame. No apologies required.
In Linux, devices (like serial ports), are abstracted as files. To use them, you use the same paradigm as used for accessing files: open(), read() write(), close(), etc. For serial ports, you also use the termios interface to set parameters such as bit rate, word size, parity, and especially terminal oriented processing performed by the device driver, such as end-of-line processing.
For more good information on serial port programming, and useful sample code: Serial HOWTO Serial Programming HOWTO Serial Programming Guide for POSIX Operating Systems
As a general rule, you can compile individual source files to object code, and then link them into a single runtime binary executable.
gcc can perfom the linkage phase, as well. There are many many options that can be applied, many of which are normally required, such as supplying directives to allow the compiler and linker to locate header files and libraries. See the gcc man page for a start.
Your use of English puts many native English writers to shame. No apologies required.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.