Check if the serial port is open, arduino serial communication in a separate standalo...
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 7 Mar 2012 10:43:08 +0000 (10:43 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 7 Mar 2012 10:43:08 +0000 (10:43 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@53 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

TactonLibrary.suo
TactonPlayer/Serial.cpp [deleted file]
TactonPlayer/Serial.hpp [deleted file]
TactonPlayer/SerialWindows.cpp [deleted file]
TactonPlayer/SerialWindows.hpp [deleted file]
TactonPlayer/TactonPlayer.cpp
TactonPlayer/TactonPlayer.hpp
TactonPlayer/TactonPlayer.vcxproj

index 592721446cd606d7c54e95e53ac64722c231c1a2..3e62d939c917d3dd768a3f197e13a7b07ea5fb2f 100644 (file)
Binary files a/TactonLibrary.suo and b/TactonLibrary.suo differ
diff --git a/TactonPlayer/Serial.cpp b/TactonPlayer/Serial.cpp
deleted file mode 100644 (file)
index 6474450..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "Serial.hpp"\r
-\r
-Serial::Serial(const char *)\r
-:_connected(false)\r
-{\r
-}\r
-\r
-Serial::~Serial()\r
-{\r
-}\r
diff --git a/TactonPlayer/Serial.hpp b/TactonPlayer/Serial.hpp
deleted file mode 100644 (file)
index 4ee686d..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef _SERIAL_\r
-#define _SERIAL_\r
-\r
-#define ARDUINO_WAIT_TIME 500\r
-\r
-class Serial\r
-{\r
-    public:\r
-        //Initialize Serial communication with the given COM port\r
-        Serial(const char *portName);\r
-\r
-        //Close the connection\r
-        //NOTA: for some reason you can't connect again before exiting\r
-        //the program and running it again\r
-        virtual ~Serial();\r
-\r
-        //Read data in a buffer, if nbChar is greater than the\r
-        //maximum number of bytes available, it will return only the\r
-        //bytes available. The function return -1 when nothing could\r
-        //be read, the number of bytes actually read.\r
-        virtual int ReadData(void *buffer, unsigned int nbChar)=0;\r
-\r
-        //Writes data from a buffer through the Serial connection\r
-        //return true on success.\r
-        virtual bool WriteData(void *buffer, unsigned int nbChar)=0;\r
-\r
-        //Check if we are actually connected\r
-               bool IsConnected() { return _connected; }\r
-\r
-    protected:\r
-        //Connection status\r
-        bool _connected;\r
-};\r
-\r
-#endif\r
diff --git a/TactonPlayer/SerialWindows.cpp b/TactonPlayer/SerialWindows.cpp
deleted file mode 100644 (file)
index 251f9bd..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-#include "SerialWindows.hpp"\r
-\r
-#include <iostream>\r
-using namespace std;\r
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-\r
-SerialWindows::SerialWindows(const char *portName)\r
-:Serial(portName)\r
-{\r
-    //Try to connect to the given port throuh CreateFile\r
-    _hSerial = CreateFileA(portName,\r
-            GENERIC_READ | GENERIC_WRITE,\r
-            0,\r
-            NULL,\r
-            OPEN_EXISTING,\r
-            FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, //FILE_ATTRIBUTE_NORMAL,\r
-            NULL);\r
-\r
-    //Check if the connection was successfull\r
-    if(_hSerial == INVALID_HANDLE_VALUE)\r
-    {\r
-        //If not success full display an Error\r
-        if(GetLastError() == ERROR_FILE_NOT_FOUND)\r
-            cerr << "ERROR: Handle was not attached. Reason: " << portName << " not available." << endl;\r
-        else\r
-            cerr << "ERROR unknown" << endl;\r
-               char buffer[256];\r
-               sprintf(buffer, "Port %s does not exist or not reachable", portName);\r
-               throw buffer;\r
-    }\r
-    else\r
-    {\r
-       /*      
-       COMMTIMEOUTS commTimeouts;
-       commTimeouts.ReadIntervalTimeout = 1;
-       commTimeouts.ReadTotalTimeoutMultiplier = 10;
-       commTimeouts.ReadTotalTimeoutConstant = 100;
-       commTimeouts.WriteTotalTimeoutMultiplier = 10;
-       commTimeouts.WriteTotalTimeoutConstant = 100;
-       if (SetCommTimeouts(_comport, &commTimeouts) == 0)
-               throw "Cannot set COM port timeouts";*/
-\r
-\r
-        //If connected we try to set the comm parameters\r
-        DCB dcbSerialParams = {0};\r
-\r
-        //Try to get the current\r
-        if (!GetCommState(_hSerial, &dcbSerialParams))\r
-            //If impossible, show an error\r
-            cerr << "ERROR: failed to get current serial parameters!" << endl;\r
-        else\r
-        {\r
-            //Define serial connection parameters for the arduino board\r
-            dcbSerialParams.BaudRate=CBR_57600;\r
-            dcbSerialParams.ByteSize=8;\r
-            dcbSerialParams.StopBits=ONESTOPBIT;\r
-            dcbSerialParams.Parity=NOPARITY;\r
-\r
-             //Set the parameters and check for their proper application\r
-             if(!SetCommState(_hSerial, &dcbSerialParams))\r
-                cerr << "ERROR: Could not set Serial Port parameters" << endl;\r
-             else\r
-             {\r
-                 //If everything went fine we're connected\r
-                 _connected = true;\r
-                 //We wait 2s as the arduino board will be reseting\r
-                                Sleep(2000);\r
-                 //SDL_Delay(ARDUINO_WAIT_TIME);\r
-             }\r
-        }\r
-    }\r
-}\r
-\r
-SerialWindows::~SerialWindows()\r
-{\r
-    //Check if we are connected before trying to disconnect\r
-    if(_connected)\r
-    {\r
-        //We're no longer connected\r
-        _connected = false;\r
-        //Close the serial handler\r
-        CloseHandle(_hSerial);\r
-    }\r
-}\r
-\r
-int SerialWindows::ReadData(void *buffer, unsigned int nbChar)\r
-{\r
-    //Number of bytes we'll have read\r
-    DWORD bytesRead = 0;\r
-    //Number of bytes we'll really ask to read\r
-    unsigned int toRead = 0;\r
-\r
-    //Use the ClearCommError function to get status info on the Serial port\r
-    ClearCommError(_hSerial, &_errors, &_status);\r
-\r
-    //Check if there is something to read\r
-    if(_status.cbInQue > 0)\r
-    {\r
-        //If there is we check if there is enough data to read the required number\r
-        //of characters, if not we'll read only the available characters to prevent\r
-        //locking of the application.\r
-        if(_status.cbInQue > nbChar)\r
-                       toRead = nbChar;\r
-        else\r
-                       toRead = _status.cbInQue;\r
-\r
-        //Try to read the require number of chars, and return the number of read bytes on success\r
-        if(ReadFile(_hSerial, buffer, toRead, &bytesRead, NULL) && bytesRead != 0)\r
-            return bytesRead;\r
-    }\r
-\r
-    //If nothing has been read, or that an error was detected return -1\r
-    return -1;\r
-}\r
-\r
-\r
-bool SerialWindows::WriteData(void *buffer, unsigned int nbChar)\r
-{\r
-    DWORD bytesSend;\r
-\r
-    //Try to write the buffer on the Serial port\r
-    if(!WriteFile(_hSerial, buffer, nbChar, &bytesSend, 0))\r
-    {\r
-        //In case it don't work get comm error and return false\r
-        ClearCommError(_hSerial, &_errors, &_status);\r
-\r
-        return false;\r
-    }\r
-    else\r
-       {\r
-        ClearCommError(_hSerial, &_errors, &_status);\r
-/*             if(!FlushFileBuffers(_hSerial))\r
-                       cout << "ERROR while flushing" << endl;*/\r
-/*             stringstream s;
-               s << bytesSend << " SENT" << endl;
-               OutputDebugString(s.str().c_str());*/
-        return true;\r
-       }\r
-}\r
diff --git a/TactonPlayer/SerialWindows.hpp b/TactonPlayer/SerialWindows.hpp
deleted file mode 100644 (file)
index a7e5c16..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef _SERIALWINDOWS_\r
-#define _SERIALWINDOWS_\r
-\r
-#include "Serial.hpp"\r
-\r
-#include <windows.h>\r
-\r
-class SerialWindows : public Serial\r
-{\r
-    public:\r
-        //Initialize Serial communication with the given COM port\r
-        SerialWindows(const char *portName);\r
-        //Close the connection\r
-        //NOTA: for some reason you can't connect again before exiting\r
-        //the program and running it again\r
-        ~SerialWindows();\r
-        //Read data in a buffer, if nbChar is greater than the\r
-        //maximum number of bytes available, it will return only the\r
-        //bytes available. The function return -1 when nothing could\r
-        //be read, the number of bytes actually read.\r
-        int ReadData(void *buffer, unsigned int nbChar);\r
-        //Writes data from a buffer through the Serial connection\r
-        //return true on success.\r
-        bool WriteData(void *buffer, unsigned int nbChar);\r
-\r
-\r
-    private:\r
-        //Serial comm handler\r
-        HANDLE _hSerial;\r
-        //Get various information about the connection\r
-        COMSTAT _status;\r
-        //Keep track of last error\r
-        DWORD _errors;\r
-};\r
-#endif\r
index 35eab85be01eb67c557204d2322384eb1ae12dc0..e57595c3a05a5e577866a9e41ca8f03a8eded2e9 100644 (file)
@@ -1,6 +1,6 @@
 #include "TactonPlayer.hpp"\r
 \r
-#include "SerialWindows.hpp"\r
+#include <ArduinoSerial\SerialWindows.hpp>\r
 \r
 #include <stdexcept>\r
 \r
index bb77e14820aba32319a349fb3a4a9dae9175dc3f..3671db2cdd5bd0880ed9a3af99ce70a48c1d0cea 100644 (file)
@@ -1,6 +1,6 @@
 #include "Tacton.hpp"\r
 \r
-#include "Serial.hpp"\r
+#include <ArduinoSerial\Serial.hpp>\r
 \r
 class TactonPlayer\r
 {\r
index 790227485bf0e9f08f6e685134f47741327e822a..86019d3002dbc588fd6964981f1032cb7e9e8d39 100644 (file)
@@ -56,7 +56,7 @@
     <Link>\r
       <SubSystem>Windows</SubSystem>\r
       <GenerateDebugInformation>true</GenerateDebugInformation>\r
-      <AdditionalDependencies>arduinoserial.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <AdditionalDependencies>arduinoseriald.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
     </Link>\r
     <PostBuildEvent>\r
       <Command>copy /y $(CodeAnalysisInputAssembly) C:\Windows\system\\r