MATLAB Answers

0

Can I read data from a serial port and a data acquisition board simulataneously using the Data Acquisition Toolbox 2.14 (R2009a)?

I have two separate devices: one connected to the serial port and the other is a National Instruments data acquisition board. I would like to know if it is possible for me to read data from both devices simultaneously.

2 Answers

Answer by MathWorks Support Team on 15 Nov 2016
 Accepted Answer

It is possible to read data simultaneously from a serial port and a data acquisition board using the Data Acquisition Toolbox 2.14 (R2009a). The "StartFcn" property of the ANALOGINPUT object can be used to initiate reading from the SERIAL port. The code snippet below creates an ANALOGINPUT object and performs the data acquisition:
 
%Create and open serial object
s = serial('COM1','OutputBufferSize',4096)
fopen(s)
% Create analoginput object
ai = analoginput('nidaq','Dev1');
set(ai,'StartFcn',{@myserial,s});
addchannel(ai,0,{'chan1'})
% Start reading data from analoginput
start(ai)
% Retrieve data from analoginput object
getdata(ai)
The Callback function MYSERIAL, used with the StartFcn event in the code above, is shown below and contains the MATLAB code to read data from the serial port.
 
function myserial(obj, event, s)
%Read data from Serial. This will vary on how you want to retrieve the data
serialdata = fread(s,1)
set(obj,'UserData',serialdata)
For more information about events and callback functions, please check the following link:

  0 Comments

Sign in to comment.


Answer by Rajeev Yadav on 10 Mar 2014

I have two DAQ boards and one arduino board. I want to initiate simultaneous AI from the two DAQ boards (NI boards) and also from the Arduino board via serial port. My concern is how to initiate them. I also want to do a DI/DO using the Arduino board while the AI is bing done by NI boards. The problem can be restated as : NI boards perform AI simulatenously while Arduino board does user interactive operations. Is it possible to do with the DAQ toolbox? Can you please give me an example?
Thanks RY

  0 Comments

Sign in to comment.