int CSerialPort::Write(uint8_t* data, int len)
{
fd_set port;
-
+
+ CLockObject lock(&m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
int64_t now, target;
int bytesread = 0;
+ CLockObject lock(&m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
{
m_name = name;
m_error = strerror(errno);
-
+ CLockObject lock(&m_mutex);
+
if (databits < 5 || databits > 8)
{
m_error = "Databits has to be between 5 and 8";
void CSerialPort::Close()
{
+ CLockObject lock(&m_mutex);
if (m_fd != -1)
{
close(m_fd);
return true;
}
-bool CSerialPort::IsOpen() const
+bool CSerialPort::IsOpen()
{
+ CLockObject lock(&m_mutex);
return m_fd != -1;
}
#include <string>
#include <vector>
#include <stdint.h>
+#include "../platform/threads.h"
#ifndef __WINDOWS__
#include <termios.h>
#else
-#include "../util/threads.h"
#include "../util/buffer.h"
#endif
virtual ~CSerialPort();
bool Open(std::string name, int baudrate, int databits = 8, int stopbits = 1, int parity = PAR_NONE);
- bool SetBaudRate(int baudrate);
- bool IsOpen() const;
+ bool IsOpen();
void Close();
int Write(std::vector<uint8_t> data)
std::string GetName() { return m_name; }
private:
+ bool SetBaudRate(int baudrate);
+
std::string m_error;
std::string m_name;
+ CMutex m_mutex;
#ifdef __WINDOWS__
bool SetTimeouts(bool bBlocking);