-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethPicoMotorIO.m
138 lines (125 loc) · 4.34 KB
/
ethPicoMotorIO.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%ethPicoMotorIO ethernet interface between MATLAB and the NewFocus
%Picomotor Ethernet Controller 8752
%
% Methods::
%
% ethPicoMotorIO Constructor, initialises and opens the ethernet connection
% delete Destructor, closes the ethernet connection
%
% open Open a ethernet connection to the PicoMotor
% close Close the ethernet connection to the PicoMotor
% read Read data from the PicoMotor through ethernet
% write Write data to the PicoMotor through ethernet
%
% Example::
% ethPM = ethPicoMotorIO()
%
% Notes::
% - Uses the Java Socket stack
%
% Author: Klaus Hueck (e-mail: khueck (at) physik (dot) uni-hamburg (dot) de)
% Version: 0.0.1alpha
% Changes tracker: 28.01.2016 - First version
% License: GPL v3
classdef ethPicoMotorIO < PicoMotorIO
properties
% connection handle
handle
% debug input
debug = 0;
% IP
IP = '192.168.10.2';
% port
port = 23;
end
methods
function PMIO = ethPicoMotorIO(varargin)
%ethPicoMotorIO.ethPicoMotorIO Create a ethPicoMotorIO object
%
% PMIO = ethPicoMotorIO(varargin) is an object which
% initialises a ethernet connection between MATLAB and the
% PicoMotor using the Java socket stack.
%
% Notes::
% - Can take one parameter debug which is a flag specifying
% output printing (0 or 1).
if nargin == 0
PMIO.debug = 0;
end
if nargin > 0
PMIO.debug = varargin{1};
end
if PMIO.debug > 0
fprintf('ethPicoMotorIO init\n');
end
% create the eth handle
PMIO.handle = JavaSocket(PMIO.debug, PMIO.IP, PMIO.port);
% open the PicoMotorIO connection
PMIO.open;
end
function delete(PMIO)
%ethPicoMotorIO.delete Delete the ethPicoMotorIO object
%
% delete(PMIO) closes the ethernet connection handle
if PMIO.debug > 0
fprintf('ethPicoMotorIO delete\n');
end
% delete the ethernet handle
delete(PMIO.handle)
end
% open the PicoMotorIO connection
function open(PMIO)
%ethPicoMotorIO.open Open the ethPicoMotorIO object
%
% ethPicoMotorIO.open() opens the ethernet handle through the
% Java socket stack
if PMIO.debug > 0
fprintf('ethPicoMotorIO open\n');
end
% open the ethernet handle
PMIO.handle.open;
end
function close(PMIO)
%ethPicoMotorIO.close Close the ethPicoMotorIO object
%
% ethPicoMotorIO.close() closes the ethernet handle through
% Java socket stack
if PMIO.debug > 0
fprintf('ethPicoMotorIO close\n');
end
% close the ethernet handle
PMIO.handle.close;
end
function rmsg = read(PMIO)
%ethPicoMotorIO.read Read data from the ethPicoMotorIO object
%
% rmsg = ethPicoMotorIO.read() reads data from the PicoMotor through
% ethernet and returns the data in uint8 format.
%
if PMIO.debug > 0
fprintf('ethPicoMotorIO read\n');
end
% read from the ethernet handle
rmsg = PMIO.handle.read;
% cast to char and replace '>' by ''
rmsg = strrep(char(rmsg), '>', '');
% split by line
rmsg = strsplit(rmsg, '\n');
end
function write(PMIO,wmsg)
%ethPicoMotorIO.write Write data to the ethPicoMotorIO object
%
% ethPicoMotorIO.write(wmsg) writes data to the PicoMotor
% through ethernet.
%
% Notes::
% - wmsg is the data to be written to the PicoMotor via
% ethernet in char format.
if PMIO.debug > 0
fprintf('ethPicoMotorIO write\n');
end
% write to the ethernet handle
PMIO.handle.write(wmsg);
end
end
end