質問するログイン新規登録

質問編集履歴

1

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

2016/10/14 04:02

投稿

k_noriyuki
k_noriyuki

スコア7

title CHANGED
File without changes
body CHANGED
@@ -11,193 +11,15 @@
11
11
 
12
12
  error c2061:構文エラー:識別子’TCommand’ ファイル:krslib.h 行:108
13
13
 
14
- ###該当のソースコード
15
14
 
16
- ```c
17
15
 
18
- #ifndef _KRSLIB_H_INCLUDE
16
+ 文字数が1000文字を超えてしまいますのでドライブに置きました。
19
- #define _KRSLIB_H_INCLUDE
17
+ よろしくお願いします。
20
18
 
21
- #ifdef __cplusplus
22
- extern "C" {
23
- #endif
24
- #ifdef _WIN32
25
- #include <windows.h>
19
+ [ソース](https://drive.google.com/drive/folders/0BypGMUZQqteUY19vUmIwT1puUE0?usp=sharing)
26
- #else
27
- #include <pthread.h>
28
- #endif
29
20
 
30
- #ifndef _MSC_VER
31
- #include <stdbool.h>
32
- #endif
33
- #include <stdint.h>
34
- #include <stdint.h>
35
21
 
36
- #define BROADCASTING_ID (0xfe)
37
22
 
38
- #ifndef _WIN32
39
- typedef int HANDLE;
40
- typedef pthread_mutex_t CRITICAL_SECTION;
41
-
42
- #define EnterCriticalSection(mtx) pthread_mutex_lock(mtx)
43
- #define LeaveCriticalSection(mtx) pthread_mutex_unlock(mtx)
44
- #define DeleteCriticalSection(mtx) pthread_mutex_destroy(mtx)
45
- #define InitializeCriticalSection(mtx) pthread_mutex_init(mtx,NULL)
46
- #define SetEvent(evt) pthread_cond_signal(evt)
47
- #define INVALID_int_VALUE -1
48
- #define INVALID_HANDLE_VALUE -1
49
- #endif
50
-
51
- // デバイスID
52
- #ifdef _WIN32
53
- #ifdef _WIN64
54
- typedef uint64_t TDeviceID;
55
- #else
56
- typedef uint32_t TDeviceID;
57
- #endif
58
- #else
59
- typedef uint32_t TDeviceID;
60
- #endif
61
-
62
- // コマンド
63
- typedef enum {CMD_WRITE_POS = 4, CMD_READ_PARAM = 5, CMD_WRITW_PARAM = 6, CMD_ID = 7} TCommand;
64
-
65
- // サブコマンド
66
- #define SC_EEPROM (0)
67
- #define SC_STRETCH (1)
68
- #define SC_SPEED (2)
69
- #define SC_CURRENT (3)
70
- #define SC_TEMPTURE (4)
71
-
72
- #define SC_READ_ID (0)
73
- #define SC_WRITE_ID (1)
74
-
75
- // エラーフラグ
76
- typedef uint16_t TErrorCode;
77
- #define ERR_INVALID_DEVID (1 << 15)
78
- #define ERR_INVALID_ID (1 << 14)
79
- #define ERR_DIFF_ID (1 << 13)
80
- #define ERR_ILLEGAL_SIZE (1 << 12)
81
- #define ERR_INVALID_PARAM (1 << 11)
82
- #define ERR_COMM (1 << 10)
83
- #define ERR_CHECKSUM (1 << 9)
84
- #define ERR_TIMEOUT (1 << 8)
85
- #define ERR_KRS_INST (1 << 6)
86
- #define ERR_KRS_OVERLOAD (1 << 5)
87
- #define ERR_KRS_CHECKSUM (1 << 4)
88
- #define ERR_KRS_RANGE (1 << 3)
89
- #define ERR_KRS_OVERHEAT (1 << 2)
90
- #define ERR_KRS_ANGLE (1 << 1)
91
- #define ERR_KRS_OVERVOLTAGE (1 << 0)
92
- #define ERR_NON (0)
93
-
94
- // アラームステータス
95
- typedef struct {
96
- uint8_t id;
97
- TErrorCode Status;
98
- } TAlarmStatus;
99
-
100
- #ifdef _WIN32
101
- #ifdef __MAKE_LIB__
102
- #define KRSAPIDLL __declspec(dllexport) WINAPI
103
- #else
104
- #define KRSAPIDLL __declspec(dllimport) WINAPI
105
- #endif
106
- #else
107
- #define KRSAPIDLL
108
- #define WINAPI
109
- #endif
110
-
111
- #ifndef _DYNAMICLOAD
112
- // 静的なDLL呼び出し時は以下のプロトタイプ宣言を使用
113
- TDeviceID KRSAPIDLL KRS_OpenPort (char *name, uint32_t baud);
114
- bool KRSAPIDLL KRS_ClosePort (TDeviceID dvid);
115
- void KRSAPIDLL KRS_SetEchoCancel (bool becho);
116
- bool KRSAPIDLL KRS_SetBaudrate (TDeviceID dvid, uint32_t baud);
117
- bool KRSAPIDLL KRS_Active (TDeviceID dvid);
118
- void KRSAPIDLL KRS_SetTimeOutOffset (TDeviceID dvid, uint32_t t);
119
- double KRSAPIDLL GetQueryPerformanceCounter (void);
120
- bool KRSAPIDLL KRS_TxPacket (TDeviceID dvid, uint8_t id, TCommand cmd, uint8_t *param, uint32_t len, TErrorCode *err);
121
- bool KRSAPIDLL KRS_RxPacket (TDeviceID dvid, uint8_t *rdata, uint32_t rdatasize, uint32_t *rlen, uint32_t timeout, TErrorCode *err);
122
- bool KRSAPIDLL KRS_ReadByteData(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, TErrorCode *errcode);
123
- bool KRSAPIDLL KRS_WriteByteData(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t dat, TErrorCode *errcode);
124
- bool KRSAPIDLL KRS_ReadWordData(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t *rdata, TErrorCode *errcode);
125
- bool KRSAPIDLL KRS_WriteWordData(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t dat, TErrorCode *errcode);
126
- bool KRSAPIDLL KRS_ReadBlockData (TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, uint32_t len, TErrorCode *errcode);
127
- bool KRSAPIDLL KRS_WriteBlockData(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *dat, uint32_t len, TErrorCode *errcode);
128
- bool KRSAPIDLL KRS_WriteSyncData (TDeviceID dvid, uint8_t *dat, uint32_t size, TErrorCode *errcode);
129
- bool KRSAPIDLL KRS_Ping(TDeviceID dvid, uint8_t id, TErrorCode *errcode);
130
-
131
- #else
132
- // 動的なDLL呼び出し時は以下の型宣言を使用
133
- typedef TDeviceID (WINAPI *_KRS_OpenPort)(char *name, long baud);
134
- typedef bool (WINAPI *_KRS_ClosePort)(TDeviceID dvid);
135
- typedef void (WINAPI *_KRS_SetEchoCancel)(bool becho);
136
- typedef bool (WINAPI *_KRS_SetBaudrate) (TDeviceID dvid, long baud);
137
- typedef bool (WINAPI *_KRS_Active)(TDeviceID dvid);
138
- typedef void (WINAPI *_KRS_SetTimeOutOffset)(TDeviceID dvid, uint32_t offsettime);
139
- typedef bool (WINAPI *_KRS_TxPacket) (TDeviceID dvid, uint8_t id, TCommand cmd, uint8_t *param, uint32_t len, TErrorCode *err);
140
- typedef bool (WINAPI *_KRS_RxPacket) (TDeviceID dvid, uint8_t *rdata, uint32_t rdatasize, uint32_t *rlen, TErrorCode *err);
141
- typedef bool (WINAPI *_KRS_ReadByteData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, TErrorCode *errcode);
142
- typedef bool (WINAPI *_KRS_WriteByteData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t dat, TErrorCode *errcode);
143
- typedef bool (WINAPI *_KRS_ReadWordData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t *rdata, TErrorCode *errcode);
144
- typedef bool (WINAPI *_KRS_WriteWordData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint16_t dat, TErrorCode *errcode);
145
- typedef bool (WINAPI *_KRS_ReadBlockData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *rdata, uint32_t len, TErrorCode *errcode);
146
- typedef bool (WINAPI *_KRS_WriteBlockData)(TDeviceID dvid, uint8_t id, uint8_t adr, uint8_t *dat, uint32_t len, TErrorCode *errcode);
147
- typedef bool (WINAPI *_KRS_WriteSyncData) (TDeviceID dvid, uint8_t *dat, uint32_t size, TErrorCode *errcode);
148
- typedef bool (WINAPI *_KRS_Ping)(TDeviceID dvid, uint8_t id, TErrorCode *errcode);
149
-
150
- _KRS_OpenPort KRS_OpenPort = NULL;
151
- _KRS_ClosePort KRS_ClosePort = NULL;
152
- _KRS_SetEchoCancel KRS_SetEchoCancel = NULL;
153
- _KRS_SetBaudrate KRS_SetBaudrate = NULL;
154
- _KRS_Active KRS_Active = NULL;
155
- _KRS_SetTimeOutOffset KRS_SetTimeOutOffset = NULL;
156
- _KRS_TxPacket KRS_TxPacket = NULL;
157
- _KRS_RxPacket KRS_RxPacket = NULL;
158
- _KRS_ReadByteData KRS_ReadByteData = NULL;
159
- _KRS_WriteByteData KRS_WriteByteData = NULL;
160
- _KRS_ReadWordData KRS_ReadWordData = NULL;
161
- _KRS_WriteWordData KRS_WriteWordData = NULL;
162
- _KRS_ReadBlockData KRS_ReadBlockData = NULL;
163
- _KRS_WriteBlockData KRS_WriteBlockData = NULL;
164
- _KRS_WriteSyncData KRS_WriteSyncData = NULL;
165
- _KRS_Ping KRS_Ping = NULL;
166
-
167
- static HMODULE hModule = NULL;
168
-
169
- #ifdef _WIN32
170
- #ifdef _WIN64
171
- #define DLLNAME "krslib_x64.dll"
172
- #else
173
- #define DLLNAME "krslib_x32.dll"
174
- #endif
175
- #else
176
- #ifdef __x86_64__
177
- #define DLLNAME "krslib_x64.dll"
178
- #else
179
- #define DLLNAME "krslib_x32.dll"
180
- #endif
181
- #endif
182
-
183
- // DLLのロード
184
- bool LoadDLL (void) {
185
- hModule = LoadLibrary (DLLNAME);
186
- if (hModule == NULL) {
187
- return false;
188
- }
189
-
190
- #endif
191
-
192
- #ifdef __cplusplus
193
- }
194
- #endif
195
-
196
- #endif //_KRSLIB_H_INCLUDE
197
-
198
- ```
199
-
200
-
201
23
  ###試したこと
202
24
 
203
25
  使用環境はvisualStudio2013です。