File: RunMatlabTestServer.m

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (61 lines) | stat: -rw-r--r-- 2,353 bytes parent folder | download
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
%This example shows how to expose an object as a service using MATLAB
%as the server.  It uses the "classdef" new style classes.

%%Startup section.  Only run this once per session

%Start the server. THIS MUST BE THE FIRST THING DONE USING ROBOT RACONTEUR
%DURING THE SESSION
RobotRaconteur.StartLocalServer('example.MatlabTestServer');
RobotRaconteur.StartTcpServer(4343);

%cSpell: ignore testva

%Define a service definition
servicedef1=['service example.MatlabTestService\n\n' ...
    'struct MatlabTestStruct\n' ...
    'field int32 val1\n' ...
    'field double[] val2\n' ...
    'end struct\n\n' ...
    'object MatlabTestObject\n' ...
    'property int32 testprop1\n' ...
    'property MatlabTestStruct testprop2\n' ...
    'function void testfunc1(int32 testval1, double testva2)\n' ...
    'function int32 testfunc2(int32 testval1)\n' ...
    'event testevent1()\n' ...
    'event testevent2(int32 testval1, int32 testval2)\n' ...
    'end object\n'];
%Use sprintf to convert the '\n' to newlines
servicedef=sprintf(servicedef1);

%Register the service definition
RobotRaconteur.RegisterServiceType(servicedef);

%Create the object
o=MatlabTestServiceClass();

%Register the object as a service
RobotRaconteur.RegisterService('MatlabTestService','example.MatlabTestService.MatlabTestObject',o);

%Use the following instead if you want authentication. "authdata"
%has the same format as the "PasswordFileUserAuthenticator"
%authdata=sprintf(['myusername 34819d7beeabb9260a5c854bc85b3e44 objectlock\n' ...
%'anotherusername 1910ea24600608b01b5efd7d4ea6a840 objectlock\n' ...
%'superuser f1bc69265be1165f64296bcb7ca180d5 objectlock,objectlockoverride\n']);
%RobotRaconteur.RegisterService('MatlabTestService','example.MatlabTestService.MatlabTestObject',o,authdata);

%%Runtime section.  Run this section repeatedly to execute requests
%to the service.

%Run the service.  Use Ctrl-C to exit
i=0;
while(1)
  %We need to process the incoming requests manually because MATLAB
  %has poor threading capabilities.  It will timeout in 1 second.
  RobotRaconteur.ProcessServerRequests(1);
  %Fire off a few events
  notify(o,'testevent1');
  %Note that parameters are passed using the "RobotRaconteurEventData"
  %command with the parameters stored in a cell vector.
  notify(o,'testevent2',RobotRaconteurEventData({int32(10);int32(i)}))
  i=i+1;
end