- Timestamp:
- 08/29/12 16:52:22 (12 years ago)
- 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 86 86 87 87 public: 88 89 virtual~LxSerial();90 virtualbool port_open(const std::string& portname, LxSerial::PortType port_type); // open serial port. If overridden, make sure you set s_port_name!!91 virtualbool 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(); 92 92 std::string& get_port_name(); 93 virtualbool set_speed(LxSerial::PortSpeed baudrate ); // enumerated94 virtualbool set_speed_int(const int baudrate); // Set speed by integer value directly - UNPROTECTED!95 void 96 virtualbool port_close();97 virtual intport_read(unsigned char* buffer, int numBytes) const;98 virtualint port_read(unsigned char* buffer, int numBytes, int seconds, int microseconds);99 virtual intport_write(unsigned char* buffer, int numBytes);100 v irtual void flush_buffer(); // flush input and output buffers93 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 101 101 102 102 }; -
trunk/shared_serial/include/shared_serial/client.h
r8 r12 4 4 #include <ros/ros.h> 5 5 6 /// shared_serial client interface class. 6 7 class SerialClient 7 8 { 8 9 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. 17 18 18 19 public: 20 /// Initialize interface. 21 /** \param path Path to server node. */ 19 22 void init(const char *path="/comm"); 20 23 24 /// Lock serial port. 25 /** 26 * \param timeout Lock time in [s] 27 * \returns Socket identifier. 28 */ 21 29 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 */ 22 39 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 */ 23 51 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 */ 24 65 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 */ 25 75 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 */ 26 82 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 */ 27 90 void flush(int socket, float timeout); 28 91 }; -
trunk/shared_serial/mainpage.dox
r8 r12 12 12 \section codeapi Code API 13 13 14 The API is internal and not meant to be used. See the <a href="index-msg.html">message and service documentation</a> instead.14 The 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>. 15 15 16 16 <!-- -
trunk/shared_serial/src/LxSerial.cpp
r8 r12 455 455 LxSerial::~LxSerial() 456 456 { 457 // Warn when you forgot to close the port before destruction.458 // We CANNOT call port_close() here, because port_close is a virtual function459 // and virtual functions cannot be called in constructors and destructors.460 457 if (hPort != INVALID_DEVICE_HANDLE) 461 p rintf("[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 116 116 ROS_ASSERT(nh_.getParam("port_type", port_type)); 117 117 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); 119 119 120 120 if (port_type == "RS232")
Note: See TracChangeset
for help on using the changeset viewer.