Go to the documentation of this file.00001 #ifndef OF_SERIAL_H
00002 #define OF_SERIAL_H
00003
00004 #include "ofConstants.h"
00005
00006 #if defined( TARGET_OSX ) || defined( TARGET_LINUX )
00007 #include <termios.h>
00008 #include <sys/ioctl.h>
00009 #include <getopt.h>
00010 #include <dirent.h>
00011 #else
00012 #include <winbase.h>
00013 #include <tchar.h>
00014 #include <iostream>
00015 #include <string.h>
00016 #include <setupapi.h>
00017 #include <regstr.h>
00018 #define MAX_SERIAL_PORTS 256
00019 #include <winioctl.h>
00020 #ifdef __MINGW32__
00021 #define INITGUID
00022 #include <initguid.h>
00023 #endif
00024 #endif
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <fcntl.h>
00030 #include <errno.h>
00031 #include <ctype.h>
00032
00033
00034
00035
00036
00037 class ofSerial{
00038
00039 public:
00040 ofSerial();
00041 virtual ~ofSerial();
00042
00043 void enumerateDevices();
00044
00045 void close();
00046 bool setup();
00047 bool setup(string portName, int baudrate);
00048 bool setup(int deviceNumber, int baudrate);
00049
00050
00051 int readBytes(unsigned char * buffer, int length);
00052 int writeBytes(unsigned char * buffer, int length);
00053 bool writeByte(unsigned char singleByte);
00054 int readByte();
00055 void flush(bool flushIn = true, bool flushOut = true);
00056 int available();
00057
00058 bool bVerbose;
00059 void setVerbose(bool bLoudmouth) { bVerbose = bLoudmouth; };
00060
00061
00062
00063 protected:
00064
00065 bool bInited;
00066
00067 #ifdef TARGET_WIN32
00068
00069 char ** portNamesShort;
00070 char ** portNamesFriendly;
00071 HANDLE hComm;
00072 int nPorts;
00073 bool bPortsEnumerated;
00074 void enumerateWin32Ports();
00075 COMMTIMEOUTS oldTimeout;
00076
00077 #else
00078 int fd;
00079 struct termios oldoptions;
00080 #endif
00081
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 #endif