質問編集履歴

1

修正

2020/01/08 10:05

投稿

miii
miii

スコア27

test CHANGED
File without changes
test CHANGED
@@ -1,557 +1,5 @@
1
- 生体信号の値をコンソールに出力するプログラムがあるのですが、Textに書き出せるように手を加えたいと思っていす。かし、どこをどう直しらいいのか(どの変数に生体信号の値が入ってるのか)がわからず、進めません
1
+ 解決しました。
2
2
 
3
- どなたか、どんな小なことでもいのでヒントを頂けらと思います…!!
3
+ コードを削除せていただきます
4
4
 
5
- よろしくお願いします
6
-
7
- ```C++
8
-
9
- // 40_SimplereadData.cpp :
10
-
11
-
12
-
13
- #define _WIN32_DCOM // for using CoInitializeEx
14
-
15
- #include<iostream>
16
-
17
- #include<fstream>
18
-
19
-
20
-
21
- #include <stdio.h>
22
-
23
- #include <conio.h> // for kbhit() and getch()
24
-
25
-
26
-
27
- #define USING_WRAPPER_CLASS
28
-
29
- #include "..\ttllive.h"
30
-
31
-
32
-
33
- #define F "test.txt"
34
-
35
- using namespace std;
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
- ITTLLive2Ptr g_TTLLive;
52
-
53
-
54
-
55
- void show_error(_com_error &e)
56
-
57
- {
58
-
59
- printf("(0x%08X)\n\r",e.Error());
60
-
61
- PrintLine("");
62
-
63
- printf("%s\n\r",(char*)e.Description());
64
-
65
- }
66
-
67
-
68
-
69
- void read_data(void)
70
-
71
- {
72
-
73
- int col = 0;
74
-
75
- LONG liSamplesAvailable, liChannelHND;
76
-
77
- FLOAT fBuffer[4096];
78
-
79
-
80
-
81
- liChannelHND = g_TTLLive->GetFirstChannelHND();
82
-
83
- while( liChannelHND > -1 ){
84
-
85
-
86
-
87
- if( col == 0 )printf("\n\rData ");
88
-
89
-
90
-
91
- liSamplesAvailable = g_TTLLive->SamplesAvailable[liChannelHND];
92
-
93
-
94
-
95
- if( liSamplesAvailable ){
96
-
97
- g_TTLLive->ReadChannelData(liChannelHND, fBuffer, &liSamplesAvailable );
98
-
99
-
100
-
101
- }
102
-
103
-
104
-
105
- // If any samples available, we simply print out value of the first one
106
-
107
- if( liSamplesAvailable ){
108
-
109
- printf("%c:%6.3f, ",(char)('A'+liChannelHND),fBuffer[0]);
110
-
111
-
112
-
113
-
114
-
115
- } else {
116
-
117
- printf("%c:NO DATA, ",(char)('A'+liChannelHND),fBuffer[0]);
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
- }
126
-
127
-
128
-
129
- col++;
130
-
131
- if( col >= 5)col = 0;
132
-
133
-
134
-
135
- liChannelHND = g_TTLLive->GetNextChannelHND();
136
-
137
- }
138
-
139
-
140
-
141
-
142
-
143
- printf("\n\rDate");
144
-
145
-
146
-
147
-
148
-
149
- }
150
-
151
-
152
-
153
- void channel_setup(BOOL bForceSensors)
154
-
155
- {
156
-
157
- LONG liChannelHND;
158
-
159
-
160
-
161
- LONG liChannelCount;
162
-
163
-
164
-
165
- PrintLine(MSG_SETTING_UP_CHANNELS);
166
-
167
- g_TTLLive->AutoSetupChannels();
168
-
169
-
170
-
171
- liChannelHND = g_TTLLive->GetFirstChannelHND();
172
-
173
- while( liChannelHND > -1 ){
174
-
175
- // Setting up channels with arbitrary configuration, turning-off channel
176
-
177
- // notification, pluggin-in sensor ID into sensor type and set channels
178
-
179
- // to output raw COUNTS.
180
-
181
- g_TTLLive->Notification[liChannelHND]=0;
182
-
183
- g_TTLLive->ForceSensor[liChannelHND]=bForceSensors;
184
-
185
- g_TTLLive->SensorType[liChannelHND] = g_TTLLive->SensorID[liChannelHND];
186
-
187
- g_TTLLive->UnitType[liChannelHND]=TTLAPI_UT_COUNT;
188
-
189
- liChannelHND = g_TTLLive->GetNextChannelHND();
190
-
191
- }
192
-
193
- // if we get here it means there was no exceptions.
194
-
195
- liChannelCount = g_TTLLive->ChannelCount;
196
-
197
- printf("Created %d channel%s.\n\r",liChannelCount,(liChannelCount>1)?"s":"");
198
-
199
- }
200
-
201
-
202
-
203
- void force_channels(BOOL bForceSensors )
204
-
205
- {
206
-
207
- LONG liChannelHND;
208
-
209
-
210
-
211
- printf("Force Channels = ");
212
-
213
- if( bForceSensors ){
214
-
215
- printf("TRUE, also acquiring data from unconnected channels.\n\r");
216
-
217
- } else {
218
-
219
- printf("FALSE, only acquiring data only from connected channels.\n\r");
220
-
221
- }
222
-
223
-
224
-
225
- liChannelHND = g_TTLLive->GetFirstChannelHND();
226
-
227
- while( liChannelHND > -1 ){
228
-
229
- g_TTLLive->ForceSensor[liChannelHND]=bForceSensors;
230
-
231
- liChannelHND = g_TTLLive->GetNextChannelHND();
232
-
233
- }
234
-
235
- }
236
-
237
-
238
-
239
- void show_menu(void)
240
-
241
- {
242
-
243
- printf("\n\r***** Main Menu *****\n\r\n\r");
244
-
245
- printf("press 'O' to attempt connecting to encoder.\n\r");
246
-
247
- printf("press 'C' to close all connections.\n\r");
248
-
249
- printf("press 'S' to setup channels.\n\r");
250
-
251
- printf("press 'D' to toggle acquiring data.\n\r");
252
-
253
- printf("press 'F' to toggle between [force channels/only use connected channels].\n\r");
254
-
255
- printf("press 'X' to exit.\n\r\n\r");
256
-
257
- }
258
-
259
-
260
-
261
- int main(int argc, char* argv[])
262
-
263
- {
264
-
265
- LONG liEncoderCount = 0;
266
-
267
- UINT_PTR puiTimer = NULL;
268
-
269
- HRESULT hr = S_OK;
270
-
271
- MSG msg = {0};
272
-
273
- int c = 0;
274
-
275
-
276
-
277
- BOOL bReadingData = FALSE;
278
-
279
- BOOL bForceSensors = TRUE;
280
-
281
-
282
-
283
- printf("\n\rSimple TTLLive Console Test Client Reading Actual Sample Data\n\r\n\r");
284
-
285
-
286
-
287
-
288
-
289
- PrintLine(MSG_CO_INITIALIZE);
290
-
291
-
292
-
293
- hr = CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
294
-
295
- CheckHRESULT(hr);
296
-
297
-
298
-
299
- if( SUCCEEDED(hr)){
300
-
301
- PrintLine(MSG_CREATING_INSTANCE);
302
-
303
-
304
-
305
- // This will attempt creating an TTLLive object
306
-
307
- hr = g_TTLLive.CreateInstance(CLSID_TTLLive);
308
-
309
- CheckHRESULT(hr);
310
-
311
- if( SUCCEEDED(hr)){
312
-
313
- try {
314
-
315
-
316
-
317
- T_Version sV;
318
-
319
-
320
-
321
- PrintLine(MSG_GETTING_VERSION);
322
-
323
- sV.liVersion = g_TTLLive->Version;
324
-
325
- printf("%d.%d.%d\n\r", sV.byMajor, sV.byMinor, sV.woBuild);
326
-
327
-
328
-
329
-
330
-
331
- } catch ( _com_error &e ) {
332
-
333
- show_error(e);
334
-
335
- }
336
-
337
-
338
-
339
- show_menu();
340
-
341
-
342
-
343
- do {
344
-
345
- try {
346
-
347
- if( kbhit()){
348
-
349
- c = toupper(getch());
350
-
351
-
352
-
353
- switch( c ){
354
-
355
- case 'O' :
356
-
357
- bReadingData = FALSE;
358
-
359
- PrintLine(MSG_AUTODETECTING);
360
-
361
- //g_TTLLive->OpenConnections(TTLAPI_OCCMD_AUTODETECT,1000,NULL,NULL);
362
-
363
- g_TTLLive->OpenConnection("USB:0",1000);
364
-
365
- liEncoderCount = g_TTLLive->EncoderCount;
366
-
367
- printf("Found %d encoder%s.\n\r",liEncoderCount,(liEncoderCount>1)?"s":"");
368
-
369
- break;
370
-
371
-
372
-
373
- case 'C' :
374
-
375
- PrintLine(MSG_CLOSE_CONNECTIONS);
376
-
377
- g_TTLLive->CloseConnections();
378
-
379
- liEncoderCount = g_TTLLive->EncoderCount;
380
-
381
- printf("EncoderCount = %d.\n\r",liEncoderCount);
382
-
383
- bReadingData = FALSE;
384
-
385
- ::KillTimer(NULL,puiTimer);
386
-
387
- break;
388
-
389
-
390
-
391
- case 'S' :
392
-
393
- channel_setup(bForceSensors);
394
-
395
- break;
396
-
397
-
398
-
399
- case 'D' :
400
-
401
- bReadingData^=TRUE;
402
-
403
- if( bReadingData ){
404
-
405
- if( g_TTLLive->EncoderCount > 0 ){
406
-
407
- PrintLine("Starting data");
408
-
409
- g_TTLLive->StartChannels();
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
- CheckHRESULT(S_OK);
418
-
419
- // Setting windows timer to get a WM_TIMER messages
420
-
421
- // about 5 times per second.
422
-
423
- puiTimer = ::SetTimer(NULL,0,200,NULL);
424
-
425
- } else {
426
-
427
- printf("No encoder created yet.\n\r");
428
-
429
- }
430
-
431
- } else {
432
-
433
- PrintLine("Stopping data");
434
-
435
- g_TTLLive->StartChannels();
436
-
437
- CheckHRESULT(S_OK);
438
-
439
- ::KillTimer(NULL,puiTimer);
440
-
441
- }
442
-
443
- break;
444
-
445
-
446
-
447
- case 'F':
448
-
449
- bForceSensors^=TRUE;
450
-
451
- force_channels(bForceSensors);
452
-
453
- break;
454
-
455
-
456
-
457
- case 'X':
458
-
459
- break;
460
-
461
-
462
-
463
- default:
464
-
465
- show_menu();
466
-
467
- }
468
-
469
- }
470
-
471
-
472
-
473
- while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
474
-
475
- switch( msg.message ){
5
+ 回答してくださった方ありがとうございました。
476
-
477
- case WM_TIMER:
478
-
479
- if( msg.wParam == puiTimer ){
480
-
481
- if( bReadingData ){
482
-
483
- read_data();
484
-
485
- }
486
-
487
- }
488
-
489
- break;
490
-
491
- }
492
-
493
- DispatchMessage(&msg);
494
-
495
- }
496
-
497
-
498
-
499
- Sleep(10);
500
-
501
- } catch ( _com_error &e ) {
502
-
503
- show_error(e);
504
-
505
- }
506
-
507
-
508
-
509
- } while( c !='X');
510
-
511
-
512
-
513
- // Releasing instance since we used 'g_TTLLive.CreateInstance'
514
-
515
- PrintLine(MSG_RELEASING_INSTANCES);
516
-
517
- if( g_TTLLive )g_TTLLive.Release();
518
-
519
- printf("Done!\n\r");
520
-
521
-
522
-
523
- }
524
-
525
-
526
-
527
- // We much balance a successful call to CoInitialize
528
-
529
- // by a call to CoUninitialize.
530
-
531
- PrintLine(MSG_CO_UNINITIALIZE);
532
-
533
- CoUninitialize();
534
-
535
- printf("Done!\n\r");
536
-
537
- }
538
-
539
-
540
-
541
- if( NULL != puiTimer )
542
-
543
- ::KillTimer(NULL,puiTimer);
544
-
545
-
546
-
547
- printf("\n\rExiting application...\n\r");
548
-
549
- return 0;
550
-
551
- }
552
-
553
-
554
-
555
-
556
-
557
- ```