SerialDevice.h
Go to the documentation of this file.
00001 /*
00002 *  Copyright (c) 2012, Robotnik Automation, SLL
00003 * 
00004 *   This file is part of sick-s3000-ros-pkg.
00005 *
00006 *   sick-s3000-ros-pkg is free software: you can redistribute it and/or modify
00007 *   it under the terms of the GNU General Public License as published by
00008 *   the Free Software Foundation, either version 3 of the License, or
00009 *   (at your option) any later version.
00010 *
00011 *   This program is distributed in the hope that it will be useful,
00012 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *   GNU General Public License for more details.
00015 *
00016 *   You should have received a copy of the GNU General Public License
00017 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 *
00019 */
00020 
00031 #ifndef __SERIALDEV_H
00032 #define __SERIALDEV_H
00033         
00034 #include <stdio.h>
00035 
00036 #define SERIAL_OK                               0
00037 #define SERIAL_ERROR                            -2
00038 
00039 #define BUFFER                                  254
00040 #define DEFAULT_PORT                            "/dev/ttyS1"
00041 #define DEFAULT_TRANSFERRATE                    19200
00042 #define DEFAULT_PARITY                          "odd" //"even" "odd" "none"
00043 #define DEFAULT_SIZE_ARRAY                      128
00044 #define DEFAULT_DATA_SIZE                       7
00045 
00046 class SerialDevice{
00047 
00048 private:        
00052         int fd;
00053         //
00054         bool bReady;    
00055         //
00056         unsigned char SendBuf[BUFFER];          
00057         //
00058         unsigned char RecBuf[BUFFER];
00059         //Device's name
00060         char cDevice[DEFAULT_SIZE_ARRAY];       
00061         //Parity for input and output: EVEN, ODD, NONE
00062         char cParity[DEFAULT_SIZE_ARRAY];       
00063         //BaudRate: 9600, 19200, 38400, 115200
00064         int iBaudRate;
00065         //Character size mask. Values are CS5, CS6, CS7, or CS8.
00066         int iBitDataSize;
00067         //Entrada canónica-> La entrada canónica es orientada a línea. Los caracteres se meten en un buffer hasta recibir un CR o LF.
00068         bool bCanon;
00069         
00070 public:
00071         // Public Constructor
00072         SerialDevice(void);
00073         // Public Constructor
00074         SerialDevice(const char *device, int baudrate,const char *parity, int datasize);        
00075         // Public Destructor
00076         ~SerialDevice(void);    
00077         int OpenPort1(void);
00078         int OpenPort2(void);
00079         // Closes serial port
00080         int ClosePort();
00081         // Receive commands from SerialDevice
00082         // @return number of read bytes
00083         int ReceiveMessage(char *msg);
00084         // Send commands to the SerialDevice
00085         // @return number of sent bytes 
00086         int SendMessage(char *msg, int length);
00087         //int SendMessage(char *msg);   
00088         int WritePort(char *chars, int length);
00089         int WritePort(char *chars, int *written_bytes, int length);     // Importat del SerialDevice amb Component      
00090         int ReadPort(char *result);     
00091         int ReadPort(char *result, int num_bytes);
00092         int ReadPort(char *result, int *read_bytes, int num_bytes);     // Importat del SerialDevice amb Component
00094         int Flush();    
00096         char *GetDevice();
00098         void SetCanonicalInput(bool value);
00099         
00100 private:
00101         
00108         int InitPort(void);
00109         int GetBaud(void);
00111         int SetTermSpeed(int speed);
00112 
00113 };
00114 
00115 #endif


s3000_laser
Author(s): Román Navarro
autogenerated on Wed Sep 2 2015 11:43:29