Public Member Functions | Private Attributes
Rs232 Class Reference

#include <rs232.h>

List of all members.

Public Member Functions

int askToRS232 (char *command, int commandsize, char *response)
 sends a question to the serial port and gets its response finished with "CRLF". The response is stored in a string
int askToSerial (char *command, int commandSize, char *response, int responseSize)
 sends a question to the serial port and gets its response. The response is stored in a string
int endCommunication ()
 Ends the communication closing the file descriptor and the removes the semaphore.
int initCommunication (int baudrate, char *serialDevice, char *semFile)
 Function that initializes the communication with the serial port.
int readFromRS232 (char *buff)
 reads frames finished with "CRLF" from the serial port. After reading it, the incoming message is stored in a string
int readSerial (char *response, int responseSize)
 reads form the serial port the number of characters specified by responseSize. After reading it, the incomming message is stored in a string
long int timeDifferenceMsec (struct timeval *before, struct timeval *after)
 Returns a time difference in milliseconds.
int writeToRS232 (char *command, int commandSize)
 writes (sends) a command to the serial port

Private Attributes

int _RSd
int _semID

Detailed Description

Definition at line 55 of file rs232.h.


Member Function Documentation

int Rs232::askToRS232 ( char *  command,
int  commandsize,
char *  response 
)

sends a question to the serial port and gets its response finished with "CRLF". The response is stored in a string

This function sends a command or a question to the serial port and immediately reads the response produced by the device which is connected to the other side of the serial port. It is better to use askToRS232() function rather the combination of writeToRS232() and readFromRS232() functions. The reason of that is because using the other two functions the semaphore is reserved and freed in each function. When you expect an immediate answer from the driver it is safer to maintain the semaphore open until you have read this response.

Parameters:
commandis the string used to send the question/command to the serial port
commandSizeis the size in bytes (chars) of the question/command sent to the serial port
responsestring where the output incoming from the serial port is stored
Returns:
ERR_NOERR if there aren't any problems
ERR_SEM in case of a semaphore related error
ERR_WRI if there is an error when writing in the serial port file descriptor
ERR_READ if there is an error when reading from the serial port
ERR_TIMEOUT if the time available for this operation (defined in SP_READ_TIMEOUT) expires

Number of bytes available at the serial port

Definition at line 225 of file rs232.cpp.

int Rs232::askToSerial ( char *  command,
int  commandSize,
char *  response,
int  responseSize 
)

sends a question to the serial port and gets its response. The response is stored in a string

This function sends a command or a question to the serial port and immediately reads the response produced by the device wich is connected to the other side of the serial port. It is better to use askToRS232() function rather the combination of writeToRS232() and readFromRS232() functions. The reason of that is because using the other two functions the semaphore is reserved and freed in each function. When you expect an immediate answer from the driver it is safer to maintain the semaphore open until you have read this response.

Parameters:
commandis the string used to send the question/command to the serial port
commandSizeis the size in bytes (chars) of the question/command sent to the serial port
responsestring where the output incoming from the serial port is stored
responseSizeis the size in bytes (chars) of the expected response
Returns:
ERR_NOERR if there aren't any problems
ERR_SEM in case of a semaphore related error
ERR_WRI if there is an error when writing in the serial port file descriptor
ERR_READ if there is an error when reading from the serial port
ERR_TIMEOUT if the time available for this operation (defined in SP_READ_TIMEOUT) expires
i number of characters read

Number of bytes available at the serial port

Definition at line 347 of file rs232.cpp.

Ends the communication closing the file descriptor and the removes the semaphore.

Definition at line 139 of file rs232.cpp.

int Rs232::initCommunication ( int  baudrate,
char *  serialDevice,
char *  semFile 
)

Function that initializes the communication with the serial port.

Before that creates a semaphore to forbid simultaneous access to the serial port

Parameters:
baudrateserial port communication speed
serialDeviceserial device file name
semFilesemaphore file to make the semKey
Returns:
-1 if could not configure serial port
-2 if could not open serial device
-3 if could not set zero motorSensor
-4 if there is any problem with semaphores

change this to use a rs232_t and a semaphore_t

Used to catch errors from functions

Definition at line 33 of file rs232.cpp.

int Rs232::readFromRS232 ( char *  buff)

reads frames finished with "CRLF" from the serial port. After reading it, the incoming message is stored in a string

Parameters:
buffstring where the output from the serial port is stored
Returns:
ERR_NOERR if there aren't any problems
ERR_SEM in case of a semaphore related error
ERR_READ if there is an error when reading from the serial port file descriptor
ERR_TIMEOUT in case of a reading timeout

Number of bytes available at the serial port

Definition at line 170 of file rs232.cpp.

int Rs232::readSerial ( char *  response,
int  responseSize 
)

reads form the serial port the number of characters specified by responseSize. After reading it, the incomming message is stored in a string

Functions to use with protocols not ended with special characters.

Parameters:
responsestring where the output from the serial port is stored
responseSizebytes to be read
Returns:
ERR_NOERR if there aren't any problems
ERR_SEM in case of a semaphore related error
ERR_READ if there is an error when reading from the serial port file descriptor
ERR_TIMEOUT in case of a reading timeout
i number of characters read

Number of bytes available at the serial port

Definition at line 291 of file rs232.cpp.

long int Rs232::timeDifferenceMsec ( struct timeval *  before,
struct timeval *  after 
)

Returns a time difference in milliseconds.

Parameters:
beforeis the reference time value to compare
afteris the time wich we want to compare
Returns:
the diference between before and after in milliseconds

Error control here

Definition at line 410 of file rs232.cpp.

int Rs232::writeToRS232 ( char *  command,
int  commandSize 
)

writes (sends) a command to the serial port

Parameters:
commandThe string where the command is stored
commandSizeis the number of chars of the command string
Returns:
ERR_NOERR if everything is correct
ERR_SEM if there is an error waiting the semaphore
ERR_WRI if there is an error writing to the serial port file descriptor

Definition at line 150 of file rs232.cpp.


Member Data Documentation

int Rs232::_RSd [private]

Definition at line 175 of file rs232.h.

int Rs232::_semID [private]

Definition at line 175 of file rs232.h.


The documentation for this class was generated from the following files:


sr_communications
Author(s): Raul Perula-Martinez , Victor Gonzalez
autogenerated on Wed Aug 26 2015 16:26:48