00001
00012
00013
00014 #ifndef CANSERIAL_PEAK_H_
00015 #define CANSERIAL_PEAK_H_
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "sdhexception.h"
00027 #include "serialbase.h"
00028 #include "basisdef.h"
00029 #include "sdhlibrary_settings.h"
00030
00031 #if defined( OSNAME_LINUX )
00032 # include <libpcan.h>
00033
00034 # define PCAN_HANDLE HANDLE
00035
00036 #elif defined( OSNAME_CYGWIN )
00037
00038
00039 # define NOMINMAX
00040 # include <windows.h>
00041 # include <Pcan_usb.h>
00042
00043 typedef void* PCAN_HANDLE;
00044
00045 #elif SDH_USE_VCC
00046 # include <windows.h>
00047 # include <Pcan_usb.h>
00048
00049 typedef void* PCAN_HANDLE;
00050
00051 #else
00052 # error "FIXME: support for PEAK CAN devices in other systems than linux/cygwin is not provided yet!"
00053
00054 #endif
00055 #include "sdhlibrary_settings.h"
00056
00057
00058
00059
00060
00061
00062 NAMESPACE_SDH_START
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00080 class cCANSerial_PEAKException: public cSerialBaseException
00081 {
00082 public:
00083 cCANSerial_PEAKException( cMsg const & _msg )
00084 : cSerialBaseException( "cCANSerial_PEAKException", _msg )
00085 {}
00086 };
00087
00088
00089
00093 class cCANSerial_PEAK : public cSerialBase
00094 {
00095
00096 protected:
00097
00099 unsigned long baudrate;
00100
00102 DWORD id_read;
00103
00105 DWORD id_write;
00106
00108 PCAN_HANDLE handle;
00109
00111 WORD BaudrateToBaudrateCode( unsigned long baudrate )
00112 throw (cCANSerial_PEAKException*);
00113
00114 char m_device[64];
00115
00116 private:
00117
00118 #if defined( OSNAME_LINUX )
00119 int timeout_us;
00120 #else
00121
00122 #endif
00123
00130 #if defined( OSNAME_LINUX )
00131 TPCANRdMsg m_cmsg;
00132 # define M_CMSG_MSG() m_cmsg.Msg
00133 #else
00134 TPCANMsg m_cmsg;
00135 # define M_CMSG_MSG() m_cmsg
00136 #endif
00137
00138 int m_cmsg_next;
00139
00140 public:
00151 cCANSerial_PEAK( unsigned long _baudrate, double _timeout, Int32 _id_read, Int32 _id_write, const char *device="/dev/pcanusb0" )
00152 throw (cCANSerial_PEAKException*);
00153
00163 cCANSerial_PEAK( PCAN_HANDLE _handle, double _timeout, Int32 _id_read, Int32 _id_write )
00164 throw (cCANSerial_PEAKException*);
00165
00173 PCAN_HANDLE GetHandle()
00174 {
00175 return handle;
00176 }
00177
00181 void Open( void )
00182 throw (cCANSerial_PEAKException*);
00183
00185 bool IsOpen( void )
00186 throw();
00187
00189 void Close( void )
00190 throw (cCANSerial_PEAKException*);
00191
00193
00201 int write( char const *ptr, int len=0 )
00202 throw (cCANSerial_PEAKException*);
00203
00212 ssize_t Read( void *data, ssize_t size, long timeout_us, bool return_on_less_data )
00213 throw (cCANSerial_PEAKException*);
00214
00216 void SetTimeout( double _timeout )
00217 throw (cSerialBaseException*);
00218 };
00219
00220
00221 NAMESPACE_SDH_END
00222
00223 #endif
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236