-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslx_ljHeartbeat.m
63 lines (54 loc) · 1.97 KB
/
slx_ljHeartbeat.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%SLX_LJHEARTBEAT Mask initialization for lj_Heartbeat block
%
% slx_ljHeartbeat.m
% Julian Bell, JTEC Energy
% 2023-12-06
%
% This class definition configures & initializes the mask for the
% lj_Heartbeat block in slx_LJM
%
% Relevant references:
% - XXX
%
% TODO:
% - Figure out inconsistency in timing bug. When running at a period
% similar to the model sample period, this block produces a duty cycle that
% isn't 50%. This is almost certainly a discretization issue - but still
% need to figure it out...
classdef slx_ljHeartbeat
properties
ljHandle double
ljID string
end
methods(Static)
% Following properties of 'maskInitContext' are available to use:
% - BlockHandle
% - MaskObject
% - MaskWorkspace: Use get/set APIs to work with mask workspace.
function MaskInitialization(maskInitContext)
% Create mask contexts
bh = maskInitContext.BlockHandle;
mo = maskInitContext.MaskObject;
mw = maskInitContext.MaskWorkspace;
% Get parent block ID
parentID = get_param(bh,'Parent');
try
disp('Trying to configure heartbeat output')
ljPort = mw.get('ljPort');
ljPort = strip(ljPort,"'");
disp(['I think the port is...', num2str(ljPort)]);
ljHandle = get_param(parentID,'ljHandle');
ljHandle = str2num(ljHandle);
disp(['I think the handle is...', num2str(ljHandle)]);
set_param(bh,'ljHandle',num2str(ljHandle));
mw.set('ljHandle',ljHandle);
LabJack.LJM.eWriteName(ljHandle,ljPort,0); % Initially start output low
catch ljConnectErr
showErrorMessage(ljConnectErr);
disp(ljConnectErr)
LabJack.LJM.CloseAll();
end
end
% Use the code browser on the left to add the callbacks.
end
end