Go to the documentation of this file.00001
00035 #include <stdio.h>
00036 #include "sr_communications/serial_port/rs232.h"
00037
00038 #define DEF_SERIAL_PORT_FILE "/dev/brazo_derecho"
00039 #define DEF_SEMFILE "semfile.sem"
00040
00041
00042 #define DEFAULT_COMMAND "POS\n\r"
00043
00044 int main(int argc, char **argv)
00045 {
00046 Rs232 rs;
00047
00048 char spFile[SP_MAX_FILENAME_SIZE];
00049 char command[SP_MSG_SIZE], response[SP_MSG_SIZE];
00050
00051 semaphore_t sem;
00052
00053 int baud;
00054
00055 sprintf(sem.semFile, DEF_SEMFILE);
00056 sprintf(spFile, DEF_SERIAL_PORT_FILE);
00057
00058 printf("Semaphore file: %s\n", sem.semFile);
00059 printf("Serial port file: %s\n", spFile);
00060
00061 printf("Initializing the communication with the serial port...\n");
00062 if (rs.initCommunication(baud, spFile, sem.semFile) < ERR_NOERR) {
00063 perror("Error in init communication\n");
00064 exit(-1);
00065 }
00066
00067 sprintf(command, DEFAULT_COMMAND);
00068 printf("Sending command through the serial port...\n");
00069 if (rs.writeToRS232(command, strlen(command)) < ERR_NOERR) {
00070 perror("Error writing in the serial port\n");
00071 exit(-1);
00072 }
00073
00074 printf("Comand sent. Now reading the response....\n");
00075 if (rs.readFromRS232(response) < ERR_NOERR) {
00076 perror("Error reading from the serial port\n");
00077 exit(-1);
00078 }
00079
00080 printf("Response received.\n");
00081 printf("The command was: %s\n", command);
00082 printf("And the received response was: %s\n", response);
00083 printf("\n");
00084
00085 printf("Trying again, but this time using askToRS232 function.\n");
00086 if (rs.askToRS232(command, strlen(command), response) < ERR_NOERR) {
00087 perror("Error asking to the serial port\n");
00088 exit(-1);
00089 }
00090
00091 printf("Question sent and response received.\n");
00092 printf("The command was: %s\n", command);
00093 printf("And the received response was: %s\n", response);
00094 printf("\n");
00095
00096 return 0;
00097 }