Serial Port as a property of an object of a class
4 views (last 30 days)
Show older comments
Swarnava Pramanik
on 3 Aug 2016
Commented: Walter Roberson
on 3 Aug 2016
Hi,
I have created a serial port as a property to an object. In the program I assigned the BytesAvailableFcn property of the serial port to a callback function. However whenever I execute the code it gives an error " Undefined function 'acquireSamples' for input arguments of type 'serial'." Can anyone please help me regarding this issue ? I'm attaching the code.
classdef max10Display <max10lia.Max10LIAClass
properties
serialPort;
end
methods
function obj = max10Display(varargin)
obj.serialPort = serial('COM3');
obj.serialPort.BaudRate = 115200;
end
function getStarted(obj)
obj.serialPort = serial('COM3');
obj.serialPort.BaudRate = 115200;
size_data = 1000;
obj.serialPort.BytesAvailableFcn = {@acquireSamples size_data};
obj.serialPort.BytesAvailableFcnCount = size_data;
obj.serialPort.InputBufferSize = 30000;
obj.serialPort.BytesAvailableFcnMode = 'byte';
numSamples = obj.everyNSamples;
comma = ' ';
numSamples = ['N_Sample',comma,num2str(numSamples)];
fopen(obj.serialPort);
fprintf(obj.serialPort, numSamples);
end
function acquireSamples(obj,~,chunk)
........
........
end
end
end
0 Comments
Accepted Answer
Walter Roberson
on 3 Aug 2016
You made acquireSamples a non-static method of your class, so it expects an object of your class max10Display as the first parameter. But you are using a standard serial port BytesAvailableFcn callback, and for that the first parameter passed is the serial port object.
2 Comments
Walter Roberson
on 3 Aug 2016
obj.serialPort.BytesAvailableFcn = {@(src, event) acquireSamples(obj, src, event), size_data};
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!