TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: STEVE WESTCOT
from: CHRISTIAN ANDERSEN
date: 1997-04-18 09:10:00
subject: Serial I/O using C++ objects

Hello Steve.
15 Apr 97 13:45, Steve Westcot wrote to All:
 SW> I am wondering if there is a shareware/freeware serial I/O object type
 SW> perhaps derived from streambuf or ios?  Or is there a commercial one
 SW> out there?
Dont know...
 SW> I am interested in creating a door program using C++ objects and
 SW> wondered if I could get a serial i/o that was the same way.  So I
 SW> could code:
 SW> serout << "Hello World!";
 SW> And it would send it to the serial port that I had previously set up.
 SW> Are fossil drivers necessary?  Can someone tell me what they do in
 SW> serial communications?
You should use operator overloading, like in this example:
//////////////////////////// SERIAL PORT EXAMPLE - START
#include 
#include 
class CSerialObject
{
public:
    // Overloaded '<<' operator
    operator<<(char *s) {
        WriteStringToSerialPort(s);
        return 0;
    }
protected:
    // Dummy function
    void WriteStringToSerialPort(char *s) {
        printf(s);
    }
};
void main()
{
    CSerialObject serout;
    serout << "Hello Serialport!\n";
}
//////////////////////////// SERIAL PORT EXAMPLE - END
In this example, the function WriteStringToSerialPort(),
whould of course not just contain a printf statement,
but the real code to write to the serialport.
If you want to read something from the serial port, and
use it in a cout, you, basically, do the same thing, but
it is a bit more complicated.
If I have misunderstood, what you mean, and the thing you really
need, is to know how to write to the serial port, then say so.
 SW> Now for a different topic, multiple instances of the same
 SW> program...like a chat program, would the easiest way to transfer info
 SW> be a file sharing system?
When you're talking about a chat program I, take it, that you're want to run 
only one instance of each program on each machine, but on mutiple machines 
connected to each other in a LAN -  Unless, of cource, you want to chat with 
somebody using the same machine, and then sharing the keyboard :-).
If you're using DOS, I dont know what you can do, but in the windows 
environment, there a many different ways to do it: mailslots, named pipes, 
sockect and memory-mapped files.
If you tell me some details about what you want to do, Ill give you some 
advice.
Christian
--- GoldED 2.50 UNREG
---------------
* Origin: Men i aften skal det v‘re anderledes... (2:235/335.22)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.