function [ out ] = serialTest(inp_str,PORT,BAUD)
%This is a function that takes an input string send it to the Serial port 
%and receives from the serial port what the other device is sending and
%then display the output it received as a string 
%This component is authord by Akram Ahmed on September 9, 2014 and can be
%distributed and used for non profit purposes.
%The inputs are:
%   inp_str : this should be a string
%   PORT    : this is the communication port on which the communication 
%             will be establised
%   BAUD    : This is the Baud Rate you want to communicate with

    len = length(inp_str);
    buffer_size = len;
    sp = serial(PORT,'BaudRate',BAUD,'InputBufferSize',buffer_size);
    fopen(sp);
    %Ensure serial port can be openned
    if(strcmp(sp.Status,'closed'))
        delete(sp);
        clear sp;
        delete(instrfindall);
        error('Error: Unable to open serial port');
    end
    for i = 1:1:len;
        fwrite(sp,inp_str(1,i),'uint8');
    end
    recData = zeros(1,len);
    cnt = 1;
    while(sp.BytesAvailable > 0)
        recData(cnt) = fread(sp,1,'uint8');
        cnt = cnt +1;
    end
    out = char(recData);
    fclose(sp);
    delete(sp);
    clear sp;
    delete(instrfindall);
end

