#include <rs232.h>
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 |
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.
command | is the string used to send the question/command to the serial port |
commandSize | is the size in bytes (chars) of the question/command sent to the serial port |
response | string where the output incoming from the serial port is stored |
Number of bytes available at the serial port
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.
command | is the string used to send the question/command to the serial port |
commandSize | is the size in bytes (chars) of the question/command sent to the serial port |
response | string where the output incoming from the serial port is stored |
responseSize | is the size in bytes (chars) of the expected response |
Number of bytes available at the serial port
int Rs232::endCommunication | ( | ) |
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
baudrate | serial port communication speed |
serialDevice | serial device file name |
semFile | semaphore file to make the semKey |
change this to use a rs232_t and a semaphore_t
Used to catch errors from functions
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
buff | string where the output from the serial port is stored |
Number of bytes available at the serial port
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.
response | string where the output from the serial port is stored |
responseSize | bytes to be read |
Number of bytes available at the serial port
long int Rs232::timeDifferenceMsec | ( | struct timeval * | before, |
struct timeval * | after | ||
) |
int Rs232::writeToRS232 | ( | char * | command, |
int | commandSize | ||
) |
writes (sends) a command to the serial port
command | The string where the command is stored |
commandSize | is the number of chars of the command string |
int Rs232::_RSd [private] |
int Rs232::_semID [private] |