Code covered by the BSD License  

Highlights from
MPC555 Motor Control Function Blockset

MPC555 Motor Control Function Blockset

by

 

20 Mar 2006 (Updated )

Additional I/O blocks for MPC555 target - specifically targetting TPU functionality

SerialHostEnd(serialporthandle, SerDataDefinition)
function SerDataCapturedValue = SerialHostEnd(serialporthandle, SerDataDefinition)

SerDataCapturedValue = zeros(1, length(SerDataDefinition));
SerDataCaptured = zeros(1, length(SerDataDefinition));
SerDataOnes = ones(1, length(SerDataDefinition));

% Persistently repeat using fscanf until all the data that was required has
% been captured.
while ~isequal(SerDataCaptured, SerDataOnes)
    % Scan the serial port to check if new data has been acquired
    S = fscanf(serialporthandle);
    if length(S)<1
        SerDataCapturedValue = zeros(1, length(SerDataDefinition));
        break;
    end
    % If the data is of a sensible length
    if length(S)>=9
        % Get the ID of the data in HEX
        dataID = S(2:5);
        % Get the value of the data in HEX
        dataValue = S(7:10);
        
        
        % This TRY/CATCH is used to ensure that the data can be converted
        % from hex to decimal without throwing an error.  Otherwise write
        % it off as invalid data
        try
            hex2dec(dataID);
            hex2dec(dataValue);
            validdataID = true;
        catch
            validdataID = false;
        end
        
        % If the data is valid, and the ID is within a sensible range
        if validdataID && (hex2dec(dataID) >= 0) && (hex2dec(dataID) <= length(SerDataDefinition))
           % Take a copy of the captured value in the appropriate output
           % structure
           SerDataCapturedValue(hex2dec(dataID)+1) = hex2dec(dataValue);
           % Mark the data as captured
           SerDataCaptured(hex2dec(dataID)+1) = 1;
        end
    end
end
end

Contact us