Changeset 12 for trunk


Ignore:
Timestamp:
08/29/12 16:52:22 (12 years ago)
Author:
wcaarls
Message:

Updated shared_serial to revision 1017

Location:
trunk/shared_serial
Files:
1 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/shared_serial/include/shared_serial/LxSerial.h

    r8 r12  
    8686
    8787        public:
    88                                                 LxSerial();
    89                 virtual                  ~LxSerial();
    90                 virtual bool    port_open(const std::string& portname, LxSerial::PortType port_type);   // open serial port. If overridden, make sure you set s_port_name!!
    91                 virtual bool    is_port_open();
     88                        LxSerial();
     89                         ~LxSerial();
     90                bool    port_open(const std::string& portname, LxSerial::PortType port_type);   // open serial port. If overridden, make sure you set s_port_name!!
     91                bool    is_port_open();
    9292                std::string&    get_port_name();
    93                 virtual bool    set_speed(LxSerial::PortSpeed baudrate );                                               // enumerated
    94                 virtual bool    set_speed_int(const int baudrate);      // Set speed by integer value directly - UNPROTECTED!
    95                 void                    set_clear_echo(bool clear);                                                                             // clear echoed charackters from input and detect collisions on write
    96                 virtual bool    port_close();
    97                 virtual int             port_read(unsigned char* buffer, int numBytes) const;
    98                 virtual int     port_read(unsigned char* buffer, int numBytes, int seconds, int microseconds);
    99                 virtual int             port_write(unsigned char* buffer, int numBytes);
    100                 virtual void    flush_buffer();                                                                                                 // flush input and output buffers
     93                bool    set_speed(LxSerial::PortSpeed baudrate );                                               // enumerated
     94                bool    set_speed_int(const int baudrate);      // Set speed by integer value directly - UNPROTECTED!
     95                void    set_clear_echo(bool clear);                                                                             // clear echoed charackters from input and detect collisions on write
     96                bool    port_close();
     97                int     port_read(unsigned char* buffer, int numBytes) const;
     98                int     port_read(unsigned char* buffer, int numBytes, int seconds, int microseconds);
     99                int     port_write(unsigned char* buffer, int numBytes);
     100                void    flush_buffer();                                                                                                 // flush input and output buffers
    101101
    102102};
  • trunk/shared_serial/include/shared_serial/client.h

    r8 r12  
    44#include <ros/ros.h>
    55
     6/// shared_serial client interface class.
    67class SerialClient
    78{
    89  protected:
    9     ros::NodeHandle nh_;
    10     ros::ServiceClient connect_service_;
    11     ros::ServiceClient sendto_service_;
    12     ros::ServiceClient recv_service_;
    13     ros::ServiceClient sendrecv_service_;
    14     ros::Publisher     send_topic_;
    15     ros::Publisher     close_topic_;
    16     ros::Publisher     flush_topic_;
     10    ros::NodeHandle nh_;                  ///< ROS node handle.
     11    ros::ServiceClient connect_service_;  ///< Service client for connect function.
     12    ros::ServiceClient sendto_service_;   ///< Service client for sendto function.
     13    ros::ServiceClient recv_service_;     ///< Service client for recv function.
     14    ros::ServiceClient sendrecv_service_; ///< Service client for sendrecv function.
     15    ros::Publisher     send_topic_;       ///< Publisher for send function.
     16    ros::Publisher     close_topic_;      ///< Published for close function.
     17    ros::Publisher     flush_topic_;      ///< Publisher for flush function.
    1718
    1819  public:
     20    /// Initialize interface.
     21    /** \param path Path to server node. */
    1922    void init(const char *path="/comm");
    2023
     24    /// Lock serial port.
     25    /**
     26     * \param timeout Lock time in [s]
     27     * \returns Socket identifier.
     28     */
    2129    int connect(float timeout);
     30   
     31    /// Send data over serial port.
     32    /**
     33     * \param socket Socket identifier (when 0, the port is locked first).
     34     * \param data Data to send.
     35     * \param length Length of \c data parameter.
     36     * \param timeout Lock time in [s].
     37     * \returns Socket identifier.
     38     */
    2239    int sendto(int socket, const unsigned char *data, size_t length, float timeout);
     40   
     41    /// Receive data from serial port.
     42    /**
     43     * \param sock Socket identifier (when 0, the port is locked first).
     44     * \param length Length of data to receive.
     45     * \param recv_timeout Time to wait for data in [s].
     46     * \param sock_timeout Lock time in [s].
     47     * \param data Data buffer, at least \c length bytes long.
     48     * \param[out] data_length Number of bytes received.
     49     * \returns Socket identifier.
     50     */
    2351    int recv(int socket, int length, float recv_timeout, float sock_timeout, unsigned char *data, size_t *data_length);
     52   
     53    /// Coalesced send and receive.
     54    /**
     55     * \param socket Socket identifier (when 0, the port is locked first).
     56     * \param send_data Data to send.
     57     * \param send_length Length of \c send_data parameter in bytes.
     58     * \param recv_length Length of data to receive.
     59     * \param recv_timeout Time to wait for data in [s].
     60     * \param sock_timeout Lock time in [s].
     61     * \param recv_data Receive data buffer, at least \c recv_length bytes long.
     62     * \param[out] recv_data_length Number of bytes received.
     63     * \returns Socket identifier.
     64     */
    2465    int sendrecv(int socket, const unsigned char *send_data, size_t send_length, size_t recv_length, float recv_timeout, float sock_timeout, unsigned char *recv_data, size_t *recv_data_length);
     66   
     67    /// Send data over already locked serial port.
     68    /**
     69     * \param socket Socket identifier.
     70     * \param data Data to send.
     71     * \param length Length of \c data parameter in bytes.
     72     * \param timeout Lock time in [s].
     73     * \note This function is asynchronous.
     74     */
    2575    void send(int socket, const unsigned char *data, size_t length, float timeout);
     76   
     77    /// Unlock serial port.
     78    /**
     79     * \param socket Socket identifier.
     80     * \note This function is asynchronous.
     81     */
    2682    void close(int socket);
     83   
     84    /// Flush serial port.
     85    /**
     86     * \param socket Socket identifier.
     87     * \param timeout Lock time in [s].
     88     * \note This function is asynchronous.
     89     */
    2790    void flush(int socket, float timeout);
    2891};
  • trunk/shared_serial/mainpage.dox

    r8 r12  
    1212\section codeapi Code API
    1313
    14 The API is internal and not meant to be used. See the <a href="index-msg.html">message and service documentation</a> instead.
     14The client API is a single class, called SerialClient. You can also use the messages and services defined in the <a href="index-msg.html">message and service documentation</a>.
    1515
    1616<!--
  • trunk/shared_serial/src/LxSerial.cpp

    r8 r12  
    455455LxSerial::~LxSerial()
    456456{
    457         // Warn when you forgot to close the port before destruction.
    458         // We CANNOT call port_close() here, because port_close is a virtual function
    459         // and virtual functions cannot be called in constructors and destructors.
    460457        if (hPort != INVALID_DEVICE_HANDLE)
    461                 printf("[LxSerial] Warning: you didn't call port_close before calling the destructor.\n");
    462 }
     458                port_close();
     459}
  • trunk/shared_serial/src/server.cpp

    r8 r12  
    116116  ROS_ASSERT(nh_.getParam("port_type", port_type));
    117117  ROS_ASSERT(nh_.getParam("baud_rate", baud_rate));
    118   nh_.param<double>("watchdog_interval", watchdog_interval, 1);
     118  nh_.param<double>("watchdog_interval", watchdog_interval, 10);
    119119
    120120  if (port_type == "RS232")
Note: See TracChangeset for help on using the changeset viewer.