SDC C-Project CF Review 프로그램
LYW
2021-07-01 597136832196f40e9d91dee12c3b9ca94a8fc7eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
        File: cmplclib.h
 
        PMAC Compiled PLC Command strings, Max parameters,
        Axis masks, & Error codes
 
        Author(s):      Ed Lay
 
        08/03/93      EBL     Created
 
        Change log:
 
          Date       Rev     Who         Description
        ---------    -----   -----   -----------------------------------------
        01/11/4              EBL     Changes for windows DLL
        01/21/4              EBL     Add "dlllib.h" & "struct.h" for WINDOWS
        01/27/4              EBL     New lvardef structure
        03/03/4              EBL     New Function Blocks(TON,TOF,TP,CTU,CTD,CTUD)
        03/03/4              EBL     Change CmdSingle VALUE
        03/13/5              EBL     Add FBnn.ET &=  logic
        08/24/99             EBL     Change Token structure to be "integer"
        10/13/00             EBL     Add Lnn-> definition using Mnn-> format
        10/19/00             EBL     Add LOCK, UNLOCK, SETPHSE strings
 
*/
// #define _DEBUG 1
 
#ifndef _CMPLCLIB_H
  #define _CMPLCLIB_H
  #include <stdlib.h>
  #include <stdio.h>
  #include <ctype.h>
  #include <share.h>
  #ifdef _MSC_VER
    #include <malloc.h>
  #endif
 
//*****************  Strings  ***********************************
 
  #define SABS    "ABS"
  #define SACOS   "ACOS"
  #define SADD    "ADD"
  #define SADDR   "\x41\x44\xC4\x52\xC5\xD3\xD3"        // ADDRESS
  #define SAND    "AND"
  #define SASIN   "ASIN"
  #define SATAN   "ATAN"
  #define SATAN2  "ATAN2"
  #define SCLEAR  "\x43\x4C\xC5\xC1\x52"
  #define SCLOSE  "\x43\x4C\xCF\x53\xC5"
  #define SCMD    "\x43\xCF\x4D\xCD\xC1\xCE\x44"        // COMMAND
  #define SCHN    "CHN"                                 // MACPlcc CHN
  #define SCOS    "COS"
  #define SCOPYR  "COP\xD9\x52\xC5\xC7"                  // COPyReg
  #define SCOPYR2 "COP\xD9\x52\xC5\xC7\x32"              // COPyReg2
  #define SCTD    "CTD"
  #define SCTR_R  "CTR_R"
  #define SCTU    "CTU"
  #define SCTUD   "CTUD"
  #define SDISPLC "DIS\xC1\xC2\xCC\xC5\xA0\x50\x4C\x43" // 'DISABLE PLC'
  #define SDISP   "DIS\x50\xCC\xC1\xD9"                 // 'DISPLAY'
  #define SDIV     "DIV"
  #define SENAPLC "ENA\xC2\xCC\xC5\xA0\x50\x4C\x43"     // 'ENABLE PLC'
  #define SENDI   "END\xA0\x49\xC6"                     // 'END IF'
  #define SENDW   "END\xA0\x57\xC8\xC9\xCC\xC5"         // 'END WHILE'
  #define SELSE   "ELSE"
  #define SEQ     "EQ"
  #define SEXP    "EXP"
  #define SFTOI   "FTOI"
  #define SFLIMIT "FLIMIT"
  #define SGT     "GT"
  #define SGTE    "GTE"
  #define SIF     "IF"
  #define SINT    "INT"
  #define SITOF   "ITOF"
  #define SLOCK   "LOCK"
  #define SLN     "LN"
  #define SLT     "LT"
  #define SLTE    "LTE"
  #define SMACPLCC "MACPLCC\xA0"                            // 'MACPLCC '
  #define SLMOVRLY "LMOV\xC5\x52\x4C\xC1\x59"           // 'LMOVeRLaY'
  #define SMOD    "MOD"
  #define SMTRNum "MTRN\xD5\xCD"
  #define SMULT   "MULT"
  #define SNAND   "NAND"
  #define SNEQ    "NE"
  #define SNOR    "NOR"
  #define SOPEN   "\x4F\x50\xC5\x4E"                    // OPEN - OPN
  #define SOPTI   "OPTI\xCD\xC9\xDA\xC5\xA0\x4F\x46\xC6" // OPTImize OFf
  #define SOR     "OR"
  #define SPLCC   "PLCC\xA0"                            // 'PLCC '
  #define SRET    "RET\xD5\xD2\xCE"                     // 'RETurn'
  #define SSCAN   "SCAN"
  #define SSEND   "SEND"
  #define SSETPH  "SETPHASE"
  #define SSERVO  "SERVO"                               // 'SERVO'
  #define SSIN    "SIN"
  #define SSQRT   "SQRT"
  #define SSUB    "SUB"
  #define STAN    "TAN"
  #define STON    "TON"
  #define STOF    "TOF"
  #define STP     "TP"
  #define STMR_R  "TMR_R"
  #define SUNLOCK "UNLOCK"
  #define SWHILE  "WHILE"
  #define SXOR    "XOR"
 
//
// TIMER STRUCTURE ELEMENTs
//
  #define STMR_IN ".IN"     // Strings
  #define STMR_TT ".TT"
  #define STMR_Q  ".Q"
  #define STMR_PT ".PT"
  #define STMR_ET ".ET"
  #define TMR_IN 0x160A     // Format Code
  #define TMR_TT 0x150A
  #define TMR_Q  0x140A
  #define TMR_PT 0x00A2
  #define TMR_ET 0x0000
  #define FBXREAD 0x800000L // READS DATA INTO "X1" REGISTER
 
//
// COUNTER STRUCTURE ELEMENTs
//
  #define SCTR_RS ".R"  // Strings
  #define SCTR_CU ".CU"
  #define SCTR_Q ".Q"
  #define SCTR_PV ".PV"
  #define SCTR_LD ".LD"
  #define SCTR_CD ".CD"
  #define SCTR_CV ".CV"
  #define CTR_RS 0x170A // Format Code
  #define CTR_CU 0x160A
  #define CTR_QU 0x140A
  #define CTR_PV 0x00A2
  #define CTR_LD 0x1708
  #define CTR_CD 0x1608
  #define CTR_QD 0x1408
  #define CTR_CV 0x00A0
 
//
// MATH STRUCTURE ELEMENTs
//
  #define SMATH_A ".A"
  #define SMATH_B ".B"
  #define SMATH_C ".C"
  #define SMATH_Q ".Q"
  #define SMATH_EN ".EN"
  #define SMATH_ENO ".ENO"
  #define SSCAN_TIME ".TIME"
  #define SSCAN_MAX ".MAX"
  #define SSCAN_MIN ".MIN"
  #define SSCAN_CLR ".CLR"
// FB READ/WRITE FORMAT CODE
  #define MATH_A      0x0002
  #define MATH_B      0x0000
  #define MATH_C      0x0002
  #define MATH_Q      0x1708
  #define MATH_ENO    0x1708
  #define MATH_EN     0x1608
  #define SCAN_TIME   0x0000
  #define SCAN_MAX    0x0002
  #define SCAN_MIN    0x0080
  #define SCAN_CLR    0x1508
 
//****************************************************************************
//
//      Function Return codes for PLCstrcnvt, PLCstrtod, PLCmtrnum,
//      PLCplcnum, PLCaxisnum
//
//****************************************************************************
//  #ifdef _DEBUG
//    #define PLCTOKENMAX 655  // For DEBUG?? limited to 64k at the present struct size = 10
//    #define PLC56KMAX  1536  // For DEBUG maximum number of PLC 56k memory = 15K
//    #define LVARSIZE   1024  // Max size of L-var variables
//  #else
//    #define PLCTOKENMAX 6553 // limited to 64k at the present struct size = 10
  #define PLC56KMAX  15360 // maximum number of PLC 56k memory = 15K
  #define LVARSIZE   8192  // Max size of L-var variables
                           //  #endif
 
  #define STACKMAX   128    // maximum number of temporary 56k stack
  #define PLCSTRMAX  8192*2   // max number of buffered characters allowed for string cmds.
  #define PLCSTRLINEMAX 256 // max number of characters allowed in one string + 1
  #define PLCOk   0
  #define PLCClose 1        // Close command encoutered - not an error
 
//enum PLCCompileErrors {       Is now in "pmacresc.h"
//    PLCOk              =   0,
//     PLCClose           =   1,   // Close command encoutered - not an error
//     PLCFltErr          = -33,   // Unable to pack; floating point number too large
//     PLCStrToDErr       = -34,   // Unable to convert string to double float number
//     PLCCmdErr          = -35,   // Illegal Command or Format in string
//     PLCIntErr          = -36,   // Integer number out of range
//     PLCParenErr        = -37,   // Unmatching parenthesis
//     PLCElseErr         = -38,   // Illegal Else
//     PLCEndIfErr        = -39,   // Illegal EndIf
//     PLCEndWhErr        = -40,   // Illegal EndWhile
//     PLCOutFileErr      = -41,   // PLCC Output File Error
//     PLCInpFileErr      = -42,   // PLCC Input File Error
//     PLCCmdClsErr       = -43,   // Unclosed If or While
//     PLC56kMemMaxErr    = -44,   // Max number of PLC 56k memory exceeded
//     PLC56kstackMaxErr  = -45,   // Max number of PLC 56k conversion stack exceeded
//     PLCTokenMaxErr     = -46,   // Max number of Tokens exceeded for allowed memory
//     PLCfarheapErr      = -47,   // Far heap allocate error
//     PLCStrErr          = -48,   // String error Must be in "" & less than 255 characters
//     PLCLvarNotDef      = -49,   // L-var address not defined
//     PLCLvarMpyDef      = -50    // Two L-vars have the same address definition
// or has already been defined
//};
 
 
struct plccnvt { // PLC ASCII to Binary Token convert structure
 
     int     token;
     double  data;
};
 
 
  #define XYBITMASK 0x5F // see below
  #define XYMASK 0x40    // see below
  #define BITMASK 0x1F   // see below
  #define FORMATMASK 0x80
 
struct lvardef_struct { // PLC ASCII to Binary Token convert structure
 
     DWORD           addr;
     unsigned char   xybit; // Bit use      7       6        5    43210
                            //              ---    --------  --  ----------
                            //            U/S= 0/1 x/y= 0/1  0   offset # 0-23
 
     unsigned char   width; // width 1,4,8,12,16,24
     int             l_def; // Lnn-> using X/Y: Mnn-> definition format
};
 
 
 
///////////////////////////////////////////////////////////////////////////
// Functions
 
  #ifdef __cplusplus
extern "C" {
  #endif
  // Converts from a .PMA to .56K
  int CALLBACK PmacPlccCompilerA( DWORD dwDevice, int *datainfo, PCHAR inName, PCHAR outName );
  int CALLBACK PmacPlccCompilerW( DWORD dwDevice, int *datainfo, PWCHAR inName, PWCHAR outName );
  #ifdef __cplusplus
}
  #endif
 
  #ifdef UNICODE
    #define PlccCompiler PlccCompilerW
  #else
    #define PlccCompiler PlccCompilerA
  #endif // !UNICODE
 
#endif