#include #include #include #include #include #include "vdefinitions.h" #include "vrs232.h" /* VertexRSI_command function that passed the command to the VertexRSI ACU for intrepretation. The argruements are file_descriptor = device opened by rs232_openport function that describes the serial device where the VertexRSI ACU is found. command = pointer to the string containing the command that will be passed to the VertexRSI command. The command should not have the terminating "CR". This will be appended to the string in the function automatically. responce = array of string pointers that will contain the reply from the VertexRSI ACU. If response==NULL, response_buffer_length==0, or number_of_terminators==0 then no reply is expected. response_buffer_length = length of the reply buffer string. This is the maximum size of the reply buffer any string beyond this will not be read in. number_of_terminators = number of "\r" (carrage returns) expected from the reply of the VertexRSI ACU. This is to allow for reading of multiple line replies from the VRSI ACU. Initial version of this software was written by Robert C. Berrington. VertexRSI version added by James Weger. Please contact for questions regarding the code at rberring@uwyo.edu or weger@uwyo.edu, as appropriate. */ int vrsi_command(int file_descriptor, char *command, char **response, int response_buffer_length, int number_of_terminators) { char c='\0'; int i; int j; int max_attempts=1; int status=FAILURE; size_t bytes_read; unsigned int sleep_s=1; /* seconds to sleep */ char *command_with_terminator=NULL; /* Test to make sure the arguements passed into the VertexRSI_command function are correct */ if (command == NULL) { fprintf(stderr, "'command' buffer pointer passed was NULL. No command sent.\n"); fflush(stderr); return NULL_ARGUEMENT; } if ((response_buffer_length>0) && (response==NULL)) { fprintf(stderr, "'response' buffer pointer passed was NULL with positive expected buffer length!\n"); fflush(stderr); return NULL_ARGUEMENT; } if (number_of_terminators==0) { fprintf(stderr, "*WARNING* expected number of terminators was %d! No reply expected\n", number_of_terminators); fflush(stderr); } /* Allocate the memory required for the string that will include the terminator sequence for the VertexRSI command. This is the will be the string that will actually be sent to the VertexRSI ACU */ if ((command_with_terminator = calloc(strlen(command)+2, sizeof(char)))==NULL) { fprintf(stderr, "*ERROR* failed to allocate command buffer!"); fflush(stderr); return FAILURE; } strcpy(command_with_terminator, command); strcat(command_with_terminator, "\r\0"); /* Append end of command sequence */ /* #ifdef DEBUG */ /* Just to show that we got this far. */ printf("This command was received, %s\n", command_with_terminator); /* #endif */ status = rs232_putline(file_descriptor,command_with_terminator); free(command_with_terminator); if (status != SUCCESS) { return status; } /* Get the response, if one is expected. */ if ( (response != NULL) || (response_buffer_length != 0) || (number_of_terminators != 0)) { for (j=0; j= max_attempts) { if (status != SUCCESS) { fprintf(stderr, "Failed at attempt to discard unread characters"); fflush(stderr); return FAILURE; } } } } return SUCCESS; } /* function vrsi_command */