Subversion Repositories HomeAutomation

Rev

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

Rev 1597 Rev 1599
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();
-
 
37
        this->serial_port_.close();
-
 
38
    }
-
 
39
}
34
}
40
 
35
 
41
void SerialClient::Connect(std::string address, unsigned int baud)
36
void SerialClient::Connect(std::string address, unsigned int baud)
42
{
37
{
43
    boost::asio::serial_port_base::baud_rate baud_option(baud);
38
    boost::asio::serial_port_base::baud_rate baud_option(baud);
44
   
39
   
45
    this->serial_port_.open(address);
40
    this->serial_port_.open(address);
46
   
41
   
47
    if (!this->serial_port_.is_open())
42
    if (!this->serial_port_.is_open())
48
    {
43
    {
49
        throw std::runtime_error("Error while opening " + address);
44
        throw std::runtime_error("Error while opening " + address);
50
    }
45
    }
51
   
46
   
52
    this->serial_port_.set_option(baud_option);
47
    this->serial_port_.set_option(baud_option);
53
   
48
   
54
    this->Read();
49
    this->Read();
55
}
50
}
56
 
51
 
57
void SerialClient::Disconnect()
52
void SerialClient::Stop()
58
{
53
{
59
    if (this->serial_port_.is_open())
54
    if (this->serial_port_.is_open())
60
    {
55
    {
61
        this->serial_port_.cancel();
56
        this->serial_port_.cancel();
62
        this->serial_port_.close();
57
        this->serial_port_.close();
63
    }
58
    }
64
   
-
 
65
    Client::Disconnect();
-
 
66
}
59
}
67
 
60
 
68
void SerialClient::Send(type::Byteset data)
61
void SerialClient::Send(type::Byteset data)
69
{
62
{
70
    try
63
    try