RS-232 C++ Programming


 
Thread Tools Search this Thread
Top Forums Programming RS-232 C++ Programming
# 1  
Old 12-16-2007
RS-232 C++ Programming

First off, the target system is FreeBSD 6.x on an old AMD K6 333. I know C++ but I wouldn't consider myself a programmer. (Haven't written a line since college.)

Anyway, I want to write a program to allow me to pan and tilt a webcam or to simply send a signal from a serial port to a relay switch in a diagram I found.

I found a program written in C that is pretty close to what I'm wanting to do, but the only problem is it's using...

#include <asm/io.h>
#include <libio.h>

Here's a link to this program and diagram of switch.
http://axlebath.net/rccar.txt

These headers don't appear to be installed on my system. I'm assuming this program was written for a LINUX system.

MY QUESTION...
1. Any idea on how to do this using C++?
2. Knowing full well I need to know what I'm doing to accomplish this, is there a good reference guide, tutorial, and/or set of examples to help me understand termios programming; especially in respect of interfacing with a serial port?
3. Does anyone have any tips to point me into the right direction?

Thanks in advance for your help...
# 2  
Old 12-16-2007
Quote:
Originally Posted by Alpha_Harblo
2. Knowing full well I need to know what I'm doing to accomplish this, is there a good reference guide, tutorial, and/or set of examples to help me understand termios programming; especially in respect of interfacing with a serial port?
Drop any linux or assembly bits, you should not need them.

cfmakeraw() is useful API, makes sure you don't have a terminal discipline enabled on the port....

otherwise, just make sure you set the baud rate, characters bits, parity and stop, and set the file descriptor to blocking or nonblocking as per your whim.

Last edited by porter; 12-18-2007 at 04:05 PM..
# 3  
Old 12-18-2007
Lots of tips

I just finished re-writing a cctv utility that does the whole ptz thing. The first cut was a trivial C utility. I built a C++ architecture that does the same thing, but it does it reliably. It is also very extensible, maintainable, flexible, self documenting, supplemented with srs and design docs, and is specialized at three levels to provide a solid foundation.

So, the first thing that I did was to set up a couple libraries. The first one is just a grab bag of basic tools. The second, a set of parameterized classes that provide stream specializations. These not only can work on every platform (with necessary specializations), but can be adapted to different types of com devices. The third library set up an abstract architecture to facilitate stream interactions. The final utility is a specialization of the abstract architecture, and defines specifically how to interact with the target device.

So, all of the generic work is handled using generic stuff. All the specializations are handled in the user code.

-Jmt
# 4  
Old 12-21-2007
I am wanting to keep it fairly simple. I don't need any kind of GUI, at least at this point....you know, one step at a time.

At this point I'm still trying to figure out details how things in this subject work. I'm trying to figure out the "Hello World" stage, so to speak.

Is there some kind of reference that would be more helpful than man pages?
# 5  
Old 12-21-2007
Serial Programming Guide for POSIX Operating Systems - Michael R Sweet

http://www.lafn.org/~dave/linux/Seri...ming-HOWTO.txt

It's amazing what you can come up with in two minutes using google these days.
# 6  
Old 12-21-2007
I've been googling a lot in the past week. The big part of the problem is I not sure what exactly to look for and if I'm looking at anything relevant.

Thanks for the links; the HOWTO step by step explanation will be helpful and should allow me to learn things.

My only concern is they're directed to LINUX systems. How I understand it, as far as serial comm programming, there are some differences between LINUX and BSD systems.
# 7  
Old 12-22-2007
Great find!

mikes serial device resources look really good.

The way I look at it, the most important thing to consider is that the device may not do what you think it will. The utility needs to have a way of checking to see if it did what you asked it to do. It needs to be patient, the clock on your target device is not in sync with your cpu, so don't expect it to respond, just check, and patiently wait 'till it says it did what you asked it to do, then let your program continue on to the next command. If it never does what you asked it to do, request a heartbeat response, there might be a com problem, or the device may be busy or dead, when you get a response, you've got to be able to issue the command that failed again (and you might have to send re-init sequences before you can do that right).

It makes good sense to start with some libraries that already do approximately what you want to do, then refine, maintain and extend 'till it does exactly what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies

2. Programming

RS 232, CentOS 5.6, gcc 3.4.9

Hello! Can somebody help me with one problem. I write driver for I/o from COM port. That's the main code: #include <stdio.h> // standard input / output functions #include <string.h> // string function definitions #include <unistd.h> // UNIX standard function definitions #include <fcntl.h>... (0 Replies)
Discussion started by: alter_man
0 Replies

3. AIX

Console Setup for RS-232 port on 9131-52A

Hi, I have tried to setup the console on a Power5 9131-52A type IBM Server. On the back there are 2 RS-232 ports labeled T1 T2. I am going under the assuming that these are the serial ports (Normally the serial ports are S1 S0). When I finish assigning the console under smit, I get no response... (3 Replies)
Discussion started by: mrmurdock
3 Replies

4. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

5. HP-UX

XIO: fatal IO error 232 (Connection reset by peer) on X server "192.168.1.239:0.0"

Hi All... I'm newbie here..., i have problem when installing oracle9206, i use HPUX 11.11, i'm using Xmanager enterprise 2.1 for forwarding from server A to my laptop # export DISPLAY=192.168.1.239:0.0 # echo $DISPLAY output ==> 192.168.1.239:0.0 at the oracle directory, i execute ... (3 Replies)
Discussion started by: grimanda
3 Replies
Login or Register to Ask a Question