SerialPortImplWin32.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2006-02-16 11:24:44 -0600 (Thu, 16 Feb 2006) $
00011  * Version:       $Revision: 18429 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_SERIAL_PORT_IMPL_WIN32_H_
00043 #define _VPR_SERIAL_PORT_IMPL_WIN32_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 
00047 #include <iostream>
00048 #include <stdio.h>
00049 #include <string>
00050 #include <vector>
00051 
00052 #include <vpr/IO/IOSys.h>
00053 #include <vpr/IO/Port/SerialTypes.h>
00054 #include <vpr/Util/ReturnStatus.h>
00055 #include <vpr/Util/Interval.h>
00056 #include <vpr/Util/Debug.h>
00057 
00058 
00059 namespace vpr
00060 {
00061 
00068 class VPR_CLASS_API SerialPortImplWin32
00069 {
00070 public:
00080    SerialPortImplWin32(const std::string& portName);
00081 
00087    ~SerialPortImplWin32();
00088 
00089    // ========================================================================
00090    // vpr::BlockIO basics.
00091    // ========================================================================
00092 
00098    const std::string& getName() const
00099    {
00100       return mName;
00101    }
00102 
00111    void setOpenReadOnly()
00112    {
00113       mOpenFlag = GENERIC_READ;
00114    }
00115 
00124    void setOpenWriteOnly()
00125    {
00126       mOpenFlag = GENERIC_WRITE;
00127    }
00128 
00137    void setOpenReadWrite()
00138    {
00139       mOpenFlag = GENERIC_READ | GENERIC_WRITE;
00140    }
00141 
00155    vpr::ReturnStatus open();
00156 
00169    vpr::ReturnStatus close();
00170 
00181    vpr::ReturnStatus setBlocking(bool flag);
00182 
00191    bool isBlocking() const
00192    {
00193       return ! (mBlocking & FILE_FLAG_OVERLAPPED);
00194    }
00195 
00199    vpr::IOSys::Handle getHandle() const
00200    {
00201 #ifdef VPR_USE_NSPR
00202       vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
00203          << "ERROR: Cannot get handle for Win32 file descriptor with NSPR!\n";
00204       return vpr::IOSys::NullHandle;
00205 #else
00206       return mHandle;
00207 #endif
00208    }
00209 
00220    bool isReadOnly() const
00221    {
00222       return GENERIC_READ == mOpenFlag;
00223    }
00224 
00235    bool isWriteOnly() const
00236    {
00237       return GENERIC_WRITE == mOpenFlag;
00238    }
00239 
00250    bool isReadWrite() const
00251    {
00252       return(GENERIC_READ | GENERIC_WRITE) == mOpenFlag;
00253    }
00254 
00255    // ========================================================================
00256    // VPR serial port interface implementation.
00257    // ========================================================================
00258 
00268    vpr::SerialTypes::UpdateActionOption getUpdateAction() const;
00269 
00279    void setUpdateAction(vpr::SerialTypes::UpdateActionOption action);
00280 
00293    vpr::ReturnStatus clearAll();
00294 
00308    vpr::ReturnStatus getMinInputSize(vpr::Uint16& size) const;
00309 
00323    vpr::ReturnStatus setMinInputSize(const vpr::Uint8 size);
00324 
00339    vpr::ReturnStatus getTimeout(vpr::Uint8& timeout) const;
00340 
00354    vpr::ReturnStatus setTimeout(const vpr::Uint8 timeout);
00355 
00370    vpr::ReturnStatus getCharacterSize(vpr::SerialTypes::CharacterSizeOption& size) const;
00371 
00385    vpr::ReturnStatus setCharacterSize(const vpr::SerialTypes::CharacterSizeOption bpb);
00386 
00396    bool getReadState() const
00397    {
00398       return true;
00399    }
00400 
00410    vpr::ReturnStatus setRead(bool flag)
00411    {
00412       return vpr::ReturnStatus();
00413    }
00414 
00426    bool getLocalAttachState() const;
00427 
00437    vpr::ReturnStatus setLocalAttach(bool flag);
00438 
00448    bool getBreakByteIgnoreState() const;
00449 
00459    vpr::ReturnStatus setBreakByteIgnore(bool flag);
00460 
00474    vpr::ReturnStatus getStopBits(vpr::Uint8& numBits) const;
00475 
00488    vpr::ReturnStatus setStopBits(const vpr::Uint8 numBits);
00489 
00504    bool getCanonicalState() const;
00505 
00518    vpr::ReturnStatus setCanonicalInput(bool flag);
00519 
00529    bool getBadByteIgnoreState() const;
00530 
00541    vpr::ReturnStatus setBadByteIgnore(bool flag);
00542 
00551    bool getInputParityCheckState() const;
00552 
00562    vpr::ReturnStatus setInputParityCheck(bool flag);
00563 
00574    bool getBitStripState() const;
00575 
00585    vpr::ReturnStatus setBitStripping(bool flag);
00586 
00602    bool getStartStopInputState() const;
00603 
00616    vpr::ReturnStatus setStartStopInput(bool flag);
00617 
00631    bool getStartStopOutputState() const;
00632 
00645    vpr::ReturnStatus setStartStopOutput(bool flag);
00646 
00660    bool getParityGenerationState() const;
00661 
00672    vpr::ReturnStatus setParityGeneration(bool flag);
00673 
00682    bool getParityErrorMarkingState() const;
00683 
00700    vpr::ReturnStatus setParityErrorMarking(bool flag);
00701 
00711    SerialTypes::ParityType getParity() const;
00712 
00722    vpr::ReturnStatus setParity(const SerialTypes::ParityType& type);
00723 
00737    vpr::ReturnStatus getInputBaudRate(vpr::Uint32& rate) const;
00738 
00750    vpr::ReturnStatus setInputBaudRate(const vpr::Uint32& rate);
00751 
00765    vpr::ReturnStatus getOutputBaudRate(vpr::Uint32& rate) const;
00766 
00778    vpr::ReturnStatus setOutputBaudRate(const vpr::Uint32& rate);
00779 
00789    vpr::ReturnStatus drainOutput();
00790 
00806    vpr::ReturnStatus controlFlow(vpr::SerialTypes::FlowActionOption opt);
00807 
00818    bool getHardwareFlowControlState() const;
00819 
00831    vpr::ReturnStatus setHardwareFlowControl(bool flag);
00832 
00848    vpr::ReturnStatus flushQueue(vpr::SerialTypes::FlushQueueOption queue);
00849 
00866    vpr::ReturnStatus sendBreak(const vpr::Int32 duration);
00867 
00874    int getCarrierDetect() const
00875    {
00876       return -1;
00877    }
00878 
00885    int getDataSetReady() const
00886    {
00887       return -1;
00888    }
00889 
00896    int getClearToSend() const
00897    {
00898       return -1;
00899    }
00900 
00907    int getRingIndicator() const
00908    {
00909       return -1;
00910    }
00911 
00913    vpr::ReturnStatus setDataTerminalReady(bool val);
00914 
00916    vpr::ReturnStatus setRequestToSend(bool val);
00917 
00944    vpr::ReturnStatus read_i(void* buffer, const vpr::Uint32 length,
00945                             vpr::Uint32& bytesRead,
00946                             const vpr::Interval timeout = vpr::Interval::NoTimeout);
00947 
00974    vpr::ReturnStatus readn_i(void* buffer, const vpr::Uint32 length,
00975                              vpr::Uint32& bytesRead,
00976                              const vpr::Interval timeout = vpr::Interval::NoTimeout);
00977 
01003    vpr::ReturnStatus write_i(const void* buffer, const vpr::Uint32 length,
01004                              vpr::Uint32& bytesWritten,
01005                              const vpr::Interval timeout = vpr::Interval::NoTimeout);
01006 
01007 protected:
01008    HANDLE mHandle;     
01009    DWORD mOpenFlag;    
01010    std::string mName;  
01011    bool mOpen;
01012    DWORD mBlocking;    
01013    bool mParityMark;   
01014    vpr::Uint8 mCurrentTimeout;
01015 };
01016 
01017 } // End of vpr namespace
01018 
01019 
01020 #endif  /* _VPR_SERIAL_PORT_IMPL_WIN32_H_ */

Generated on Thu Jan 4 10:52:10 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1