function [text, numbers] = GetBS2NumbersAndText(rows, columns, port_number) % Connects to the BS2 and gets the numbers and text from it % % Synopsis: [text, numbers] = GetBS2NumbersAndText(rows, columns, port) % % input: rows = (required) The number of rows transfered by the % BS2 terminal. % columns = (required) The number of columns transfered by the % BS2 terminal. % port = (required) The COM port that the BS2 is connected to. % example: 'COM1' % % output: text = the column headings transfered by the BS2. % numbers = the numerical information transfered by the BS2. % % Also displays the information about the serial port. % % Notes: The informaition transfered by the BS2 modual must consist of a % one lined message sent followed by an rows X columns matrix of % numerical data. % port = ['COM', num2str(port_number)]; s = serial(port); % Select COM port fopen(s) % Open COM port for reading [message, leangth] = fscanf(s); %Recived lone LF from Boe-Bot % Repeate the while loop below untill information is being sent. When there is % information being sent its length will always be two or greater. x is % used because sometimes a stable communication is not established (due to % an inproper connection, falty coding, etc.) so x will keep the loop from % repeating infinitly in that case. while leangth < 2; x = 0; x = x + 1; if x == 30; leangth = 30; end [message, leangth] = fscanf(s); %Recived text from Boe-Bot end text1_char = message; text(1,1) = cellstr(text1_char); for z = 2:(columns); text_char = fscanf(s); %Recived text from Boe-Bot text(z,1) = cellstr(text_char); end for x = 1:rows; data{x,1} = fscanf(s); end fclose(s) delete(s) clear s % converts the data character matrix into the numerical matrix numbers. numbers = BS2NumberConverter(rows, columns, data);