質問編集履歴
2
自己解決の部分を追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -357,3 +357,67 @@
|
|
357
357
|
Visual Studio2013
|
358
358
|
|
359
359
|
KI-VISA
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
### 自己解決方法
|
364
|
+
|
365
|
+
読み照らしながらC++で電圧値をプログラムから通信で変更することができました。
|
366
|
+
|
367
|
+
そのソースです。
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
#include "stdafx.h"
|
374
|
+
|
375
|
+
//タイプライブラリの作成
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
int _tmain(int argc, _TCHAR* argv[])
|
380
|
+
|
381
|
+
{
|
382
|
+
|
383
|
+
IMessagePtr spMsg; //スマート・ポインタ IMessagePtr型でCOMインターフェースを宣言、呼び出しを自動化している
|
384
|
+
|
385
|
+
CoInitializeEx(NULL, COINIT_MULTITHREADED); //COMを使うための宣言
|
386
|
+
|
387
|
+
HRESULT hr;
|
388
|
+
|
389
|
+
IResourceManager3Ptr spRM;
|
390
|
+
|
391
|
+
hr = spRM.CreateInstance(CLSID_ResourceManager); //CreateInstance()メソッドを使ってリソース・マネージャを作成
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
spMsg = spRM->Open(L"TCPIP::192.168.11.2::inst0::INSTR", NO_LOCK, 0, L""); //インターフェースの参照
|
398
|
+
|
399
|
+
SAFEARRAY* pSA = NULL;
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
pSA = spRM->FindRsrc(L"TCPIP?* INSTR");
|
404
|
+
|
405
|
+
int r;
|
406
|
+
|
407
|
+
r = spMsg->WriteString(L"OUTP 0 \n");
|
408
|
+
|
409
|
+
r = spMsg->WriteString(L"VOLT 10.0 \n");
|
410
|
+
|
411
|
+
r = spMsg->WriteString(L"CURR 5.0 \n");
|
412
|
+
|
413
|
+
r = spMsg->WriteString(L"OUTP 1 \n");
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
spMsg->Close(); //閉じる
|
420
|
+
|
421
|
+
return 0;
|
422
|
+
|
423
|
+
}
|
1
新しくプログラムを書きました
test
CHANGED
File without changes
|
test
CHANGED
@@ -262,9 +262,93 @@
|
|
262
262
|
|
263
263
|
```
|
264
264
|
|
265
|
-
|
265
|
+
```C++
|
266
|
+
|
266
|
-
|
267
|
+
#import "C:\Program Files\IVI Foundation\VISA\VisaCom64\GlobMgr.DLL" no_namespace named_guids
|
268
|
+
|
269
|
+
|
270
|
+
|
267
|
-
|
271
|
+
IMessagePtr spMsg;
|
272
|
+
|
273
|
+
IMessage* pMsg = NULL;
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
HRESULT hr;
|
278
|
+
|
279
|
+
IResourceManager3Ptr spRM;
|
280
|
+
|
281
|
+
hr = spRM.CreateInstance(CLSID_ResourceManager);
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
IMessagePtr spMsg;
|
286
|
+
|
287
|
+
spMsg = spRM->Open(L"TCPIP::192.168.11.2::inst0::INSTR", NO_LOCK, 0, L"");
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
SAFEARRAY* pSA = NULL;
|
292
|
+
|
293
|
+
try {
|
294
|
+
|
295
|
+
pSA = spRM->FindRsrc(L"?*INSTR");
|
296
|
+
|
297
|
+
r = spmsg->WriteString(L"CURR 20.0\n");
|
298
|
+
|
299
|
+
r = spmsg->WriteString(L"VOLT 5.5\n");
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
catch (_com_error e) {
|
306
|
+
|
307
|
+
//エラー・コードとメッセージは_com_error クラスのメンバー関数から取得できる
|
308
|
+
|
309
|
+
HRESULT hr = e.Error();
|
310
|
+
|
311
|
+
_bstr_t strDescription = e.Description();
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
if (pSA) {
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
BSTR* rgElems = NULL;
|
320
|
+
|
321
|
+
::SafeArrayAccessData(pSA, (PVOID*)&rgElems);
|
322
|
+
|
323
|
+
ASSERT(rgElems);
|
324
|
+
|
325
|
+
LONG lLBound, lUBound;
|
326
|
+
|
327
|
+
::SafeArrayGetLBound(pSA, 1, &lLBound);
|
328
|
+
|
329
|
+
::SafeArrayGetUBound(pSA, 1, &lUBound);
|
330
|
+
|
331
|
+
for (long lNdx = lLBound; lNdx <= lUBound; lNdx++) {
|
332
|
+
|
333
|
+
_bstr_t strFound = rgElems[lNdx];
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
::SafeArrayUnaccessData(pSA);
|
338
|
+
|
339
|
+
::SafeArrayDestroyData(pSA);
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
spMsg->Close();
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
```
|
268
352
|
|
269
353
|
|
270
354
|
|