% /***********************************************************************
%
% * Company: TATA ELXSI LIMITED
%
% * File Name: serailreadscript.m
%
% * Author : Nitin S
%
% * Version : 0.0.1
%
% * Description: This script performs the serial read operation using a serial object already connected
%
% * Date :3/08/2005
%
% * Customer Bug No./ CMF No. : NA
%
% * Brief description of the fix/enhancement: NA
%
% ***********************************************************************/
%Asynchornous continuous or Auto mode
serobj ; % Is the serobj which is already available
set(serobj, 'ReadAsyncMode', 'Continuous') ; % set the asynchronous mode to continuous by default it is continuous
set(serobj, 'Timeout', 1) ; % Specify timeout for read operation
serobj.BytesAvailable % Shows the number of bytes in input buffer
ret1 = fscanf(serobj, '%d', [1,1]) ; % reads 1 data byte and interpret as integer value
serobj.ValuesReceived
ret2 = fscanf(serobj, '%f', [1,4]) ; % reads 4 bytes and interprets it as a float value
serobj.ValuesReceived
ret3 = fscanf(serobj, '%s', [1,4]) ; % reads string
serobj.ValuesReceived
ret4 = fscanf(serobj, '%c', [1,1]) ; % reads a 1 byte and interpret it as a character
serobj.ValuesReceived
ret5 = fgetl(serobj) ; % reads till terminator
serobj.ValuesReceived
%Asynchornous continuous or manual mode
set(serobj, 'ReadAsyncMode', 'manual') ; % set the asynchronous mode to manual
% Bytes wont be read automatically from port
serobj.BytesAvailable
%Give sufficient value for time out now if required
readasync(serobj, 50) ; % Read 50 bytes from device and store in input buffer
serobj.BytesAvailable
ret1 = fscanf(serobj, '%d', [1,1]) ; % reads 1 data byte and interpret as integer value
serobj.ValuesReceived
ret2 = fscanf(serobj, '%f', [1,4]) ; % reads 4 bytes and interprets it as a float value
serobj.ValuesReceived