From eea242fdb12af8b929a64d0c9b57974e38e06e99 Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Wed, 7 Mar 2012 09:17:51 +0000 Subject: [PATCH] Handle different baudrates, static library git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@50 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- ArduinoSerial/ArduinoSerial.suo | Bin 19456 -> 20992 bytes .../ArduinoSerial/ArduinoSerial.vcxproj | 4 +- Serial.cpp | 2 +- Serial.hpp | 3 +- SerialWindows.cpp | 39 +++++++++++++++++- SerialWindows.hpp | 2 +- 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/ArduinoSerial/ArduinoSerial.suo b/ArduinoSerial/ArduinoSerial.suo index 71bf454febfb3450f098cc089d8c35c012e10bb3..b6522dacec4a105e972526246b79d3153a6de4be 100644 GIT binary patch delta 1000 zcmcJMUr19?9LMi(yVvHt(_N>gt2y__$#U5&ar4hgO~RJ7Yk%xTP*VHzV3fOoPcoE1 z5^e5hWwHka4XGYtSIFog#U9Mawg;awgYc=B3>E}J>)a*d+It7SaL(s@&iDMz?*t|w zFas}cDaP7ZLlH$$CL%MDg~&=&Ok^V}5l0l)AVfEV22HeaA78sNSnl|MemchLiJwN4 zAOmBx6&KTK>|>f)W*4T6Ko%|jV&2mlDE!xot9dquK$R>=6f$^*RT7dZqZrrnEK5L! z912{NmF~&i1G9Y^Fc6}a(|9(IZ!?@I=q{?VWri5n`Djh@8JrBGkk7OG2`G@mc)kyp zIgc19Xj0+|=MEX-U=)8EZYy98TRgguX%Yg`1fwUqaI+{A>FTQy^GVP^7Rk}dvjhvt zqRTOESr_jW3xMyeOX6?a9N@5>RacR%G*ROMPTNQDwEY~TAWJ)j?Vs|b=KLMoZ=`;- z676o(mo`Y}8R;rY>?yqjXf__l%!Wf))X3ttLyMy(6&Ub~XIPpsC1jr$O|F7a*(mpI ze(S;P;^W-a`y0Ji)_NBh98>5pQZ~Y^zp~k?&Mv2~PM&i1FWM{8l1}H5FuV*on^Xr# zO6tP}C(la7rpurhce0?3#&+&>g_$SHiP=YE7hWrqA(o@hxbObWEqZ?1hdbO-_vMd2 z)RLp=p}MJ?ltB5ZHp(w1ssKc&NB|@v^>Yd|TMKcj#)kckJPy?Kk@x9goHYLib{O?| z{#YIik=0!cR;nPJ;vL>R<~k{iMuV#zXR6&8t>lyE1|#kbfROmvVSz}s14w8H9W||D zPVE{%kR-T5o(9swgZR}m4o_2&!NU&Z>mCw1w5O#eQB^qA507!Z3^rJstg7f`W|}OIL$>h6FrFran=R%sVwyA zT4@SGsuuc9tn^#=jx{m`TX-i%PUEQsVZQ3TBp7%dykgxTn|Z1nHK`Yk2j6f2tr0KG!&*A=nP>zHD+I9FY-;)Fuf{RxxKVA&VZv z;og8X9|y8OrtM@xu+SKQWxt&aqcSiP_(aG!oUG5+qsI7{E-4wTBrw<534CY}qV*if zk}OSe0_~MCv6;eZ=(f@@?y45n8_bZXR9GFX)NSs~)WbyaV>Tb`;mzxcB+fIg!E}8% zEei7o(!uE}6vKHK(}iU?A_F@O+=U@ONB*N|D2_~lz&|1)wh@A2zC%02^gx_?{{jSz BN0$Hq diff --git a/ArduinoSerial/ArduinoSerial/ArduinoSerial.vcxproj b/ArduinoSerial/ArduinoSerial/ArduinoSerial.vcxproj index 588b847..963a0c6 100644 --- a/ArduinoSerial/ArduinoSerial/ArduinoSerial.vcxproj +++ b/ArduinoSerial/ArduinoSerial/ArduinoSerial.vcxproj @@ -17,12 +17,12 @@ - DynamicLibrary + StaticLibrary true Unicode - DynamicLibrary + StaticLibrary false true Unicode diff --git a/Serial.cpp b/Serial.cpp index 6474450..0852327 100644 --- a/Serial.cpp +++ b/Serial.cpp @@ -1,6 +1,6 @@ #include "Serial.hpp" -Serial::Serial(const char *) +Serial::Serial(const char *, int baudrate) :_connected(false) { } diff --git a/Serial.hpp b/Serial.hpp index da69a33..61f9a0b 100644 --- a/Serial.hpp +++ b/Serial.hpp @@ -7,7 +7,8 @@ class Serial { public: //Initialize Serial communication with the given COM port - __declspec(dllexport) Serial(const char *portName); + //baudrate among 300 1200 2400 4800 9600 14400 19200 38400 57600 115200 + __declspec(dllexport) Serial(const char *portName, int baudrate = 57600); //Close the connection //NOTA: for some reason you can't connect again before exiting diff --git a/SerialWindows.cpp b/SerialWindows.cpp index 04a27ad..872a712 100644 --- a/SerialWindows.cpp +++ b/SerialWindows.cpp @@ -7,7 +7,7 @@ using namespace std; #include #endif -SerialWindows::SerialWindows(const char *portName) +SerialWindows::SerialWindows(const char *portName, int baudrate) :Serial(portName) { //Try to connect to the given port throuh CreateFile @@ -54,7 +54,42 @@ SerialWindows::SerialWindows(const char *portName) else { //Define serial connection parameters for the arduino board - dcbSerialParams.BaudRate=CBR_57600; + switch(baudrate) + { + case 300: + dcbSerialParams.BaudRate=CBR_300; + break; + case 1200: + dcbSerialParams.BaudRate=CBR_1200; + break; + case 2400: + dcbSerialParams.BaudRate=CBR_2400; + break; + case 4800: + dcbSerialParams.BaudRate=CBR_4800; + break; + case 9600: + dcbSerialParams.BaudRate=CBR_9600; + break; + case 14400: + dcbSerialParams.BaudRate=CBR_14400; + break; + case 19200: + dcbSerialParams.BaudRate=CBR_19200; + break; + case 38400: + dcbSerialParams.BaudRate=CBR_38400; + break; + case 57600: + dcbSerialParams.BaudRate=CBR_57600; + break; + case 115200: + dcbSerialParams.BaudRate=CBR_115200; + break; + default: + dcbSerialParams.BaudRate=CBR_57600; + break; + } dcbSerialParams.ByteSize=8; dcbSerialParams.StopBits=ONESTOPBIT; dcbSerialParams.Parity=NOPARITY; diff --git a/SerialWindows.hpp b/SerialWindows.hpp index 0d2b112..f3c056e 100644 --- a/SerialWindows.hpp +++ b/SerialWindows.hpp @@ -9,7 +9,7 @@ class SerialWindows : public Serial { public: //Initialize Serial communication with the given COM port - __declspec(dllexport) SerialWindows(const char *portName); + __declspec(dllexport) SerialWindows(const char *portName, int baudrate = 57600); //Close the connection //NOTA: for some reason you can't connect again before exiting //the program and running it again -- 2.30.2