Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 163637 | Differences between
and this patch

Collapse All | Expand All

(-)examples/read_port.cpp (-10 / +11 lines)
Lines 1-5 Link Here
1
#include <iostream>
1
#include <iostream>
2
#include <unistd.h>
2
#include <unistd.h>
3
#include <cstdlib>
3
#include <SerialStream.h>
4
#include <SerialStream.h>
4
5
5
int
6
int
Lines 12-21 Link Here
12
    using namespace LibSerial ;
13
    using namespace LibSerial ;
13
    SerialStream serial_port ;
14
    SerialStream serial_port ;
14
    serial_port.Open( "/dev/ttyUSB0" ) ;
15
    serial_port.Open( "/dev/ttyUSB0" ) ;
15
    if ( ! serial_port.good() ) 
16
    if ( ! serial_port.good() )
16
    {
17
    {
17
        std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] "
18
        std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] "
18
                  << "Error: Could not open serial port." 
19
                  << "Error: Could not open serial port."
19
                  << std::endl ;
20
                  << std::endl ;
20
        exit(1) ;
21
        exit(1) ;
21
    }
22
    }
Lines 23-29 Link Here
23
    // Set the baud rate of the serial port.
24
    // Set the baud rate of the serial port.
24
    //
25
    //
25
    serial_port.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
26
    serial_port.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
26
    if ( ! serial_port.good() ) 
27
    if ( ! serial_port.good() )
27
    {
28
    {
28
        std::cerr << "Error: Could not set the baud rate." << std::endl ;
29
        std::cerr << "Error: Could not set the baud rate." << std::endl ;
29
        exit(1) ;
30
        exit(1) ;
Lines 32-38 Link Here
32
    // Set the number of data bits.
33
    // Set the number of data bits.
33
    //
34
    //
34
    serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
35
    serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
35
    if ( ! serial_port.good() ) 
36
    if ( ! serial_port.good() )
36
    {
37
    {
37
        std::cerr << "Error: Could not set the character size." << std::endl ;
38
        std::cerr << "Error: Could not set the character size." << std::endl ;
38
        exit(1) ;
39
        exit(1) ;
Lines 41-47 Link Here
41
    // Disable parity.
42
    // Disable parity.
42
    //
43
    //
43
    serial_port.SetParity( SerialStreamBuf::PARITY_NONE ) ;
44
    serial_port.SetParity( SerialStreamBuf::PARITY_NONE ) ;
44
    if ( ! serial_port.good() ) 
45
    if ( ! serial_port.good() )
45
    {
46
    {
46
        std::cerr << "Error: Could not disable the parity." << std::endl ;
47
        std::cerr << "Error: Could not disable the parity." << std::endl ;
47
        exit(1) ;
48
        exit(1) ;
Lines 50-56 Link Here
50
    // Set the number of stop bits.
51
    // Set the number of stop bits.
51
    //
52
    //
52
    serial_port.SetNumOfStopBits( 1 ) ;
53
    serial_port.SetNumOfStopBits( 1 ) ;
53
    if ( ! serial_port.good() ) 
54
    if ( ! serial_port.good() )
54
    {
55
    {
55
        std::cerr << "Error: Could not set the number of stop bits."
56
        std::cerr << "Error: Could not set the number of stop bits."
56
                  << std::endl ;
57
                  << std::endl ;
Lines 60-66 Link Here
60
    // Turn off hardware flow control.
61
    // Turn off hardware flow control.
61
    //
62
    //
62
    serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
63
    serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
63
    if ( ! serial_port.good() ) 
64
    if ( ! serial_port.good() )
64
    {
65
    {
65
        std::cerr << "Error: Could not use hardware flow control."
66
        std::cerr << "Error: Could not use hardware flow control."
66
                  << std::endl ;
67
                  << std::endl ;
Lines 74-93 Link Here
74
    //
75
    //
75
    // Wait for some data to be available at the serial port.
76
    // Wait for some data to be available at the serial port.
76
    //
77
    //
77
    while( serial_port.rdbuf()->in_avail() == 0 ) 
78
    while( serial_port.rdbuf()->in_avail() == 0 )
78
    {
79
    {
79
        usleep(100) ;
80
        usleep(100) ;
80
    }
81
    }
81
    //
82
    //
82
    // Keep reading data from serial port and print it to the screen.
83
    // Keep reading data from serial port and print it to the screen.
83
    //
84
    //
84
    while( serial_port.rdbuf()->in_avail() > 0  ) 
85
    while( serial_port.rdbuf()->in_avail() > 0  )
85
    {
86
    {
86
        char next_byte;
87
        char next_byte;
87
        serial_port.get(next_byte);
88
        serial_port.get(next_byte);
88
        std::cerr << std::hex << static_cast<int>(next_byte) << " ";
89
        std::cerr << std::hex << static_cast<int>(next_byte) << " ";
89
        usleep(100) ;
90
        usleep(100) ;
90
    } 
91
    }
91
    std::cerr << std::endl ;
92
    std::cerr << std::endl ;
92
    return EXIT_SUCCESS ;
93
    return EXIT_SUCCESS ;
93
}
94
}
(-)examples/write_port.cpp (-17 / +18 lines)
Lines 1-9 Link Here
1
#include <iostream>
1
#include <iostream>
2
#include <fstream>
2
#include <fstream>
3
#include <cstdlib>
3
#include <SerialStream.h>
4
#include <SerialStream.h>
4
5
5
//
6
//
6
// This example reads the contents of a file and writes the entire 
7
// This example reads the contents of a file and writes the entire
7
// file to the serial port one character at a time.
8
// file to the serial port one character at a time.
8
//
9
//
9
int
10
int
Lines 11-17 Link Here
11
      char** argv  )
12
      char** argv  )
12
{
13
{
13
    //
14
    //
14
    if ( argc < 2 ) 
15
    if ( argc < 2 )
15
    {
16
    {
16
        std::cerr << "Usage: " << argv[0] << " <filename>" << std::endl ;
17
        std::cerr << "Usage: " << argv[0] << " <filename>" << std::endl ;
17
        return 1 ;
18
        return 1 ;
Lines 20-32 Link Here
20
    // Open the serial port.
21
    // Open the serial port.
21
    //
22
    //
22
    const char* const SERIAL_PORT_DEVICE = "/dev/ttyUSB0" ;
23
    const char* const SERIAL_PORT_DEVICE = "/dev/ttyUSB0" ;
23
    using namespace LibSerial ;    
24
    using namespace LibSerial ;
24
    SerialStream serial_port ;
25
    SerialStream serial_port ;
25
    serial_port.Open( SERIAL_PORT_DEVICE ) ;
26
    serial_port.Open( SERIAL_PORT_DEVICE ) ;
26
    if ( ! serial_port.good() ) 
27
    if ( ! serial_port.good() )
27
    {
28
    {
28
        std::cerr << "Error: Could not open serial port " 
29
        std::cerr << "Error: Could not open serial port "
29
                  << SERIAL_PORT_DEVICE 
30
                  << SERIAL_PORT_DEVICE
30
                  << std::endl ;
31
                  << std::endl ;
31
        exit(1) ;
32
        exit(1) ;
32
    }
33
    }
Lines 34-40 Link Here
34
    // Set the baud rate of the serial port.
35
    // Set the baud rate of the serial port.
35
    //
36
    //
36
    serial_port.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
37
    serial_port.SetBaudRate( SerialStreamBuf::BAUD_115200 ) ;
37
    if ( ! serial_port.good() ) 
38
    if ( ! serial_port.good() )
38
    {
39
    {
39
        std::cerr << "Error: Could not set the baud rate." << std::endl ;
40
        std::cerr << "Error: Could not set the baud rate." << std::endl ;
40
        exit(1) ;
41
        exit(1) ;
Lines 43-49 Link Here
43
    // Set the number of data bits.
44
    // Set the number of data bits.
44
    //
45
    //
45
    serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
46
    serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 ) ;
46
    if ( ! serial_port.good() ) 
47
    if ( ! serial_port.good() )
47
    {
48
    {
48
        std::cerr << "Error: Could not set the character size." << std::endl ;
49
        std::cerr << "Error: Could not set the character size." << std::endl ;
49
        exit(1) ;
50
        exit(1) ;
Lines 52-58 Link Here
52
    // Disable parity.
53
    // Disable parity.
53
    //
54
    //
54
    serial_port.SetParity( SerialStreamBuf::PARITY_NONE ) ;
55
    serial_port.SetParity( SerialStreamBuf::PARITY_NONE ) ;
55
    if ( ! serial_port.good() ) 
56
    if ( ! serial_port.good() )
56
    {
57
    {
57
        std::cerr << "Error: Could not disable the parity." << std::endl ;
58
        std::cerr << "Error: Could not disable the parity." << std::endl ;
58
        exit(1) ;
59
        exit(1) ;
Lines 61-67 Link Here
61
    // Set the number of stop bits.
62
    // Set the number of stop bits.
62
    //
63
    //
63
    serial_port.SetNumOfStopBits( 1 ) ;
64
    serial_port.SetNumOfStopBits( 1 ) ;
64
    if ( ! serial_port.good() ) 
65
    if ( ! serial_port.good() )
65
    {
66
    {
66
        std::cerr << "Error: Could not set the number of stop bits."
67
        std::cerr << "Error: Could not set the number of stop bits."
67
                  << std::endl ;
68
                  << std::endl ;
Lines 71-77 Link Here
71
    // Turn on hardware flow control.
72
    // Turn on hardware flow control.
72
    //
73
    //
73
    serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
74
    serial_port.SetFlowControl( SerialStreamBuf::FLOW_CONTROL_NONE ) ;
74
    if ( ! serial_port.good() ) 
75
    if ( ! serial_port.good() )
75
    {
76
    {
76
        std::cerr << "Error: Could not use hardware flow control."
77
        std::cerr << "Error: Could not use hardware flow control."
77
                  << std::endl ;
78
                  << std::endl ;
Lines 83-109 Link Here
83
    //
84
    //
84
    // serial_port.unsetf( std::ios_base::skipws ) ;
85
    // serial_port.unsetf( std::ios_base::skipws ) ;
85
    //
86
    //
86
    // Open the input file for reading. 
87
    // Open the input file for reading.
87
    //
88
    //
88
    std::ifstream input_file( argv[1] ) ;
89
    std::ifstream input_file( argv[1] ) ;
89
    if ( ! input_file.good() ) 
90
    if ( ! input_file.good() )
90
    {
91
    {
91
        std::cerr << "Error: Could not open file "
92
        std::cerr << "Error: Could not open file "
92
                  << argv[1] << " for reading." << std::endl ;
93
                  << argv[1] << " for reading." << std::endl ;
93
        return 1 ;
94
        return 1 ;
94
    }
95
    }
95
    //
96
    //
96
    // Read characters from the input file and dump them to the serial 
97
    // Read characters from the input file and dump them to the serial
97
    // port. 
98
    // port.
98
    //
99
    //
99
    std::cerr << "Dumping file to serial port." << std::endl ;
100
    std::cerr << "Dumping file to serial port." << std::endl ;
100
    while( input_file ) 
101
    while( input_file )
101
    {
102
    {
102
        char next_byte ;
103
        char next_byte ;
103
        input_file.read( &next_byte, 1 ) ;
104
        input_file.read( &next_byte, 1 ) ;
104
        serial_port.write( &next_byte, 1 ) ;
105
        serial_port.write( &next_byte, 1 ) ;
105
        //
106
        //
106
        // Print a '.' for every character read from the input file. 
107
        // Print a '.' for every character read from the input file.
107
        //
108
        //
108
        std::cerr << "." ;
109
        std::cerr << "." ;
109
    }
110
    }
(-)src/PosixSignalDispatcher.cpp (-2 / +3 lines)
Lines 14-19 Link Here
14
#include <map>
14
#include <map>
15
#include <errno.h>
15
#include <errno.h>
16
#include <signal.h>
16
#include <signal.h>
17
#include <cstring>
17
18
18
namespace
19
namespace
19
{
20
{
Lines 285-292 Link Here
285
        }
286
        }
286
        //
287
        //
287
        // :TODO: Why is the following code commented out using "#if 0" ?
288
        // :TODO: Why is the following code commented out using "#if 0" ?
288
        // Check and remove this code if it is not necessary. Otherwise, if 
289
        // Check and remove this code if it is not necessary. Otherwise, if
289
        // it has been commented out due to a bug then debug and correct it. 
290
        // it has been commented out due to a bug then debug and correct it.
290
        //
291
        //
291
#if 0
292
#if 0
292
        /*
293
        /*
(-)src/SerialPort.cpp (-37 / +38 lines)
Lines 23-28 Link Here
23
#include "PosixSignalHandler.h"
23
#include "PosixSignalHandler.h"
24
#include <queue>
24
#include <queue>
25
#include <map>
25
#include <map>
26
#include <cstdlib>
26
#include <cerrno>
27
#include <cerrno>
27
#include <cassert>
28
#include <cassert>
28
#include <termios.h>
29
#include <termios.h>
Lines 200-208 Link Here
200
    SetDtr( const bool dtrState )
201
    SetDtr( const bool dtrState )
201
        throw( SerialPort::NotOpen,
202
        throw( SerialPort::NotOpen,
202
               std::runtime_error ) ;
203
               std::runtime_error ) ;
203
    
204
204
    bool
205
    bool
205
    GetDtr() const 
206
    GetDtr() const
206
        throw( SerialPort::NotOpen,
207
        throw( SerialPort::NotOpen,
207
               std::runtime_error ) ;
208
               std::runtime_error ) ;
208
209
Lines 210-229 Link Here
210
    SetRts( const bool rtsState )
211
    SetRts( const bool rtsState )
211
        throw( SerialPort::NotOpen,
212
        throw( SerialPort::NotOpen,
212
               std::runtime_error ) ;
213
               std::runtime_error ) ;
213
    
214
214
    bool
215
    bool
215
    GetRts() const 
216
    GetRts() const
216
        throw( SerialPort::NotOpen,
217
        throw( SerialPort::NotOpen,
217
               std::runtime_error ) ;
218
               std::runtime_error ) ;
218
219
219
    bool
220
    bool
220
    GetCts() const 
221
    GetCts() const
221
        throw( SerialPort::NotOpen,
222
        throw( SerialPort::NotOpen,
222
               std::runtime_error ) ;
223
               std::runtime_error ) ;
223
224
224
    
225
225
    bool
226
    bool
226
    GetDsr() const 
227
    GetDsr() const
227
        throw( SerialPort::NotOpen,
228
        throw( SerialPort::NotOpen,
228
               std::runtime_error ) ;
229
               std::runtime_error ) ;
229
    /*
230
    /*
Lines 258-276 Link Here
258
259
259
    /**
260
    /**
260
     * Circular buffer used to store the received data. This is done
261
     * Circular buffer used to store the received data. This is done
261
     * asynchronously and helps prevent overflow of the corresponding 
262
     * asynchronously and helps prevent overflow of the corresponding
262
     * tty's input buffer.
263
     * tty's input buffer.
263
     * 
264
     *
264
     * :TODO: The size of this buffer is allowed to increase indefinitely. If 
265
     * :TODO: The size of this buffer is allowed to increase indefinitely. If
265
     * data keeps arriving at the serial port and is never read then this 
266
     * data keeps arriving at the serial port and is never read then this
266
     * buffer will continue occupying more and more memory. We need to put a 
267
     * buffer will continue occupying more and more memory. We need to put a
267
     * cap on the size of this buffer. It might even be worth providing a 
268
     * cap on the size of this buffer. It might even be worth providing a
268
     * method to set the size of this buffer.  
269
     * method to set the size of this buffer.
269
     */
270
     */
270
    std::queue<unsigned char> mInputBuffer ;
271
    std::queue<unsigned char> mInputBuffer ;
271
272
272
    /**
273
    /**
273
     * Set the specified modem control line to the specified value. 
274
     * Set the specified modem control line to the specified value.
274
     *
275
     *
275
     * @param modemLine One of the following four values: TIOCM_DTR,
276
     * @param modemLine One of the following four values: TIOCM_DTR,
276
     * TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR.
277
     * TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR.
Lines 286-292 Link Here
286
287
287
    /**
288
    /**
288
     * Get the current state of the specified modem control line.
289
     * Get the current state of the specified modem control line.
289
     * 
290
     *
290
     * @param modemLine One of the following four values: TIOCM_DTR,
291
     * @param modemLine One of the following four values: TIOCM_DTR,
291
     * TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR.
292
     * TIOCM_RTS, TIOCM_CTS, or TIOCM_DSR.
292
     *
293
     *
Lines 296-302 Link Here
296
    bool
297
    bool
297
    GetModemControlLine( const int modemLine ) const
298
    GetModemControlLine( const int modemLine ) const
298
        throw( SerialPort::NotOpen,
299
        throw( SerialPort::NotOpen,
299
               std::runtime_error ) ;        
300
               std::runtime_error ) ;
300
} ;
301
} ;
301
302
302
SerialPort::SerialPort( const std::string& serialPortName ) :
303
SerialPort::SerialPort( const std::string& serialPortName ) :
Lines 524-539 Link Here
524
void
525
void
525
SerialPort::SetDtr( const bool dtrState )
526
SerialPort::SetDtr( const bool dtrState )
526
    throw( SerialPort::NotOpen,
527
    throw( SerialPort::NotOpen,
527
           std::runtime_error ) 
528
           std::runtime_error )
528
{
529
{
529
    mSerialPortImpl->SetDtr( dtrState ) ;
530
    mSerialPortImpl->SetDtr( dtrState ) ;
530
    return ;
531
    return ;
531
}
532
}
532
533
533
bool
534
bool
534
SerialPort::GetDtr() const 
535
SerialPort::GetDtr() const
535
    throw( SerialPort::NotOpen,
536
    throw( SerialPort::NotOpen,
536
           std::runtime_error ) 
537
           std::runtime_error )
537
{
538
{
538
    return mSerialPortImpl->GetDtr() ;
539
    return mSerialPortImpl->GetDtr() ;
539
}
540
}
Lines 541-573 Link Here
541
void
542
void
542
SerialPort::SetRts( const bool rtsState )
543
SerialPort::SetRts( const bool rtsState )
543
    throw( SerialPort::NotOpen,
544
    throw( SerialPort::NotOpen,
544
           std::runtime_error ) 
545
           std::runtime_error )
545
{
546
{
546
    mSerialPortImpl->SetRts( rtsState ) ;
547
    mSerialPortImpl->SetRts( rtsState ) ;
547
    return ;
548
    return ;
548
}
549
}
549
550
550
bool
551
bool
551
SerialPort::GetRts() const 
552
SerialPort::GetRts() const
552
    throw( SerialPort::NotOpen,
553
    throw( SerialPort::NotOpen,
553
           std::runtime_error ) 
554
           std::runtime_error )
554
{
555
{
555
    return mSerialPortImpl->GetRts() ;
556
    return mSerialPortImpl->GetRts() ;
556
}
557
}
557
558
558
559
559
bool
560
bool
560
SerialPort::GetCts() const 
561
SerialPort::GetCts() const
561
    throw( SerialPort::NotOpen,
562
    throw( SerialPort::NotOpen,
562
           std::runtime_error ) 
563
           std::runtime_error )
563
{
564
{
564
    return mSerialPortImpl->GetCts() ;
565
    return mSerialPortImpl->GetCts() ;
565
}
566
}
566
567
567
bool
568
bool
568
SerialPort::GetDsr() const 
569
SerialPort::GetDsr() const
569
    throw( SerialPort::NotOpen,
570
    throw( SerialPort::NotOpen,
570
           std::runtime_error ) 
571
           std::runtime_error )
571
{
572
{
572
    return mSerialPortImpl->GetDsr() ;
573
    return mSerialPortImpl->GetDsr() ;
573
}
574
}
Lines 1443-1449 Link Here
1443
    throw( SerialPort::NotOpen,
1444
    throw( SerialPort::NotOpen,
1444
           std::runtime_error )
1445
           std::runtime_error )
1445
{
1446
{
1446
    this->SetModemControlLine( TIOCM_DTR, 
1447
    this->SetModemControlLine( TIOCM_DTR,
1447
                               dtrState ) ;
1448
                               dtrState ) ;
1448
    return ;
1449
    return ;
1449
}
1450
}
Lines 1455-1461 Link Here
1455
           std::runtime_error )
1456
           std::runtime_error )
1456
{
1457
{
1457
    return this->GetModemControlLine( TIOCM_DTR ) ;
1458
    return this->GetModemControlLine( TIOCM_DTR ) ;
1458
}    
1459
}
1459
1460
1460
inline
1461
inline
1461
void
1462
void
Lines 1463-1469 Link Here
1463
    throw( SerialPort::NotOpen,
1464
    throw( SerialPort::NotOpen,
1464
           std::runtime_error )
1465
           std::runtime_error )
1465
{
1466
{
1466
    this->SetModemControlLine( TIOCM_RTS, 
1467
    this->SetModemControlLine( TIOCM_RTS,
1467
                               rtsState ) ;
1468
                               rtsState ) ;
1468
    return ;
1469
    return ;
1469
}
1470
}
Lines 1475-1481 Link Here
1475
           std::runtime_error )
1476
           std::runtime_error )
1476
{
1477
{
1477
    return this->GetModemControlLine( TIOCM_RTS ) ;
1478
    return this->GetModemControlLine( TIOCM_RTS ) ;
1478
}    
1479
}
1479
1480
1480
1481
1481
inline
1482
inline
Lines 1485-1491 Link Here
1485
           std::runtime_error )
1486
           std::runtime_error )
1486
{
1487
{
1487
    return this->GetModemControlLine( TIOCM_CTS ) ;
1488
    return this->GetModemControlLine( TIOCM_CTS ) ;
1488
}    
1489
}
1489
1490
1490
1491
1491
inline
1492
inline
Lines 1495-1501 Link Here
1495
           std::runtime_error )
1496
           std::runtime_error )
1496
{
1497
{
1497
    return this->GetModemControlLine( TIOCM_DSR ) ;
1498
    return this->GetModemControlLine( TIOCM_DSR ) ;
1498
}    
1499
}
1499
1500
1500
inline
1501
inline
1501
void
1502
void
Lines 1559-1565 Link Here
1559
    }
1560
    }
1560
    //
1561
    //
1561
    // :TODO: Check to make sure that modemLine is a valid value.
1562
    // :TODO: Check to make sure that modemLine is a valid value.
1562
    // 
1563
    //
1563
    // Set or unset the specified bit according to the value of
1564
    // Set or unset the specified bit according to the value of
1564
    // lineState.
1565
    // lineState.
1565
    //
1566
    //
Lines 1567-1585 Link Here
1567
    if ( true == lineState )
1568
    if ( true == lineState )
1568
    {
1569
    {
1569
        int set_line_mask = modemLine ;
1570
        int set_line_mask = modemLine ;
1570
        ioctl_result = ioctl( mFileDescriptor, 
1571
        ioctl_result = ioctl( mFileDescriptor,
1571
                              TIOCMBIS,
1572
                              TIOCMBIS,
1572
                              &set_line_mask ) ;
1573
                              &set_line_mask ) ;
1573
    }
1574
    }
1574
    else
1575
    else
1575
    {
1576
    {
1576
        int reset_line_mask = modemLine ;
1577
        int reset_line_mask = modemLine ;
1577
        ioctl_result = ioctl( mFileDescriptor, 
1578
        ioctl_result = ioctl( mFileDescriptor,
1578
                              TIOCMBIC,
1579
                              TIOCMBIC,
1579
                              &reset_line_mask ) ;
1580
                              &reset_line_mask ) ;
1580
    }
1581
    }
1581
    //
1582
    //
1582
    // Check for errors. 
1583
    // Check for errors.
1583
    //
1584
    //
1584
    if ( -1 == ioctl_result )
1585
    if ( -1 == ioctl_result )
1585
    {
1586
    {
(-)src/SerialPort.h (-18 / +18 lines)
Lines 21-27 Link Here
21
#define _SerialPort_h_
21
#define _SerialPort_h_
22
22
23
23
24
#include <string>
24
#include <cstring>
25
#include <vector>
25
#include <vector>
26
#include <stdexcept>
26
#include <stdexcept>
27
#include <termios.h>
27
#include <termios.h>
Lines 40-51 Link Here
40
 *
40
 *
41
 * :FIXME: Provide examples of the above potential problem.
41
 * :FIXME: Provide examples of the above potential problem.
42
 *
42
 *
43
 * @todo The current implementation does not check if another process has 
43
 * @todo The current implementation does not check if another process has
44
 * locked the serial port device and does not lock the serial port device after
44
 * locked the serial port device and does not lock the serial port device after
45
 * opening it. This has been observed to cause problems while using this 
45
 * opening it. This has been observed to cause problems while using this
46
 * library while other programs such as minicom are also accessing the same device. 
46
 * library while other programs such as minicom are also accessing the same device.
47
 * It will be useful to lock the serial port device when it is being used by
47
 * It will be useful to lock the serial port device when it is being used by
48
 * this class. 
48
 * this class.
49
 */
49
 */
50
class SerialPort
50
class SerialPort
51
{
51
{
Lines 77-83 Link Here
77
        // B460800 is defined on Linux but not on Mac OS X. What about other
77
        // B460800 is defined on Linux but not on Mac OS X. What about other
78
        // operating systems ?
78
        // operating systems ?
79
        //
79
        //
80
#ifdef __linux__       
80
#ifdef __linux__
81
        BAUD_460800  = B460800,
81
        BAUD_460800  = B460800,
82
#endif
82
#endif
83
        BAUD_DEFAULT = BAUD_57600
83
        BAUD_DEFAULT = BAUD_57600
Lines 416-422 Link Here
416
     * Get the status of the DTR line.
416
     * Get the status of the DTR line.
417
     */
417
     */
418
    bool
418
    bool
419
    GetDtr() const 
419
    GetDtr() const
420
        throw( NotOpen,
420
        throw( NotOpen,
421
               std::runtime_error ) ;
421
               std::runtime_error ) ;
422
422
Lines 432-438 Link Here
432
     * Get the status of the RTS line.
432
     * Get the status of the RTS line.
433
     */
433
     */
434
    bool
434
    bool
435
    GetRts() const 
435
    GetRts() const
436
        throw( NotOpen,
436
        throw( NotOpen,
437
               std::runtime_error ) ;
437
               std::runtime_error ) ;
438
438
Lines 440-448 Link Here
440
    //SetCts( const bool ctsState = true )
440
    //SetCts( const bool ctsState = true )
441
    //    throw( NotOpen,
441
    //    throw( NotOpen,
442
    //           std::runtime_error ) ;
442
    //           std::runtime_error ) ;
443
    
443
444
    bool
444
    bool
445
    GetCts() const 
445
    GetCts() const
446
        throw( NotOpen,
446
        throw( NotOpen,
447
               std::runtime_error ) ;
447
               std::runtime_error ) ;
448
448
Lines 450-479 Link Here
450
    //SetDsr( const bool dsrState = true )
450
    //SetDsr( const bool dsrState = true )
451
    //    throw( NotOpen,
451
    //    throw( NotOpen,
452
    //           std::runtime_error ) ;
452
    //           std::runtime_error ) ;
453
    
453
454
    bool
454
    bool
455
    GetDsr() const 
455
    GetDsr() const
456
        throw( NotOpen,
456
        throw( NotOpen,
457
               std::runtime_error ) ;
457
               std::runtime_error ) ;
458
private:
458
private:
459
	/**
459
	/**
460
	 * Prevent copying of objects of this class by declaring the copy 
460
	 * Prevent copying of objects of this class by declaring the copy
461
     * constructor private. This method is never defined. 
461
     * constructor private. This method is never defined.
462
     */
462
     */
463
    SerialPort( const SerialPort& otherSerialPort ) ;
463
    SerialPort( const SerialPort& otherSerialPort ) ;
464
    
464
465
    /**
465
    /**
466
     * Prevent copying of objects of this class by declaring the assignment
466
     * Prevent copying of objects of this class by declaring the assignment
467
     * operator private. This method is never defined. 
467
     * operator private. This method is never defined.
468
     */
468
     */
469
    SerialPort& operator=(const SerialPort& otherSerialPort ) ;
469
    SerialPort& operator=(const SerialPort& otherSerialPort ) ;
470
    
470
471
    /*
471
    /*
472
     * Forward declaration of the implementation class folowing the
472
     * Forward declaration of the implementation class folowing the
473
     * PImpl idiom.
473
     * PImpl idiom.
474
     */
474
     */
475
    class SerialPortImpl ;
475
    class SerialPortImpl ;
476
    
476
477
    /**
477
    /**
478
     * Pointer to implementation class instance.
478
     * Pointer to implementation class instance.
479
     */
479
     */
(-)src/SerialStream.h (-42 / +42 lines)
Lines 8-14 Link Here
8
#ifndef _SerialStream_h_
8
#ifndef _SerialStream_h_
9
#define _SerialStream_h_
9
#define _SerialStream_h_
10
10
11
#include <string>
11
#include <cstring>
12
#include <fstream>
12
#include <fstream>
13
#include <SerialStreamBuf.h>
13
#include <SerialStreamBuf.h>
14
14
Lines 42-51 Link Here
42
            obtained from <a href="http://www.UNIX-systems.org/">
42
            obtained from <a href="http://www.UNIX-systems.org/">
43
            http://www.UNIX-systems.org/</a>. We will refer to this
43
            http://www.UNIX-systems.org/</a>. We will refer to this
44
            document as SUS-2.
44
            document as SUS-2.
45
	
45
46
            @author $Author: crayzeewulf $ <A HREF="pagey@gnudom.org">Manish P. Pagey</A>
46
            @author $Author: crayzeewulf $ <A HREF="pagey@gnudom.org">Manish P. Pagey</A>
47
            @version $Id: SerialStream.h,v 1.5 2004/05/06 18:32:02 crayzeewulf
47
            @version $Id: SerialStream.h,v 1.5 2004/05/06 18:32:02 crayzeewulf
48
     
48
49
        */
49
        */
50
        class SerialStream : public std::iostream {
50
        class SerialStream : public std::iostream {
51
        public:
51
        public:
Lines 78-88 Link Here
78
                stream is in a good state before using it for any further
78
                stream is in a good state before using it for any further
79
                I/O operations.
79
                I/O operations.
80
80
81
                @param fileName The filename of the serial port. 
81
                @param fileName The filename of the serial port.
82
                @param openMode The openmode for the serial port file. 
82
                @param openMode The openmode for the serial port file.
83
83
84
            */
84
            */
85
            explicit SerialStream( const std::string fileName, 
85
            explicit SerialStream( const std::string fileName,
86
                                   std::ios_base::openmode openMode =
86
                                   std::ios_base::openmode openMode =
87
                                   std::ios::in|std::ios::out) ;
87
                                   std::ios::in|std::ios::out) ;
88
88
Lines 92-103 Link Here
92
92
93
            */
93
            */
94
            explicit SerialStream() ;
94
            explicit SerialStream() ;
95
      
95
96
            /** The destructor. It closes the stream associated with
96
            /** The destructor. It closes the stream associated with
97
                mFileDescriptor. The rest is done by the fstream destructor.
97
                mFileDescriptor. The rest is done by the fstream destructor.
98
	  
98
99
            */
99
            */
100
            virtual ~SerialStream() ; 
100
            virtual ~SerialStream() ;
101
            //@}
101
            //@}
102
102
103
            /** @name Other Public Methods
103
            /** @name Other Public Methods
Lines 107-114 Link Here
107
                s and the specified mode, mode.
107
                s and the specified mode, mode.
108
108
109
            */
109
            */
110
            void Open( const std::string fileName, 
110
            void Open( const std::string fileName,
111
                       std::ios_base::openmode openMode = 
111
                       std::ios_base::openmode openMode =
112
                       std::ios_base::in | std::ios_base::out) ;
112
                       std::ios_base::in | std::ios_base::out) ;
113
113
114
            /** Close the serial port. No communications can occur with the
114
            /** Close the serial port. No communications can occur with the
Lines 122-128 Link Here
122
            */
122
            */
123
            const bool IsOpen() const ;
123
            const bool IsOpen() const ;
124
124
125
            /** Set the baud rate for serial communications. 
125
            /** Set the baud rate for serial communications.
126
126
127
            */
127
            */
128
            void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate ) ;
128
            void SetBaudRate(SerialStreamBuf::BaudRateEnum baudRate ) ;
Lines 130-137 Link Here
130
            /** Get the current baud rate being used for serial
130
            /** Get the current baud rate being used for serial
131
                communication. This routine queries the serial port for its
131
                communication. This routine queries the serial port for its
132
                current settings and returns the baud rate that is being
132
                current settings and returns the baud rate that is being
133
                used by the serial port. 
133
                used by the serial port.
134
	  
134
135
                @return The current baud rate for the serial port.
135
                @return The current baud rate for the serial port.
136
                Note: this is not a constant function because it
136
                Note: this is not a constant function because it
137
                checks to see that it is dealing with a SerialStream
137
                checks to see that it is dealing with a SerialStream
Lines 140-198 Link Here
140
            */
140
            */
141
            const SerialStreamBuf::BaudRateEnum BaudRate() ;
141
            const SerialStreamBuf::BaudRateEnum BaudRate() ;
142
142
143
            /** Set the character size associated with the serial port. 
143
            /** Set the character size associated with the serial port.
144
	  
144
145
            @param size The character size will be set to this value. 
145
            @param size The character size will be set to this value.
146
            */
146
            */
147
            void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ;
147
            void SetCharSize(const SerialStreamBuf::CharSizeEnum charSize ) ;
148
148
149
            /** Get the character size being used for serial communication. 
149
            /** Get the character size being used for serial communication.
150
	 
150
151
            @return The current character size. 
151
            @return The current character size.
152
            */
152
            */
153
            const SerialStreamBuf::CharSizeEnum CharSize() ;
153
            const SerialStreamBuf::CharSizeEnum CharSize() ;
154
154
155
            /** Set the number of stop bits used during serial
155
            /** Set the number of stop bits used during serial
156
                communication. The only valid values are 1 and 2.
156
                communication. The only valid values are 1 and 2.
157
157
158
                @param stop_bits The number of stop bits. (1 or 2). 
158
                @param stop_bits The number of stop bits. (1 or 2).
159
	  
159
160
            */
160
            */
161
            void SetNumOfStopBits(short stop_bits) ;
161
            void SetNumOfStopBits(short stop_bits) ;
162
162
163
            /** Get the number of stop bits being used during serial
163
            /** Get the number of stop bits being used during serial
164
                communication.
164
                communication.
165
	  
165
166
                @return The number of stop bits.  */
166
                @return The number of stop bits.  */
167
            const short NumOfStopBits() ; 
167
            const short NumOfStopBits() ;
168
168
169
            /** Set the parity for serial communication.
169
            /** Set the parity for serial communication.
170
	  
170
171
            @param parity The parity value. 
171
            @param parity The parity value.
172
	  
172
173
            */
173
            */
174
            void SetParity(const SerialStreamBuf::ParityEnum parity) ;
174
            void SetParity(const SerialStreamBuf::ParityEnum parity) ;
175
175
176
            /** Get the current parity setting for the serial port. 
176
            /** Get the current parity setting for the serial port.
177
	  
177
178
            @return The parity setting for the serial port. 
178
            @return The parity setting for the serial port.
179
	  
179
180
            */
180
            */
181
            const SerialStreamBuf::ParityEnum Parity() ;
181
            const SerialStreamBuf::ParityEnum Parity() ;
182
182
183
            /** Use the specified flow control. 
183
            /** Use the specified flow control.
184
184
185
            */
185
            */
186
            void 
186
            void
187
            SetFlowControl(const SerialStreamBuf::FlowControlEnum flow_c) ;
187
            SetFlowControl(const SerialStreamBuf::FlowControlEnum flow_c) ;
188
188
189
            /** Return the current flow control setting. 
189
            /** Return the current flow control setting.
190
190
191
            */
191
            */
192
            const SerialStreamBuf::FlowControlEnum FlowControl() ;
192
            const SerialStreamBuf::FlowControlEnum FlowControl() ;
193
193
194
            /** Set character buffer size.
194
            /** Set character buffer size.
195
                
195
196
            */
196
            */
197
            const short SetVMin( short vtime ) ;
197
            const short SetVMin( short vtime ) ;
198
198
Lines 200-218 Link Here
200
            /** Get current size of character buffer.
200
            /** Get current size of character buffer.
201
                Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A>
201
                Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A>
202
                for more documentation about VTIME and VMIN.
202
                for more documentation about VTIME and VMIN.
203
                
203
204
            */
204
            */
205
            const short VMin() ;
205
            const short VMin() ;
206
206
207
            /** Set character buffer timing in 10th of a second.
207
            /** Set character buffer timing in 10th of a second.
208
                
208
209
            */
209
            */
210
            const short SetVTime( short vtime ) ;
210
            const short SetVTime( short vtime ) ;
211
211
212
            /** Get current timing of character buffer in 10th of a second.
212
            /** Get current timing of character buffer in 10th of a second.
213
                Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A>
213
                Look <A HREF="http://www.unixwiz.net/techtips/termios-vmin-vtime.html">here</A>
214
                for more documentation about VTIME and VMIN.
214
                for more documentation about VTIME and VMIN.
215
                
215
216
            */
216
            */
217
            const short VTime() ;
217
            const short VTime() ;
218
218
Lines 274-280 Link Here
274
274
275
            /* Enable the serial port receiver. This will allow us to read
275
            /* Enable the serial port receiver. This will allow us to read
276
               data from the serial port.
276
               data from the serial port.
277
       
277
278
               @param enable If true then the received will be
278
               @param enable If true then the received will be
279
               enabled. Otherwise it will be disabled.
279
               enabled. Otherwise it will be disabled.
280
280
Lines 284-290 Link Here
284
        } ; // class SerialStream
284
        } ; // class SerialStream
285
285
286
        inline
286
        inline
287
        SerialStream::SerialStream() : 
287
        SerialStream::SerialStream() :
288
          std::iostream(0), mIOBuffer(0) {
288
          std::iostream(0), mIOBuffer(0) {
289
            //
289
            //
290
            // Close the stream
290
            // Close the stream
Lines 294-300 Link Here
294
294
295
        inline
295
        inline
296
        SerialStream::~SerialStream() {
296
        SerialStream::~SerialStream() {
297
            // 
297
            //
298
            // If a SerialStreamBuf is associated with this SerialStream
298
            // If a SerialStreamBuf is associated with this SerialStream
299
            // then we need to destroy it here.
299
            // then we need to destroy it here.
300
            //
300
            //
Lines 304-310 Link Here
304
        }
304
        }
305
305
306
        inline
306
        inline
307
        void 
307
        void
308
        SerialStream::Close() {
308
        SerialStream::Close() {
309
            //
309
            //
310
            // If a SerialStreamBuf is associated with the SerialStream then
310
            // If a SerialStreamBuf is associated with the SerialStream then

Return to bug 163637