APM2 Simulink Blockset
13 Nov 2012
Simulink blockset for use with the ArduPilot Mega 2.0 hardware. Includes blocks to read external rad
classdef Communicator < rtw.connectivity.RtIOStreamHostCommunicator
%COMMUNICATOR implements a host-side communicator for Arduino
% See also RTW.CONNECTIVITY.RTIOSTREAMHOSTCOMMUNICATOR
% Copyright 2007-2010 The MathWorks, Inc.
function this = Communicator(componentArgs, ...
% This method simply passes all the arguments to the
% superclass constructor
(componentArgs, launcher, rtiostreamLib);
% This method is called after host machine has opened a serial
% connection with the target but before communications (e.g. PIL
% protocol have taken place). Opening the serial connection
% causes the Arduino target to reset. The purpose of this method
% call is to wait until the reset of the target is complete. To
% check if reset is complete, we must wait for a string of data
% that is transmitted by the target with the target's implementation
% of rtIOStreamOpen. When this string is received, we know that
% the target reset is complete and we can start using the serial
% connection to communicate with it.
error(nargchk(1, 1, nargin, 'struct'));
timeout = 5;
delay = 0;
deltaT = 0.1;
dataLength = 0;
while dataLength==0 && (delay <= timeout)
[errorCode, recvdData, dataLength] = rtiostream_wrapper...
delay = delay + deltaT;
'Target must transmit byte indicating startup is complete');
% Non-receipt of the expected data may occur if the target reset
% completes before the host is ready to receive the data; this
% is not an error so it is safe to continue even if no data was