tcpserial.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 SCHUNK GmbH & Co. KG
00003  * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *   http://www.apache.org/licenses/LICENSE-2.0
00010 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 //======================================================================
00045 //======================================================================
00046 
00047 #ifndef TCP_SERIAL_H_
00048 #define TCP_SERIAL_H_
00049 
00050 //----------------------------------------------------------------------
00051 // System Includes - include with <>
00052 //----------------------------------------------------------------------
00053 
00054 #if SDH_USE_VCC
00055 # include <sys/timeb.h>
00056 # include <time.h>
00057 # include <winsock.h>
00058 #else
00059 # include <sys/time.h>
00060 #endif
00061 #include <string>
00062 
00063 //----------------------------------------------------------------------
00064 // Project Includes - include with ""
00065 //----------------------------------------------------------------------
00066 
00067 #include "sdhexception.h"
00068 #include "serialbase.h"
00069 #include "basisdef.h"
00070 
00071 #include "sdhlibrary_settings.h"
00072 
00073 //----------------------------------------------------------------------
00074 // Defines, enums, unions, structs,
00075 //----------------------------------------------------------------------
00076 
00077 NAMESPACE_SDH_START
00078 
00079 //----------------------------------------------------------------------
00080 // Global variables
00081 //----------------------------------------------------------------------
00082 
00083 
00084 //----------------------------------------------------------------------
00085 // Function and class member declarations
00086 //----------------------------------------------------------------------
00087 
00088 
00092 class VCC_EXPORT cTCPSerialException: public cSerialBaseException
00093 {
00094 public:
00095   cTCPSerialException(cMsg const & _msg)
00096     : cSerialBaseException("cTCPSerialException", _msg)
00097   {}
00098 };
00099 //======================================================================
00100 
00101 
00105 class VCC_EXPORT cTCPSerial : public cSerialBase
00106 {
00107 
00108 protected:
00109 
00110   std::string tcp_adr;
00111 
00113   int tcp_port;
00114 
00116 #if SDH_USE_VCC
00117   SOCKET fd;
00118 #else
00119   int    fd;
00120   static const int INVALID_SOCKET = -1;
00121 #endif
00122 private:
00124   struct  timeval timeout_timeval;
00126   long    timeout_us;
00127 
00128 public:
00129   static double const TIMEOUT_WAIT_FOR_EVER_S;
00130   static double const TIMEOUT_RETURN_IMMEDITELY_S;
00131   static long const   TIMEOUT_WAIT_FOR_EVER_US;
00132   static long const   TIMEOUT_RETURN_IMMEDITELY_US;
00133 
00143   cTCPSerial(char const* _tcp_adr, int _tcp_port, double _timeout)
00144   throw (cTCPSerialException*);
00145 
00149   void Open(void)
00150   throw (cTCPSerialException*);
00151 
00153   bool IsOpen(void)
00154   throw();
00155 
00157   void Close(void)
00158   throw (cTCPSerialException*);
00159 
00161 
00169   int write(char const *ptr, int len = 0)
00170   throw (cTCPSerialException*);
00171 
00180   ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)
00181   throw (cTCPSerialException*);
00182 
00184   void SetTimeout(double _timeout)
00185   throw (cSerialBaseException*);
00186 
00190   virtual tErrorCode GetErrorNumber()
00191   {
00192 #if SDH_USE_VCC
00193     return WSAGetLastError();
00194 #else
00195     return errno;
00196 #endif
00197   }
00198 };
00199 //======================================================================
00200 
00201 NAMESPACE_SDH_END
00202 
00203 #endif
00204 
00205 
00206 //======================================================================
00207 /*
00208   Here are some settings for the emacs/xemacs editor (and can be safely ignored):
00209   (e.g. to explicitely set C++ mode for *.h header files)
00210 
00211   Local Variables:
00212   mode:C++
00213   mode:ELSE
00214   End:
00215 */
00216 //======================================================================


schunk_sdh
Author(s): Mathias Luedtke , Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:21