summaryrefslogtreecommitdiff
path: root/OpenModelicaArduino/Source/serial.h
diff options
context:
space:
mode:
authormanasdas172018-06-04 11:43:49 +0530
committerGitHub2018-06-04 11:43:49 +0530
commitaf40def1c18d18eb32845ec57b6b5f07a5bcf29d (patch)
tree5e6a0fa96746ea3c9beaea7fe54521d72fce8fc7 /OpenModelicaArduino/Source/serial.h
parentfefaf700250d88595273b038909fe95d7602d125 (diff)
parent64db4ecdc6232c2e3f6d12a0381b7e601b49703c (diff)
downloadOpenModelicaEmbedded-1-af40def1c18d18eb32845ec57b6b5f07a5bcf29d.tar.gz
OpenModelicaEmbedded-1-af40def1c18d18eb32845ec57b6b5f07a5bcf29d.tar.bz2
OpenModelicaEmbedded-1-af40def1c18d18eb32845ec57b6b5f07a5bcf29d.zip
Merge pull request #1 from manasdas17/Ritu-Kanwar-Shekhawat
Ritu kanwar shekhawat
Diffstat (limited to 'OpenModelicaArduino/Source/serial.h')
-rwxr-xr-xOpenModelicaArduino/Source/serial.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/OpenModelicaArduino/Source/serial.h b/OpenModelicaArduino/Source/serial.h
new file mode 100755
index 0000000..e49b4a7
--- /dev/null
+++ b/OpenModelicaArduino/Source/serial.h
@@ -0,0 +1,57 @@
+#ifndef __serial_h__
+#define __serial_h__
+
+#include <stdint.h>
+
+#if defined(LINUX)
+#include <termios.h>
+#elif defined(MACOSX)
+#include <termios.h>
+#elif defined(WINDOWS)
+#include <windows.h>
+#endif
+
+#include <vector>
+#include <string>
+#include <sstream>
+#include <algorithm>
+
+using namespace std;
+
+class Serial
+{
+public:
+ Serial();
+ ~Serial();
+ vector<string> port_list();
+ int Open(const string& name);
+ string error_message();
+ int Set_baud(int baud);
+ int Set_baud(const string& baud_str);
+ int Read(void *ptr, int count);
+ int Write(const void *ptr, int len);
+ int Input_wait(int msec);
+ void Input_discard(void);
+ int Set_control(int dtr, int rts);
+ void Output_flush();
+ void Close(void);
+ int Is_open(void);
+ string get_name(void);
+private:
+ int port_is_open;
+ string port_name;
+ int baud_rate;
+ string error_msg;
+private:
+#if defined(LINUX) || defined(MACOSX)
+ int port_fd;
+ struct termios settings_orig;
+ struct termios settings;
+#elif defined(WINDOWS)
+ HANDLE port_handle;
+ COMMCONFIG port_cfg_orig;
+ COMMCONFIG port_cfg;
+#endif
+};
+
+#endif // __serial_h__