質問編集履歴
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,279 +1,3 @@
|
|
1
|
-
生体信号の値をコンソールに出力するプログラムがあるのですが、Textに書き出せるように手を加えたいと思っています。しかし、どこをどう直したらいいのか(どの変数に生体信号の値が入ってるのか)がわからず、進めません。
|
2
|
-
どなたか、どんな小さなことでもいいのでヒントを頂けたらと思います…!!
|
3
|
-
|
1
|
+
解決しました。
|
4
|
-
```C++
|
5
|
-
// 40_SimplereadData.cpp :
|
6
|
-
|
7
|
-
#define _WIN32_DCOM // for using CoInitializeEx
|
8
|
-
#include<iostream>
|
9
|
-
#include<fstream>
|
10
|
-
|
11
|
-
#include <stdio.h>
|
12
|
-
#include <conio.h> // for kbhit() and getch()
|
13
|
-
|
14
|
-
#define USING_WRAPPER_CLASS
|
15
|
-
#include "..\ttllive.h"
|
16
|
-
|
17
|
-
#define F "test.txt"
|
18
|
-
using namespace std;
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ITTLLive2Ptr g_TTLLive;
|
27
|
-
|
28
|
-
void show_error(_com_error &e)
|
29
|
-
{
|
30
|
-
printf("(0x%08X)\n\r",e.Error());
|
31
|
-
PrintLine("");
|
32
|
-
printf("%s\n\r",(char*)e.Description());
|
33
|
-
}
|
34
|
-
|
35
|
-
void read_data(void)
|
36
|
-
{
|
37
|
-
int col = 0;
|
38
|
-
LONG liSamplesAvailable, liChannelHND;
|
39
|
-
FLOAT fBuffer[4096];
|
40
|
-
|
41
|
-
liChannelHND = g_TTLLive->GetFirstChannelHND();
|
42
|
-
while( liChannelHND > -1 ){
|
43
|
-
|
44
|
-
if( col == 0 )printf("\n\rData ");
|
45
|
-
|
46
|
-
liSamplesAvailable = g_TTLLive->SamplesAvailable[liChannelHND];
|
47
|
-
|
48
|
-
if( liSamplesAvailable ){
|
49
|
-
g_TTLLive->ReadChannelData(liChannelHND, fBuffer, &liSamplesAvailable );
|
50
|
-
|
51
|
-
}
|
52
|
-
|
53
|
-
// If any samples available, we simply print out value of the first one
|
54
|
-
if( liSamplesAvailable ){
|
55
|
-
printf("%c:%6.3f, ",(char)('A'+liChannelHND),fBuffer[0]);
|
56
|
-
|
57
|
-
|
58
|
-
} else {
|
59
|
-
printf("%c:NO DATA, ",(char)('A'+liChannelHND),fBuffer[0]);
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
col++;
|
66
|
-
if( col >= 5)col = 0;
|
67
|
-
|
68
|
-
liChannelHND = g_TTLLive->GetNextChannelHND();
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
printf("\n\rDate");
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
void channel_setup(BOOL bForceSensors)
|
78
|
-
{
|
79
|
-
LONG liChannelHND;
|
80
|
-
|
81
|
-
LONG liChannelCount;
|
82
|
-
|
83
|
-
PrintLine(MSG_SETTING_UP_CHANNELS);
|
84
|
-
g_TTLLive->AutoSetupChannels();
|
85
|
-
|
86
|
-
liChannelHND = g_TTLLive->GetFirstChannelHND();
|
87
|
-
while( liChannelHND > -1 ){
|
88
|
-
// Setting up channels with arbitrary configuration, turning-off channel
|
89
|
-
// notification, pluggin-in sensor ID into sensor type and set channels
|
90
|
-
// to output raw COUNTS.
|
91
|
-
g_TTLLive->Notification[liChannelHND]=0;
|
92
|
-
g_TTLLive->ForceSensor[liChannelHND]=bForceSensors;
|
93
|
-
g_TTLLive->SensorType[liChannelHND] = g_TTLLive->SensorID[liChannelHND];
|
94
|
-
g_TTLLive->UnitType[liChannelHND]=TTLAPI_UT_COUNT;
|
95
|
-
liChannelHND = g_TTLLive->GetNextChannelHND();
|
96
|
-
}
|
97
|
-
// if we get here it means there was no exceptions.
|
98
|
-
liChannelCount = g_TTLLive->ChannelCount;
|
99
|
-
printf("Created %d channel%s.\n\r",liChannelCount,(liChannelCount>1)?"s":"");
|
100
|
-
}
|
101
|
-
|
102
|
-
void force_channels(BOOL bForceSensors )
|
103
|
-
{
|
104
|
-
LONG liChannelHND;
|
105
|
-
|
106
|
-
printf("Force Channels = ");
|
107
|
-
if( bForceSensors ){
|
108
|
-
printf("TRUE, also acquiring data from unconnected channels.\n\r");
|
109
|
-
} else {
|
110
|
-
printf("FALSE, only acquiring data only from connected channels.\n\r");
|
111
|
-
}
|
112
|
-
|
113
|
-
liChannelHND = g_TTLLive->GetFirstChannelHND();
|
114
|
-
while( liChannelHND > -1 ){
|
115
|
-
g_TTLLive->ForceSensor[liChannelHND]=bForceSensors;
|
116
|
-
liChannelHND = g_TTLLive->GetNextChannelHND();
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
void show_menu(void)
|
121
|
-
{
|
122
|
-
printf("\n\r***** Main Menu *****\n\r\n\r");
|
123
|
-
printf("press 'O' to attempt connecting to encoder.\n\r");
|
124
|
-
printf("press 'C' to close all connections.\n\r");
|
125
|
-
printf("press 'S' to setup channels.\n\r");
|
126
|
-
printf("press 'D' to toggle acquiring data.\n\r");
|
127
|
-
printf("press 'F' to toggle between [force channels/only use connected channels].\n\r");
|
128
|
-
printf("press 'X' to exit.\n\r\n\r");
|
129
|
-
}
|
130
|
-
|
131
|
-
int main(int argc, char* argv[])
|
132
|
-
{
|
133
|
-
LONG liEncoderCount = 0;
|
134
|
-
UINT_PTR puiTimer = NULL;
|
135
|
-
HRESULT hr = S_OK;
|
136
|
-
MSG msg = {0};
|
137
|
-
int c = 0;
|
138
|
-
|
139
|
-
BOOL bReadingData = FALSE;
|
140
|
-
BOOL bForceSensors = TRUE;
|
141
|
-
|
142
|
-
printf("\n\rSimple TTLLive Console Test Client Reading Actual Sample Data\n\r\n\r");
|
143
|
-
|
144
|
-
|
145
|
-
PrintLine(MSG_CO_INITIALIZE);
|
146
|
-
|
147
|
-
hr = CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);
|
148
|
-
|
2
|
+
コードを削除させていただきます。
|
149
|
-
|
150
|
-
if( SUCCEEDED(hr)){
|
151
|
-
PrintLine(MSG_CREATING_INSTANCE);
|
152
|
-
|
153
|
-
// This will attempt creating an TTLLive object
|
154
|
-
hr = g_TTLLive.CreateInstance(CLSID_TTLLive);
|
155
|
-
CheckHRESULT(hr);
|
156
|
-
if( SUCCEEDED(hr)){
|
157
|
-
try {
|
158
|
-
|
159
|
-
T_Version sV;
|
160
|
-
|
161
|
-
PrintLine(MSG_GETTING_VERSION);
|
162
|
-
sV.liVersion = g_TTLLive->Version;
|
163
|
-
printf("%d.%d.%d\n\r", sV.byMajor, sV.byMinor, sV.woBuild);
|
164
|
-
|
165
|
-
|
166
|
-
} catch ( _com_error &e ) {
|
167
|
-
show_error(e);
|
168
|
-
}
|
169
|
-
|
170
|
-
show_menu();
|
171
|
-
|
172
|
-
do {
|
173
|
-
try {
|
174
|
-
if( kbhit()){
|
175
|
-
c = toupper(getch());
|
176
|
-
|
177
|
-
switch( c ){
|
178
|
-
case 'O' :
|
179
|
-
bReadingData = FALSE;
|
180
|
-
PrintLine(MSG_AUTODETECTING);
|
181
|
-
//g_TTLLive->OpenConnections(TTLAPI_OCCMD_AUTODETECT,1000,NULL,NULL);
|
182
|
-
g_TTLLive->OpenConnection("USB:0",1000);
|
183
|
-
liEncoderCount = g_TTLLive->EncoderCount;
|
184
|
-
printf("Found %d encoder%s.\n\r",liEncoderCount,(liEncoderCount>1)?"s":"");
|
185
|
-
break;
|
186
|
-
|
187
|
-
case 'C' :
|
188
|
-
PrintLine(MSG_CLOSE_CONNECTIONS);
|
189
|
-
g_TTLLive->CloseConnections();
|
190
|
-
liEncoderCount = g_TTLLive->EncoderCount;
|
191
|
-
printf("EncoderCount = %d.\n\r",liEncoderCount);
|
192
|
-
bReadingData = FALSE;
|
193
|
-
::KillTimer(NULL,puiTimer);
|
194
|
-
break;
|
195
|
-
|
196
|
-
case 'S' :
|
197
|
-
channel_setup(bForceSensors);
|
198
|
-
break;
|
199
|
-
|
200
|
-
case 'D' :
|
201
|
-
bReadingData^=TRUE;
|
202
|
-
if( bReadingData ){
|
203
|
-
if( g_TTLLive->EncoderCount > 0 ){
|
204
|
-
PrintLine("Starting data");
|
205
|
-
g_TTLLive->StartChannels();
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
CheckHRESULT(S_OK);
|
210
|
-
// Setting windows timer to get a WM_TIMER messages
|
211
|
-
// about 5 times per second.
|
212
|
-
puiTimer = ::SetTimer(NULL,0,200,NULL);
|
213
|
-
} else {
|
214
|
-
printf("No encoder created yet.\n\r");
|
215
|
-
}
|
216
|
-
} else {
|
217
|
-
PrintLine("Stopping data");
|
218
|
-
g_TTLLive->StartChannels();
|
219
|
-
CheckHRESULT(S_OK);
|
220
|
-
::KillTimer(NULL,puiTimer);
|
221
|
-
}
|
222
|
-
break;
|
223
|
-
|
224
|
-
case 'F':
|
225
|
-
bForceSensors^=TRUE;
|
226
|
-
force_channels(bForceSensors);
|
227
|
-
break;
|
228
|
-
|
229
|
-
case 'X':
|
230
|
-
break;
|
231
|
-
|
232
|
-
default:
|
233
|
-
show_menu();
|
234
|
-
}
|
235
|
-
}
|
236
|
-
|
237
|
-
while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
|
238
|
-
|
3
|
+
回答してくださった方ありがとうございました。
|
239
|
-
case WM_TIMER:
|
240
|
-
if( msg.wParam == puiTimer ){
|
241
|
-
if( bReadingData ){
|
242
|
-
read_data();
|
243
|
-
}
|
244
|
-
}
|
245
|
-
break;
|
246
|
-
}
|
247
|
-
DispatchMessage(&msg);
|
248
|
-
}
|
249
|
-
|
250
|
-
Sleep(10);
|
251
|
-
} catch ( _com_error &e ) {
|
252
|
-
show_error(e);
|
253
|
-
}
|
254
|
-
|
255
|
-
} while( c !='X');
|
256
|
-
|
257
|
-
// Releasing instance since we used 'g_TTLLive.CreateInstance'
|
258
|
-
PrintLine(MSG_RELEASING_INSTANCES);
|
259
|
-
if( g_TTLLive )g_TTLLive.Release();
|
260
|
-
printf("Done!\n\r");
|
261
|
-
|
262
|
-
}
|
263
|
-
|
264
|
-
// We much balance a successful call to CoInitialize
|
265
|
-
// by a call to CoUninitialize.
|
266
|
-
PrintLine(MSG_CO_UNINITIALIZE);
|
267
|
-
CoUninitialize();
|
268
|
-
printf("Done!\n\r");
|
269
|
-
}
|
270
|
-
|
271
|
-
if( NULL != puiTimer )
|
272
|
-
::KillTimer(NULL,puiTimer);
|
273
|
-
|
274
|
-
printf("\n\rExiting application...\n\r");
|
275
|
-
return 0;
|
276
|
-
}
|
277
|
-
|
278
|
-
|
279
|
-
```
|