Bonjour,
Je suis déjà venu pour un problème au sujet des objets COM (http://www.developpez.net/forums/d13...vec-objet-com/) et j'ai depuis bien approfondi le sujet et appris dessus.
Cependant, pour la suite de mon projet, je suis confronté à la dernière difficulté de l'utilisation de ces objets : le type VARIANT.
Je me suis bien entendu renseigné sur sa composition et j'ai compris que c'était un type au format variable dont on pouvait connaître le type au moment t grâce à son membre vt. Soit.
Seulement j'ai des fonctions qui sont censées me renvoyer des valeurs dans un tableau (au moins 5 valeurs) et ces fonctions prennent toutes deux paramètres : VARIANT et unsigned long *. Le deuxième paramètre me renvoie toujours 6 et pas une autre valeur supplémentaire si j'envoie un tableau prédéfini (si c'est l'adresse d'une variable unique c'est aussi le même résultat).
Le premier, ne renvoie rien, si j'initialise le type VARIANT il reste identique à ce qui a été fait avant, sinon cela donne des valeurs aléatoires en son sein (ce qui est logique).
Cela s'explique sans doute par le fait que le type en paramètre n'est pas un pointeur et du coup la modification ne peut me revenir.
Mais dans ce cas, comment je récupère les données voulues ?
Pour que ce soit plus clair, voici mon code d'essai :
Voici l'IDL correspondant à l’interface :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 #include <stdio.h> #include <windows.h> #include <objbase.h> #include <initguid.h> #define INTERFACE IRobX DECLARE_INTERFACE_ (INTERFACE, IDispatch) { /* Implémentation de la classe IUnknown */ STDMETHOD (QueryInterface) (THIS_ GUID *, void **) PURE; STDMETHOD_ (ULONG, AddRef) (THIS) PURE; STDMETHOD_ (ULONG, Release) (THIS) PURE; /* De même pour la classe IDispatch */ STDMETHOD_ (HRESULT, GetTypeInfoCount) (THIS_ UINT *) PURE; STDMETHOD_ (HRESULT, GetTypeInfo) (THIS_ UINT, LCID, ITypeInfo **) PURE; STDMETHOD_ (HRESULT, GetIDsOfNames) (THIS_ REFIID, LPOLESTR *, UINT, LCID, DISPID *) PURE; STDMETHOD_ (HRESULT, Invoke) (THIS_ DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *) PURE; /* Méthodes de la classe spécifique au robot */ STDMETHOD_ (HRESULT, CloseComm) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, Energize) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GetErrorInfo) (THIS_ ULONG, BSTR *) PURE; STDMETHOD_ (HRESULT, GetCurrentPosition) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, GetString) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, GotoHome) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GotoPoint) (THIS_ BSTR, ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GotoPosition) (THIS_ LONG, LONG, LONG, LONG, LONG, ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GotoUserPosition) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, InitRobot) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, MemPointPosition) (THIS_ LONG, LONG, LONG, LONG, LONG, BSTR, ULONG *) PURE; STDMETHOD_ (HRESULT, Move) (THIS_ ULONG, ULONG, ULONG, ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, OpenComm) (THIS_ BSTR, ULONG *) PURE; STDMETHOD_ (HRESULT, RestoreUserDefaultPosition) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, SendString) (THIS_ BSTR, ULONG *) PURE; STDMETHOD_ (HRESULT, SetSpeed) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, SetUserPosition) (THIS_ LONG, LONG, LONG, LONG, LONG, ULONG *) PURE; STDMETHOD_ (HRESULT, Wait) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, SetLimits) (THIS_ LONG, LONG, LONG, LONG, LONG, ULONG *) PURE; STDMETHOD_ (HRESULT, RestoreDefaultLimits) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetLimits) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, SetToolParam) (THIS_ LONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GetToolParam) (THIS_ LONG *) PURE; STDMETHOD_ (HRESULT, Align) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GetVacuum) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, Pump) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, Valve) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, OpenManualBox) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetSpeed) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, WaitForManualBoxEnd) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetSerialNumber) (THIS_ BSTR *) PURE; STDMETHOD_ (HRESULT, GetUserPosition) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, Calibrate) (THIS_ LONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GetSpeedStatus) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetSpeedNum) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetCurrentPositionStatus) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetCurrentPositionStr) (THIS_ BSTR *) PURE; STDMETHOD_ (HRESULT, GetLimitsStatus) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetLimitsStr) (THIS_ BSTR *) PURE; STDMETHOD_ (HRESULT, GetVacuumStatus) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetVacuumNum) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetUserPositionStatus) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetUserPositionStr) (THIS_ BSTR *) PURE; STDMETHOD_ (HRESULT, OpenPositionManager) (THIS_ BSTR, ULONG *) PURE; STDMETHOD_ (HRESULT, WaitForPositionManagerEnd) (THIS_ BSTR *) PURE; STDMETHOD_ (HRESULT, GetPositionFile) (THIS_ BSTR *) PURE; STDMETHOD_ (HRESULT, SetPositionFile) (THIS_ BSTR) PURE; STDMETHOD_ (HRESULT, Laser) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, SetAccel) (THIS_ ULONG, ULONG *) PURE; STDMETHOD_ (HRESULT, GetAccel) (THIS_ VARIANT, ULONG *) PURE; STDMETHOD_ (HRESULT, GetAccelStatus) (THIS_ ULONG *) PURE; STDMETHOD_ (HRESULT, GetAccelNum) (THIS_ ULONG *) PURE; }; void CoupureRobot(void); int InitialisationRobot(char *port); void BSTRtoASC(BSTR str, char **strRet); void ASCtoBSTR(char *str, BSTR *strRet); void OuverturePositionManager(void); void PanneauControleRobot(void); #include <stdio.h> #include <OleAuto.h> #include <wchar.h> #include <string.h> #include <tchar.h> //92507B34-D92D-4F8C-967E-6C5166C0F1F6 DEFINE_GUID(IID_Rob5x, 0x92507b34, 0xd92d, 0x4f8c, 0x96, 0x7e, 0x6c, 0x51, 0x66, 0xc0, 0xf1, 0xf6); //5DD00CD6-E135-4799-A83F-62F06688700F DEFINE_GUID(CLSID_Rob5x, 0x5dd00cd6, 0xe135, 0x4799, 0xa8, 0x3f, 0x62, 0xf0, 0x66, 0x88, 0x70, 0x0f); IRobX *Robot = NULL; void CoupureRobot(void) { ULONG retVal; Robot->lpVtbl->CloseComm(Robot, &retVal); Robot->lpVtbl->Release(Robot); CoUninitialize(); } int InitialisationRobot(char *port) { ULONG resultat, retVal, valeur; BSTR chaineBSTR; /* On récupère l'objet, on lance une instance et on tente une communication avec le robot */ if(SUCCEEDED((resultat = CoInitialize(NULL)))) { if(CoCreateInstance(&CLSID_Rob5x, NULL, CLSCTX_ALL, &IID_Rob5x, (void**) &Robot)){ _tprintf(_TEXT("%s\n"), _TEXT("Erreur dans la création de l'instance")); return -42; } else { ASCtoBSTR(port, &chaineBSTR); resultat = Robot->lpVtbl->OpenComm(Robot, chaineBSTR, &retVal); Robot->lpVtbl->InitRobot(Robot, &valeur); } } } void PanneauControleRobot(void) { ULONG valeur; Robot->lpVtbl->OpenManualBox(Robot, &valeur); Robot->lpVtbl->WaitForManualBoxEnd(Robot, &valeur); } void OuverturePositionManager(void) { ULONG valeur; BSTR chaine; Robot->lpVtbl->OpenPositionManager(Robot, NULL, &valeur); Robot->lpVtbl->WaitForPositionManagerEnd(Robot, &chaine); } /* Deux fonctions pour traduire les chaines de type BSTR vers des types classiques */ void BSTRtoASC(BSTR str, char **strRet) { if(str != NULL) { ULONG length = WideCharToMultiByte(CP_ACP, 0, str, SysStringLen(str), NULL, 0, NULL, NULL); *strRet = malloc(sizeof(char)*length); length = WideCharToMultiByte(CP_ACP, 0, str, SysStringLen(str), *strRet, length, NULL, NULL); *(strRet)[length-2] = '\0'; } } void ASCtoBSTR(char *str, BSTR *strRet) { if(str != NULL) { ULONG length = strlen(str); int ResultLength = MultiByteToWideChar (CP_ACP,MB_PRECOMPOSED, str,length,NULL,0); *strRet = SysAllocStringLen(NULL, ResultLength); MultiByteToWideChar (CP_ACP,MB_PRECOMPOSED, str,length,*strRet,ResultLength); } } void PrintVariant(VARIANT *var) { if(var->vt==VT_UI1) { wprintf(L"VT_UI1:%u\n",var->bVal); } else if(var->vt==VT_I2) { wprintf(L"VT_I2:%d\n",var->iVal); } else if(var->vt==VT_I4) { wprintf(L"I4:%d\n",var->lVal); } else if(var->vt==VT_R4) { wprintf(L"VT_R4:%f\n",var->fltVal); } else if(var->vt==VT_R8) { wprintf(L"VT_R8:%lf\n",var->dblVal); } else if(var->vt==VT_BOOL) { wprintf(L"VT_BOOL:"); if(var->boolVal==0) { wprintf(L"false\n"); } else { wprintf(L"true\n"); } } else if(var->vt==VT_BSTR) { wprintf(L"VT_BSTR:%s\n",var->bstrVal); } else if(var->vt == (VT_BYREF|VT_UI4)) printf("Tableau d'ULONG....\n"); else printf("Rien dans la liste\n"); } int main(void) { VARIANT A; ULONG retVal[100] = { 0 }; HRESULT ret; int i = 0; VariantInit(&A); A.vt = VT_BYREF|VT_UI4; A.pulVal = malloc(sizeof(unsigned long) * 5); A.pulVal[0] = 1; A.pulVal[1] = 2; A.pulVal[2] = 3; A.pulVal[3] = 4; A.pulVal[4] = 5; InitialisationRobot("COM1"); ret = Robot->lpVtbl->GetCurrentPosition(Robot, A, retVal); printf("Vt : 0x%08.8X, %d et valeur retournee : %lu\n", A.vt, A.decVal, retVal[0]); for(i = 0; i < 100; i++) printf("%d : %lu\n", i, retVal[i]); for(i = 0; i < 5; i++) printf("%d : %lu\n", i, A.pulVal[i]); printf("hrResult : %i\n", ret); PrintVariant(&A); CoupureRobot(); return 0; }
Pour information, la documentation du constructeur (faite pour du JavaScript), montre le code d'exemple associé à la fonction GetCurrentPosition() dont j'essaie de récupérer les données :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 // Generated .IDL file (by the OLE/COM Object Viewer) // // typelib filename: Rob5x.exe [ uuid(3CF4288A-9CB4-44DE-8CB2-8EDC34EB5A7C), version(1.0), helpstring("RobX 1.0 Type Library"), custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 100663657), custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1360058814), custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, Created by MIDL version 6.00.0361 at Tue Feb 05 11:06:53 2013 ) ] library RobXLib { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface IRobX; [ uuid(5DD00CD6-E135-4799-A83F-62F06688700F), helpstring("CoRobX Class") ] coclass CoRobX { [default] interface IRobX; }; [ odl, uuid(92507B34-D92D-4F8C-967E-6C5166C0F1F6), helpstring("IRobX Interface"), dual, nonextensible, oleautomation ] interface IRobX : IDispatch { [id(0x00000001), helpstring("method CloseComm")] HRESULT CloseComm([out, retval] unsigned long* retVal); [id(0x00000002), helpstring("method Energize")] HRESULT Energize( [in] unsigned long activate, [out, retval] unsigned long* retVal); [id(0x00000003), helpstring("method GetErrorInfo")] HRESULT GetErrorInfo( [in] unsigned long errorCode, [out, retval] BSTR* retStr); [id(0x00000004), helpstring("method GetCurrentPosition")] HRESULT GetCurrentPosition( [in] VARIANT coordArray, [out, retval] unsigned long* retVal); [id(0x00000005), helpstring("method GetString")] HRESULT GetString( [in] VARIANT readBytes, [out, retval] unsigned long* retVal); [id(0x00000006), helpstring("method GotoHome")] HRESULT GotoHome( [in] unsigned long timeout, [out, retval] unsigned long* retVal); [id(0x00000007), helpstring("method GotoPoint")] HRESULT GotoPoint( [in] BSTR name, [in] unsigned long timeout, [out, retval] unsigned long* retVal); [id(0x00000008), helpstring("method GotoPosition")] HRESULT GotoPosition( [in] long X, [in] long Y, [in] long Z, [in] long W, [in] long P, [in] unsigned long timeout, [out, retval] unsigned long* retVal); [id(0x00000009), helpstring("method GotoUserPosition")] HRESULT GotoUserPosition( [in] unsigned long timeout, [out, retval] unsigned long* retVal); [id(0x0000000a), helpstring("method InitRobot")] HRESULT InitRobot([out, retval] unsigned long* retVal); [id(0x0000000b), helpstring("method MemPointPosition")] HRESULT MemPointPosition( [in] long X, [in] long Y, [in] long Z, [in] long W, [in] long P, [in] BSTR name, [out, retval] unsigned long* retVal); [id(0x0000000c), helpstring("method Move")] HRESULT Move( [in] unsigned long X, [in] unsigned long Y, [in] unsigned long Z, [in] unsigned long timeout, [out, retval] unsigned long* retVal); [id(0x0000000d), helpstring("method OpenComm")] HRESULT OpenComm( [in] BSTR portName, [out, retval] unsigned long* retVal); [id(0x0000000e), helpstring("method RestoreUserDefaultPosition")] HRESULT RestoreUserDefaultPosition([out, retval] unsigned long* retVal); [id(0x0000000f), helpstring("method SendString")] HRESULT SendString( [in] BSTR bytesToSend, [out, retval] unsigned long* retVal); [id(0x00000010), helpstring("method SetSpeed")] HRESULT SetSpeed( [in] unsigned long speed, [out, retval] unsigned long* retVal); [id(0x00000011), helpstring("method SetUserPosition")] HRESULT SetUserPosition( [in] long X, [in] long Y, [in] long Z, [in] long W, [in] long P, [out, retval] unsigned long* retVal); [id(0x00000012), helpstring("method Wait")] HRESULT Wait( [in] unsigned long millisecs, [out, retval] unsigned long* retVal); [id(0x00000013), helpstring("method SetLimits")] HRESULT SetLimits( [in] long Xmin, [in] long Xmax, [in] long Ymin, [in] long Ymax, [in] long Zmin, [out, retval] unsigned long* retVal); [id(0x00000014), helpstring("method RestoreDefaultLimits")] HRESULT RestoreDefaultLimits([out, retval] unsigned long* retVal); [id(0x00000015), helpstring("method GetLimits")] HRESULT GetLimits( [in] VARIANT Limits, [out, retval] unsigned long* retVal); [id(0x00000016), helpstring("method SetToolParam")] HRESULT SetToolParam( [in] long ToolLength, [out, retval] unsigned long* retVal); [id(0x00000017), helpstring("method GetToolParam")] HRESULT GetToolParam([out, retval] long* ToolLength); [id(0x00000018), helpstring("method Align")] HRESULT Align( [in] unsigned long activate, [out, retval] unsigned long* retVal); [id(0x00000019), helpstring("method GetVacuum")] HRESULT GetVacuum( [in] VARIANT vacuum, [out, retval] unsigned long* retVal); [id(0x0000001a), helpstring("method Pump")] HRESULT Pump( [in] unsigned long activate, [out, retval] unsigned long* retVal); [id(0x0000001b), helpstring("method Valve")] HRESULT Valve( [in] unsigned long open, [out, retval] unsigned long* retVal); [id(0x0000001c), helpstring("method OpenManualBox")] HRESULT OpenManualBox([out, retval] unsigned long* retVal); [id(0x0000001d), helpstring("method GetSpeed")] HRESULT GetSpeed( [in] VARIANT speed, [out, retval] unsigned long* retVal); [id(0x0000001e), helpstring("method WaitForManualBoxEnd")] HRESULT WaitForManualBoxEnd([out, retval] unsigned long* retVal); [id(0x0000001f), helpstring("method GetSerialNumber")] HRESULT GetSerialNumber([out, retval] BSTR* serialNumber); [id(0x00000020), helpstring("method GetUserPosition")] HRESULT GetUserPosition( [in] VARIANT userPosition, [out, retval] unsigned long* retVal); [id(0x00000021), helpstring("method Calibrate")] HRESULT Calibrate( [in] long ask, [out, retval] unsigned long* retVal); [id(0x00000022), helpstring("method GetSpeedStatus")] HRESULT GetSpeedStatus([out, retval] unsigned long* retVal); [id(0x00000023), helpstring("method GetSpeedNum")] HRESULT GetSpeedNum([out, retval] unsigned long* speed); [id(0x00000024), helpstring("method GetCurrentPositionStatus")] HRESULT GetCurrentPositionStatus([out, retval] unsigned long* retVal); [id(0x00000025), helpstring("method GetCurrentPositionStr")] HRESULT GetCurrentPositionStr([out, retval] BSTR* coordStr); [id(0x00000026), helpstring("method GetLimitsStatus")] HRESULT GetLimitsStatus([out, retval] unsigned long* retVal); [id(0x00000027), helpstring("method GetLimitsStr")] HRESULT GetLimitsStr([out, retval] BSTR* limitsStr); [id(0x00000028), helpstring("method GetVacuumStatus")] HRESULT GetVacuumStatus([out, retval] unsigned long* retVal); [id(0x00000029), helpstring("method GetVacuumNum")] HRESULT GetVacuumNum([out, retval] unsigned long* vacuum); [id(0x0000002a), helpstring("method GetUserPositionStatus")] HRESULT GetUserPositionStatus([out, retval] unsigned long* retVal); [id(0x0000002b), helpstring("method GetUserPositionStr")] HRESULT GetUserPositionStr([out, retval] BSTR* coordStr); [id(0x0000002c), helpstring("method OpenPositionManager")] HRESULT OpenPositionManager( [in] BSTR positions, [out, retval] unsigned long* retVal); [id(0x0000002d), helpstring("method WaitForPositionManagerEnd")] HRESULT WaitForPositionManagerEnd([out, retval] unsigned long* retVal); [id(0x0000002e), propget, helpstring("property PositionFile")] HRESULT PositionFile([out, retval] BSTR* filePath); [id(0x0000002e), propput, helpstring("property PositionFile")] HRESULT PositionFile([in] BSTR filePath); [id(0x0000002f), helpstring("method Laser")] HRESULT Laser( [in] unsigned long activate, [out, retval] unsigned long* retVal); [id(0x00000030), helpstring("method SetAccel")] HRESULT SetAccel( [in] unsigned long accel, [out, retval] unsigned long* retVal); [id(0x00000031), helpstring("method GetAccel")] HRESULT GetAccel( [in] VARIANT accel, [out, retval] unsigned long* retVal); [id(0x00000032), helpstring("method GetAccelStatus")] HRESULT GetAccelStatus([out, retval] unsigned long* retVal); [id(0x00000033), helpstring("method GetAccelNum")] HRESULT GetAccelNum([out, retval] unsigned long* speed); }; };
J'ai testé pour d'autres fonctions fonctionnant sur le même procédé, sans succès...GetCurrentPosition method
This method retrieves the current coordinates of the robot.
Parameters
● [out] Array: This array of integers holds the current coordinates of the robot. There are five
elements in the array (X, Y, Z, W, P). X, Y, Z are in mm, W and P are in degrees.
Return
Returns 0 when successful, else an error is returned.
JScript example
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 // Create a shell object to display user messages var WshShell = new ActiveXObject("WScript.Shell"); //Create a robot control object var RobX = new ActiveXObject("KEOLABS.Rob5x"); //Status return variable var ret; // Open communication with the robot ret = RobX.OpenComm("COM1"); if (ret) WshShell.Popup(RobX.GetErrorInfo(ret)); // Retrieve current Robot coordinates var coordinates = new Array(1,2,3,4,5); ret = RobX.GetCurrentPosition(coordinates); if (ret) WshShell.Popup(RobX.GetErrorInfo(ret)); // Display coordinates WshShell.Popup("Current robot coordinates:" + "\r\n X = " + coordinates[0] + "\r\n Y = " + coordinates[1] + "\r\n Z = " + coordinates[2] + "\r\n W = " + coordinates[3] + "\r\n P = " + coordinates[4] ); // Close communication ret = RobX.CloseComm(); if (ret) WshShell.Popup(RobX.GetErrorInfo(ret));
Je suis preneur des pistes que vous pouvez me suggérer et je vous remercie d'avance pour votre aide.
Si jamais il y a besoin, je peux fournir plus d'informations s'il en manque.
Partager