Subversion Repositories HomeAutomation

Rev

Rev 1593 | Rev 1596 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1593 Rev 1595
Line 29... Line 29...
29
{
29
{
30
}
30
}
31
 
31
 
32
SerialClient::~SerialClient()
32
SerialClient::~SerialClient()
33
{
33
{
-
 
34
    if (this->serial_port_.is_open())
-
 
35
    {
-
 
36
        this->serial_port_.cancel();
34
    this->serial_port_.close();
37
        this->serial_port_.close();
-
 
38
    }
35
}
39
}
36
 
40
 
37
void SerialClient::Connect(std::string address, unsigned int baud)
41
void SerialClient::Connect(std::string address, unsigned int baud)
38
{
42
{
39
    boost::asio::serial_port_base::baud_rate baud_option(baud);
43
    boost::asio::serial_port_base::baud_rate baud_option(baud);
40
   
44
   
41
    this->serial_port_.open(address);
45
    this->serial_port_.open(address);
42
   
46
   
43
    if (!this->serial_port_.is_open())
47
    if (!this->serial_port_.is_open())
44
    {
48
    {
45
        throw std::runtime_error("Error while opening " + address);
49
        throw std::runtime_error("Error while opening " + address);
46
    }
50
    }
47
   
51
   
48
    this->serial_port_.set_option(baud_option);
52
    this->serial_port_.set_option(baud_option);
49
   
53
   
50
    this->Read();
54
    this->Read();
51
}
55
}
52
 
56
 
53
void SerialClient::Disconnect()
57
void SerialClient::Disconnect()
54
{
58
{
-
 
59
    if (this->serial_port_.is_open())
-
 
60
    {
-
 
61
        this->serial_port_.cancel();
55
    this->serial_port_.close();
62
        this->serial_port_.close();
-
 
63
    }
56
   
64
   
57
    Client::Disconnect();
65
    Client::Disconnect();
58
}
66
}
59
 
67
 
60
void SerialClient::Send(Buffer data)
68
void SerialClient::Send(Buffer data)