![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Serial port I/O object * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************/ 00022 #ifndef FXSERIALPORT_H 00023 #define FXSERIALPORT_H 00024 00025 #ifndef FXIOHANDLE_H 00026 #include "FXIOHandle.h" 00027 #endif 00028 namespace FXEX { 00029 00030 /** 00031 * Serial port I/O object 00032 * 00033 * Port defaults: 00034 * - baud rate: 9600 00035 * - data bits: 8 00036 * - stop bits: 1 00037 * - parity: none 00038 * 00039 * Note: uses zero-based numbering for serial port device 00040 * eg: COM1 / ttyS0 == serial port zero (the first serial port) 00041 */ 00042 class FXAPI FXSerialPort : public FXIOHandle { 00043 FXDECLARE(FXSerialPort) 00044 00045 public: 00046 enum { ParityNone=0, ParityEven, ParityOdd }; 00047 00048 protected: 00049 FXint portNumber; // physical device number 00050 FXint speed; // serial port speed 00051 FXint databits; // number of data bits 00052 FXint stopbits; // number of stop bits 00053 FXint parity; // port parity 00054 00055 protected: 00056 FXSerialPort(){} 00057 00058 /// helper; setup port parameters, for the current connection 00059 FXbool setPortParameters(); 00060 00061 /// instantiate this class 00062 virtual FXSerialPort* newInstance(FXInputHandle h); 00063 00064 public: 00065 /// create an interface to the serial port 00066 FXSerialPort(FXApp* a,FXint no,FXObject *tgt=NULL,FXSelector sel=0); 00067 00068 /// Use an already open serial port handle 00069 FXSerialPort(FXInputHandle port,FXApp *a,FXObject *tgt=NULL,FXSelector sel=0); 00070 00071 /// create resources 00072 void create(); 00073 00074 /// get the port number 00075 FXint getPortNumber() { return portNumber; } 00076 00077 /// set the device - can only be set while device not open, fails silently otherwise 00078 void setPortNumber(FXint no); 00079 00080 /// get the port speed 00081 FXint getSpeed() { return speed; } 00082 00083 /// set the port speed 00084 void setSpeed(FXint sp); 00085 00086 /// get the number of data bits 00087 FXint getDataBits() { return databits; } 00088 00089 /// set the number of data bits 00090 void setDataBits(FXint db); 00091 00092 /// get the number of stop bits 00093 FXint getStopBits() { return stopbits; } 00094 00095 /// set the number of stop bits 00096 void setStopBits(FXint sb); 00097 00098 /// get the parity 00099 FXint getParity() { return parity; } 00100 00101 /// set the parity 00102 void setParity(FXint p); 00103 00104 /// open the device 00105 virtual FXbool open(); 00106 00107 /// duplicate this file handle 00108 FXSerialPort* duplicate(FXInputHandle newHandle=INVALID_HANDLE); 00109 00110 /// save resources 00111 virtual void save(FXStream &store) const; 00112 00113 /// load resources 00114 virtual void load(FXStream &store); 00115 00116 /// dtor 00117 virtual ~FXSerialPort(); 00118 }; 00119 00120 } // namespace FXEX 00121 #endif // FXSERIALPORT_H