-
Notifications
You must be signed in to change notification settings - Fork 3
/
usb_instrument.m
executable file
·41 lines (38 loc) · 1.54 KB
/
usb_instrument.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
classdef usb_instrument
% usb_instrument - connect and disconect to USB instrument
%
% F. Fajdetic, University of Zagreb, 2016
properties
port = 'COM5'
handle
baudRate = 115200
end
methods
%% Constructor
function this_usb_instrument = usb_instrument(inport, inbaudRate)
if nargin == 2
this_usb_instrument.port = inport;
this_usb_instrument.baudRate = inbaudRate;
end
end
%% open usb port
function this_usb_instrument = open(this_usb_instrument)
this_usb_instrument.handle = serial(this_usb_instrument.port, 'BaudRate', this_usb_instrument.baudRate);
fopen(this_usb_instrument.handle);
if strcmp('open', this_usb_instrument.handle.status)
disp('usb_instrument: USB port open');
elseif strcmp('closed', this_usb_instrument.handle.status)
disp('usb_instrument: Unable to open USB port');
end
end
%% close usb port
function this_usb_instrument = close(this_usb_instrument)
fclose(this_usb_instrument.handle);
if strcmp('open', this_usb_instrument.handle.status)
disp('usb_instrument: Unable to close USB port');
elseif strcmp('closed', this_usb_instrument.handle.status)
disp('usb_instrument: USB port closed');
end
end
end
end