-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathVREPWrapper.cs
114 lines (88 loc) · 5.55 KB
/
VREPWrapper.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace remoteApiNETWrapper
{
public static class VREPWrapper
{
[DllImport("remoteApi.dll")]
public static extern void simxFinish(int clientID);
[DllImport("remoteApi.dll")]
public static extern int simxGetConnectionId(int clientID);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetFloatSignal(int clientID, string signalName, ref float value, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetIntegerSignal(int clientID, string signalName, ref int value, simx_opmode opmode);
public static int simwGetIntegerSignal(int clientID, string signalName)
{
int v = -1;
simxGetIntegerSignal(clientID, signalName, ref v, simx_opmode.streaming);
Thread.Sleep(150);
simxGetIntegerSignal(clientID, signalName, ref v, simx_opmode.buffer);
return v;
}
[DllImport("remoteApi.dll")]
public static extern simx_error simxSetStringSignal(int clientID, string signalName, string value, int length, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetStringSignal(int clientID, string signalName, ref IntPtr pointerToValue, ref int signalLength, simx_opmode opmode);
public static string simwGetStringSignal(int clientID, string signalName)
{
IntPtr p = IntPtr.Zero;
var l1 = 0;
var l2 = 0;
var e = simxGetStringSignal(clientID, signalName, ref p, ref l1, simx_opmode.streaming);
Thread.Sleep(150);
e = simxGetStringSignal(clientID, signalName, ref p, ref l2, simx_opmode.buffer);
Console.WriteLine("Signal {0} -> {1}/{2}", signalName, l1, l2);
if (e == simx_error.noerror && p != IntPtr.Zero)
{
var s = Marshal.PtrToStringAnsi(p, l2);
Marshal.Release(p);
return s;
}
return "";
}
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetAndClearStringSignal(int clientID, string signalName, ref IntPtr pointerToValue, ref int signalLength, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetJointPosition(int clientID, int jointHandle, ref float targetPosition, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetObjectIntParameter(int clientID, int objectHandle, int parameterID, ref int parameterValue, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetObjectFloatParameter(int clientID, int objectHandle, int parameterID, ref float parameterValue, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetObjectOrientation(int clientID, int jointHandle, int relativeToHandle, float[] orientations, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetObjectPosition(int clientID, int jointHandle, int relativeToHandle, float[] positions, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxPauseCommunication(int cliendID, int pause);
[DllImport("remoteApi.dll")]
public extern static simx_error simxReadProximitySensor(int clientID, int sensorHandle,
ref char detectionState, float[] detectionPoint, ref int objectHandle, float[] normalVector, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxSetJointTargetPosition(int clientID, int jointHandle, float targetPosition, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxSetJointTargetVelocity(int clientID, int jointHandle, float velocity, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxSetObjectFloatParameter(int clientID, int objectHandle, int parameterID, float parameterValue, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxSetObjectIntParameter(int clientID, int objectHandle, int parameterID, int parameterValue, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern int simxStart(string ip, int port, bool waitForConnection, bool reconnectOnDisconnect, int timeoutMS, int cycleTimeMS);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetUIEventButton(int clientID, int uiHandle, ref int uiEventButtonID, IntPtr aux, simx_opmode opmode);
[DllImport("remoteApi.dll")]
// public static extern simx_error simxGetUIHandle(int clientID, string uiName, out int handle, simx_opmode opmode);
public static extern simx_error simxGetUIHandle(int clientID, string uiName, IntPtr p, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxGetObjectHandle(int clientID, string objectName, out int handle, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxStartSimulation(int clientID, simx_opmode opmode);
[DllImport("remoteApi.dll")]
public static extern simx_error simxStopSimulation(int clientID, simx_opmode opmode);
}
}