質問編集履歴

1

ソースコードの文字数が多いためドライブへのリンクに変更しました。

2016/10/14 04:02

投稿

k_noriyuki
k_noriyuki

スコア7

test CHANGED
File without changes
test CHANGED
@@ -24,375 +24,19 @@
24
24
 
25
25
 
26
26
 
27
- ###該当のソースコード
28
27
 
29
28
 
30
29
 
30
+
31
+ 文字数が1000文字を超えてしまいますのでドライブに置きました。
32
+
31
- ```c
33
+ よろしくお願いします。
32
34
 
33
35
 
34
36
 
35
- #ifndef _KRSLIB_H_INCLUDE
37
+ [ソース](https://drive.google.com/drive/folders/0BypGMUZQqteUY19vUmIwT1puUE0?usp=sharing)
36
-
37
- #define _KRSLIB_H_INCLUDE
38
38
 
39
39
 
40
-
41
- #ifdef __cplusplus
42
-
43
- extern "C" {
44
-
45
- #endif
46
-
47
- #ifdef _WIN32
48
-
49
- #include <windows.h>
50
-
51
- #else
52
-
53
- #include <pthread.h>
54
-
55
- #endif
56
-
57
-
58
-
59
- #ifndef _MSC_VER
60
-
61
- #include <stdbool.h>
62
-
63
- #endif
64
-
65
- #include <stdint.h>
66
-
67
- #include <stdint.h>
68
-
69
-
70
-
71
- #define BROADCASTING_ID (0xfe)
72
-
73
-
74
-
75
- #ifndef _WIN32
76
-
77
- typedef int HANDLE;
78
-
79
- typedef pthread_mutex_t CRITICAL_SECTION;
80
-
81
-
82
-
83
- #define EnterCriticalSection(mtx) pthread_mutex_lock(mtx)
84
-
85
- #define LeaveCriticalSection(mtx) pthread_mutex_unlock(mtx)
86
-
87
- #define DeleteCriticalSection(mtx) pthread_mutex_destroy(mtx)
88
-
89
- #define InitializeCriticalSection(mtx) pthread_mutex_init(mtx,NULL)
90
-
91
- #define SetEvent(evt) pthread_cond_signal(evt)
92
-
93
- #define INVALID_int_VALUE -1
94
-
95
- #define INVALID_HANDLE_VALUE -1
96
-
97
- #endif
98
-
99
-
100
-
101
- // デバイスID
102
-
103
- #ifdef _WIN32
104
-
105
- #ifdef _WIN64
106
-
107
- typedef uint64_t TDeviceID;
108
-
109
- #else
110
-
111
- typedef uint32_t TDeviceID;
112
-
113
- #endif
114
-
115
- #else
116
-
117
- typedef uint32_t TDeviceID;
118
-
119
- #endif
120
-
121
-
122
-
123
- // コマンド
124
-
125
- typedef enum {CMD_WRITE_POS = 4, CMD_READ_PARAM = 5, CMD_WRITW_PARAM = 6, CMD_ID = 7} TCommand;
126
-
127
-
128
-
129
- // サブコマンド
130
-
131
- #define SC_EEPROM (0)
132
-
133
- #define SC_STRETCH (1)
134
-
135
- #define SC_SPEED (2)
136
-
137
- #define SC_CURRENT (3)
138
-
139
- #define SC_TEMPTURE (4)
140
-
141
-
142
-
143
- #define SC_READ_ID (0)
144
-
145
- #define SC_WRITE_ID (1)
146
-
147
-
148
-
149
- // エラーフラグ
150
-
151
- typedef uint16_t TErrorCode;
152
-
153
- #define ERR_INVALID_DEVID (1 << 15)
154
-
155
- #define ERR_INVALID_ID (1 << 14)
156
-
157
- #define ERR_DIFF_ID (1 << 13)
158
-
159
- #define ERR_ILLEGAL_SIZE (1 << 12)
160
-
161
- #define ERR_INVALID_PARAM (1 << 11)
162
-
163
- #define ERR_COMM (1 << 10)
164
-
165
- #define ERR_CHECKSUM (1 << 9)
166
-
167
- #define ERR_TIMEOUT (1 << 8)
168
-
169
- #define ERR_KRS_INST (1 << 6)
170
-
171
- #define ERR_KRS_OVERLOAD (1 << 5)
172
-
173
- #define ERR_KRS_CHECKSUM (1 << 4)
174
-
175
- #define ERR_KRS_RANGE (1 << 3)
176
-
177
- #define ERR_KRS_OVERHEAT (1 << 2)
178
-
179
- #define ERR_KRS_ANGLE (1 << 1)
180
-
181
- #define ERR_KRS_OVERVOLTAGE (1 << 0)
182
-
183
- #define ERR_NON (0)
184
-
185
-
186
-
187
- // アラームステータス
188
-
189
- typedef struct {
190
-
191
- uint8_t id;
192
-
193
- TErrorCode Status;
194
-
195
- } TAlarmStatus;
196
-
197
-
198
-
199
- #ifdef _WIN32
200
-
201
- #ifdef __MAKE_LIB__
202
-
203
- #define KRSAPIDLL __declspec(dllexport) WINAPI
204
-
205
- #else
206
-
207
- #define KRSAPIDLL __declspec(dllimport) WINAPI
208
-
209
- #endif
210
-
211
- #else
212
-
213
- #define KRSAPIDLL
214
-
215
- #define WINAPI
216
-
217
- #endif
218
-
219
-
220
-
221
- #ifndef _DYNAMICLOAD
222
-
223
- // 静的なDLL呼び出し時は以下のプロトタイプ宣言を使用
224
-
225
- TDeviceID KRSAPIDLL KRS_OpenPort (char *name, uint32_t baud);
226
-
227
- bool KRSAPIDLL KRS_ClosePort (TDeviceID dvid);
228
-
229
- void KRSAPIDLL KRS_SetEchoCancel (bool becho);
230
-
231
- bool KRSAPIDLL KRS_SetBaudrate (TDeviceID dvid, uint32_t baud);
232
-
233
- bool KRSAPIDLL KRS_Active (TDeviceID dvid);
234
-
235
- void KRSAPIDLL KRS_SetTimeOutOffset (TDeviceID dvid, uint32_t t);
236
-
237
- double KRSAPIDLL GetQueryPerformanceCounter (void);
238
-
239
- bool KRSAPIDLL KRS_TxPacket (TDeviceID dvid, uint8_t id, TCommand cmd, uint8_t *param, uint32_t len, TErrorCode *err);
240
-
241
- bool KRSAPIDLL KRS_RxPacket (TDeviceID dvid, uint8_t *rdata, uint32_t rdatasize, uint32_t *rlen, uint32_t timeout, TErrorCode *err);
242
-
243
- bool KRSAPIDLL KRS_ReadByteData(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, TErrorCode *errcode);
244
-
245
- bool KRSAPIDLL KRS_WriteByteData(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t dat, TErrorCode *errcode);
246
-
247
- bool KRSAPIDLL KRS_ReadWordData(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t *rdata, TErrorCode *errcode);
248
-
249
- bool KRSAPIDLL KRS_WriteWordData(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t dat, TErrorCode *errcode);
250
-
251
- bool KRSAPIDLL KRS_ReadBlockData (TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, uint32_t len, TErrorCode *errcode);
252
-
253
- bool KRSAPIDLL KRS_WriteBlockData(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *dat, uint32_t len, TErrorCode *errcode);
254
-
255
- bool KRSAPIDLL KRS_WriteSyncData (TDeviceID dvid, uint8_t *dat, uint32_t size, TErrorCode *errcode);
256
-
257
- bool KRSAPIDLL KRS_Ping(TDeviceID dvid, uint8_t id, TErrorCode *errcode);
258
-
259
-
260
-
261
- #else
262
-
263
- // 動的なDLL呼び出し時は以下の型宣言を使用
264
-
265
- typedef TDeviceID (WINAPI *_KRS_OpenPort)(char *name, long baud);
266
-
267
- typedef bool (WINAPI *_KRS_ClosePort)(TDeviceID dvid);
268
-
269
- typedef void (WINAPI *_KRS_SetEchoCancel)(bool becho);
270
-
271
- typedef bool (WINAPI *_KRS_SetBaudrate) (TDeviceID dvid, long baud);
272
-
273
- typedef bool (WINAPI *_KRS_Active)(TDeviceID dvid);
274
-
275
- typedef void (WINAPI *_KRS_SetTimeOutOffset)(TDeviceID dvid, uint32_t offsettime);
276
-
277
- typedef bool (WINAPI *_KRS_TxPacket) (TDeviceID dvid, uint8_t id, TCommand cmd, uint8_t *param, uint32_t len, TErrorCode *err);
278
-
279
- typedef bool (WINAPI *_KRS_RxPacket) (TDeviceID dvid, uint8_t *rdata, uint32_t rdatasize, uint32_t *rlen, TErrorCode *err);
280
-
281
- typedef bool (WINAPI *_KRS_ReadByteData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, TErrorCode *errcode);
282
-
283
- typedef bool (WINAPI *_KRS_WriteByteData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t dat, TErrorCode *errcode);
284
-
285
- typedef bool (WINAPI *_KRS_ReadWordData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t *rdata, TErrorCode *errcode);
286
-
287
- typedef bool (WINAPI *_KRS_WriteWordData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t dat, TErrorCode *errcode);
288
-
289
- typedef bool (WINAPI *_KRS_ReadBlockData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, uint32_t len, TErrorCode *errcode);
290
-
291
- typedef bool (WINAPI *_KRS_WriteBlockData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *dat, uint32_t len, TErrorCode *errcode);
292
-
293
- typedef bool (WINAPI *_KRS_WriteSyncData) (TDeviceID dvid, uint8_t *dat, uint32_t size, TErrorCode *errcode);
294
-
295
- typedef bool (WINAPI *_KRS_Ping)(TDeviceID dvid, uint8_t id, TErrorCode *errcode);
296
-
297
-
298
-
299
- _KRS_OpenPort KRS_OpenPort = NULL;
300
-
301
- _KRS_ClosePort KRS_ClosePort = NULL;
302
-
303
- _KRS_SetEchoCancel KRS_SetEchoCancel = NULL;
304
-
305
- _KRS_SetBaudrate KRS_SetBaudrate = NULL;
306
-
307
- _KRS_Active KRS_Active = NULL;
308
-
309
- _KRS_SetTimeOutOffset KRS_SetTimeOutOffset = NULL;
310
-
311
- _KRS_TxPacket KRS_TxPacket = NULL;
312
-
313
- _KRS_RxPacket KRS_RxPacket = NULL;
314
-
315
- _KRS_ReadByteData KRS_ReadByteData = NULL;
316
-
317
- _KRS_WriteByteData KRS_WriteByteData = NULL;
318
-
319
- _KRS_ReadWordData KRS_ReadWordData = NULL;
320
-
321
- _KRS_WriteWordData KRS_WriteWordData = NULL;
322
-
323
- _KRS_ReadBlockData KRS_ReadBlockData = NULL;
324
-
325
- _KRS_WriteBlockData KRS_WriteBlockData = NULL;
326
-
327
- _KRS_WriteSyncData KRS_WriteSyncData = NULL;
328
-
329
- _KRS_Ping KRS_Ping = NULL;
330
-
331
-
332
-
333
- static HMODULE hModule = NULL;
334
-
335
-
336
-
337
- #ifdef _WIN32
338
-
339
- #ifdef _WIN64
340
-
341
- #define DLLNAME "krslib_x64.dll"
342
-
343
- #else
344
-
345
- #define DLLNAME "krslib_x32.dll"
346
-
347
- #endif
348
-
349
- #else
350
-
351
- #ifdef __x86_64__
352
-
353
- #define DLLNAME "krslib_x64.dll"
354
-
355
- #else
356
-
357
- #define DLLNAME "krslib_x32.dll"
358
-
359
- #endif
360
-
361
- #endif
362
-
363
-
364
-
365
- // DLLのロード
366
-
367
- bool LoadDLL (void) {
368
-
369
- hModule = LoadLibrary (DLLNAME);
370
-
371
- if (hModule == NULL) {
372
-
373
- return false;
374
-
375
- }
376
-
377
-
378
-
379
- #endif
380
-
381
-
382
-
383
- #ifdef __cplusplus
384
-
385
- }
386
-
387
- #endif
388
-
389
-
390
-
391
- #endif //_KRSLIB_H_INCLUDE
392
-
393
-
394
-
395
- ```
396
40
 
397
41
 
398
42