Handle different baudrates, static library
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 7 Mar 2012 09:17:51 +0000 (09:17 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 7 Mar 2012 09:17:51 +0000 (09:17 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@50 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

ArduinoSerial/ArduinoSerial.suo
ArduinoSerial/ArduinoSerial/ArduinoSerial.vcxproj
Serial.cpp
Serial.hpp
SerialWindows.cpp
SerialWindows.hpp

index 71bf454febfb3450f098cc089d8c35c012e10bb3..b6522dacec4a105e972526246b79d3153a6de4be 100644 (file)
Binary files a/ArduinoSerial/ArduinoSerial.suo and b/ArduinoSerial/ArduinoSerial.suo differ
index 588b8479a3441349972fde7187e24de4a1434ea5..963a0c694da67ff40035e230eb6dbf8ba8247ede 100644 (file)
   </PropertyGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
-    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
     <CharacterSet>Unicode</CharacterSet>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
-    <ConfigurationType>DynamicLibrary</ConfigurationType>\r
+    <ConfigurationType>StaticLibrary</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
     <CharacterSet>Unicode</CharacterSet>\r
index 64744502ddb62c11ffb29853cc9c0137ff7ec83c..08523273e9db6b33636f073c8cdb4ba6c21af1b8 100644 (file)
@@ -1,6 +1,6 @@
 #include "Serial.hpp"\r
 \r
-Serial::Serial(const char *)\r
+Serial::Serial(const char *, int baudrate)\r
 :_connected(false)\r
 {\r
 }\r
index da69a3371b61bab1059ada9efc0590ee29130f1f..61f9a0b40a450fa679ca448b60a974c84560f343 100644 (file)
@@ -7,7 +7,8 @@ class Serial
 {\r
     public:\r
         //Initialize Serial communication with the given COM port\r
-        __declspec(dllexport) Serial(const char *portName);\r
+               //baudrate among 300 1200 2400 4800 9600 14400 19200 38400 57600 115200\r
+        __declspec(dllexport) Serial(const char *portName, int baudrate = 57600);\r
 \r
         //Close the connection\r
         //NOTA: for some reason you can't connect again before exiting\r
index 04a27ad91b4282d88380e1bed26998c45b3ce08e..872a7125710de4b698a1a6b0ac03b9d03724f62c 100644 (file)
@@ -7,7 +7,7 @@ using namespace std;
 #include <windows.h>
 #endif
 \r
-SerialWindows::SerialWindows(const char *portName)\r
+SerialWindows::SerialWindows(const char *portName, int baudrate)\r
 :Serial(portName)\r
 {\r
     //Try to connect to the given port throuh CreateFile\r
@@ -54,7 +54,42 @@ SerialWindows::SerialWindows(const char *portName)
         else\r
         {\r
             //Define serial connection parameters for the arduino board\r
-            dcbSerialParams.BaudRate=CBR_57600;\r
+                       switch(baudrate)\r
+                       {        \r
+                               case 300:\r
+                           dcbSerialParams.BaudRate=CBR_300; \r
+                                       break;\r
+                               case 1200:\r
+                           dcbSerialParams.BaudRate=CBR_1200; \r
+                                       break;\r
+                               case 2400:\r
+                           dcbSerialParams.BaudRate=CBR_2400; \r
+                                       break;\r
+                               case 4800:\r
+                           dcbSerialParams.BaudRate=CBR_4800; \r
+                                       break;\r
+                               case 9600:\r
+                           dcbSerialParams.BaudRate=CBR_9600; \r
+                                       break;\r
+                               case 14400:\r
+                           dcbSerialParams.BaudRate=CBR_14400; \r
+                                       break;\r
+                               case 19200:\r
+                           dcbSerialParams.BaudRate=CBR_19200; \r
+                                       break;\r
+                               case 38400:\r
+                           dcbSerialParams.BaudRate=CBR_38400; \r
+                                       break;\r
+                               case 57600:\r
+                           dcbSerialParams.BaudRate=CBR_57600; \r
+                                       break;\r
+                               case 115200:\r
+                           dcbSerialParams.BaudRate=CBR_115200; \r
+                                       break;\r
+                               default:\r
+                                       dcbSerialParams.BaudRate=CBR_57600; \r
+                                       break;\r
+                       }\r
             dcbSerialParams.ByteSize=8;\r
             dcbSerialParams.StopBits=ONESTOPBIT;\r
             dcbSerialParams.Parity=NOPARITY;\r
index 0d2b11223d452391829685d79968f886ba07815a..f3c056ee405e1d2040be7606c861aff7aa816a04 100644 (file)
@@ -9,7 +9,7 @@ class SerialWindows : public Serial
 {\r
     public:\r
         //Initialize Serial communication with the given COM port\r
-        __declspec(dllexport) SerialWindows(const char *portName);\r
+        __declspec(dllexport) SerialWindows(const char *portName, int baudrate = 57600);\r
         //Close the connection\r
         //NOTA: for some reason you can't connect again before exiting\r
         //the program and running it again\r