forked from reyanvaldes/S7-cpp-for-Snap7
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths7.h
More file actions
183 lines (126 loc) · 7.18 KB
/
Copy paths7.h
File metadata and controls
183 lines (126 loc) · 7.18 KB
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
//*************************************************************************************
// S7 Library allow to mapping the buffer into the different data types
// based on wrapper made for .Net. And defines other types such us PLCs, Area Sources
//
// It uses Snap7 Library 1.4,made by Davide Nardella, http://snap7.sourceforge.net/
//
// Made by Reyan Valdes, reyanvaldes@yahoo.com
// 15-May-2023 - TOD, DTL, DATE, DATE_AND_TIME SET/GET contribution by PiotrBzdręga (Thanks!)
// MIT License
//*************************************************************************************
#ifndef S7_H
#define S7_H
#include "snap7.h"
// Define different PLC Types
#define S7_PLC_300_400 0 // for PLC S7 300/400
#define S7_PLC_1200_1500 1 // for PLC S7 1200/1500
#define S7_PLC_LOGO_200 2 // for PLC S7 LOGO / 200
#define S7_PLC_SINAMICS 3 // for SINAMICS Driver
// Define different Area sources
#define S7_AREA_SOURCE_I 0 // Inputs
#define S7_AREA_SOURCE_Q 1 // Outputs
#define S7_AREA_SOURCE_M 2 // Memory Marks
#define S7_AREA_SOURCE_DB 3 // Data Blocks
// Define different S7 data types
#define S7_TYPE_BOOL 1
#define S7_TYPE_BYTE 2
#define S7_TYPE_SINT 3
#define S7_TYPE_WORD 4
#define S7_TYPE_UINT 5
#define S7_TYPE_INT 6
#define S7_TYPE_DWORD 7
#define S7_TYPE_UDINT 8
#define S7_TYPE_DINT 9
#define S7_TYPE_LWORD 10
#define S7_TYPE_ULINT 11
#define S7_TYPE_LINT 12
#define S7_TYPE_REAL 13
#define S7_TYPE_LREAL 14
#define S7_TYPE_STRING 15
#define S7_TYPE_ARRAYCHAR 16
#define S7_TYPE_TOD 17
#define S7_TYPE_DATE 18
#define S7_TYPE_DATE_AND_TIME 19
#define S7_TYPE_DTL 20
struct TOD
{
uint32_t h;
uint32_t m;
uint32_t s;
uint32_t ms;
};
struct DATE
{
uint32_t year;
uint32_t month;
uint32_t day;
};
struct DATE_AND_TIME
{
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t hour;
uint16_t minute;
uint16_t second;
uint16_t msec;
uint16_t weekday;
};
struct DTL
{
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t weekday;
uint16_t hour;
uint16_t minute;
uint16_t second;
uint32_t nanosec;
};
std::string S7_GetTxtPLCType (short int plcType); // Get Text description of PLC Type
int S7_GetDataTypeSize (int type); // Get data type size
uint16_t S7_GetWordFromTSAP ( std::string TSAP); // Get the word from Transport Service Access Point (TSAP) in hex format, e.g: 10.02 => 0x1002, used by Cli_SetConnectionParams
std::string S7_GetTxtAreaSource (int areaSource); // Get Text message of Area Source
int S7_BDCToByte (byte B); // Get BDC and convert to byte
byte S7_ByteToBDC (int Value); // Convert Byte to BDC
bool S7_GetBitAt ( byte Buffer[], int Pos, int Bit); // Get Bit position at buffer of bytes
void S7_SetBitAt ( byte Buffer[], int Pos, int Bit, bool Value); // Set Bit position at buffer of bytes
uint8_t S7_GetByteAt(byte Buffer[], int Pos); // Get Byte (0..255) at buffer of bytes
void S7_SetByteAt(byte Buffer[], int Pos, uint8_t Value ); // Set Byte (0..255) at buffer of bytes
int8_t S7_GetSIntAt(byte Buffer[], int Pos); // Get SInt (-128..127) at buffer of bytes
void S7_SetSIntAt(byte Buffer[], int Pos, int Value); // Set SInt (-128..127) at buffer of bytes
uint16_t S7_GetUIntAt(byte Buffer[], int Pos); // Get 16 bit unsigned value (S7 UInt) 0..65535
void S7_SetUIntAt(byte Buffer[], int Pos, uint16_t Value ); // Set 16 bit unsigned value (S7 UInt) 0..65535
uint16_t S7_GetWordAt(byte Buffer[], int Pos); // Get 16 bit unsigned value (S7 UInt) 0..65535
void S7_SetWordAt(byte Buffer[], int Pos, uint16_t Value ); // Set 16 bit unsigned value (S7 UInt) 0..65535
int16_t S7_GetIntAt(byte Buffer[], int Pos); // Get 16 bit signed value (S7 int) -32768..32767 at buffer of bytes
void S7_SetIntAt(byte Buffer[], int Pos, int16_t Value); // Set 16 bit signed value (S7 int) -32768..32767 at buffer of bytes
uint32_t S7_GetUDIntAt(byte Buffer[], int Pos); // Get 32 bit unsigned value (S7 UDInt) 0..4294967295
void S7_SetUDIntAt(byte Buffer[], int Pos, uint32_t Value); // Set 32 bit unsigned value (S7 UDInt) 0..4294967295
uint32_t S7_GetDWordAt(byte Buffer[], int Pos); // Get 32 bit unsigned value (S7 UDInt) 0..4294967295
void S7_SetDWordAt(byte Buffer[], int Pos, uint32_t Value); // Set 32 bit unsigned value (S7 UDInt) 0..4294967295
long S7_GetDIntAt(byte Buffer[], int Pos); // Get 32 bit signed value (S7 DInt) -2147483648..2147483647
void S7_SetDIntAt(byte Buffer[], int Pos, long Value); // Set 32 bit signed value (S7 DInt) -2147483648..2147483647
uint64_t S7_GetULIntAt(byte Buffer[], int Pos); // Set 64 bit unsigned value (S7 ULint) 0..18446744073709551615
void S7_SetULIntAt(byte Buffer[], int Pos, uint64_t Value); // Set 64 bit unsigned value (S7 ULint) 0..18446744073709551615
uint64_t S7_GetLWordAt(byte Buffer[], int Pos); // Set 64 bit unsigned value (S7 ULint) 0..18446744073709551615
void S7_SetLWordAt(byte Buffer[], int Pos, uint64_t Value); // Set 64 bit unsigned value (S7 ULint) 0..18446744073709551615
int64_t S7_GetLIntAt(byte Buffer[], int Pos); // Get 64 bit signed value (S7 LInt) -9223372036854775808..9223372036854775807
void S7_SetLIntAt(byte Buffer[], int Pos, int64_t Value); // Set 64 bit signed value (S7 LInt) -9223372036854775808..9223372036854775807
float S7_GetRealAt(byte Buffer[], int Pos); // Get 32 bit floating point number (S7 Real) (Range of float)
void S7_SetRealAt(byte Buffer[], int Pos, float Value); // Set 32 bit floating point number (S7 Real) (Range of float)
double S7_GetLRealAt(byte Buffer[], int Pos); // Get 64 bit floating point number (S7 LReal) (Range of double)
void S7_SetLRealAt(byte Buffer[], int Pos, double Value); // Set 64 bit floating point number (S7 LReal) (Range of double)
std::string S7_GetStringAt(byte Buffer[], int Pos); // Get String (S7 String)
void S7_SetStringAt(byte Buffer[], int Pos, int MaxLen, std::string Value); // Set String (S7 String)
std::string S7_GetCharsAt(byte Buffer[], int Pos, int Size); //Get Array of char (S7 ARRAY OF CHARS)
void S7_SetCharsAt(byte Buffer[], int BufferLen, int Pos, std::string Value); //Set Array of char (S7 ARRAY OF CHARS)
TOD S7_GetTODAt(byte Buffer[], int Pos); // Get struct of TOD (S7 TOD)
void S7_SetTODAt(byte Buffer[], int Pos, uint32_t hour, uint32_t minute, uint32_t second, uint32_t msec); // Set struct of TOD(S7 TOD)
DATE S7_GetDATEAt(byte Buffer[], int Pos); // Get struct of DATE (S7 DATE)
void S7_SetDATEAt(byte Buffer[], int Pos, uint32_t year, uint32_t month, uint32_t day); // Set struct of DATE (S7 DATE)
DATE_AND_TIME S7_GetDATE_AND_TIMEAt(byte Buffer[], int Pos); // Get struct of DATE_AND_TIME (S7 DATE_AND_TIME)
void S7_SetDATE_AND_TIMEAt(byte Buffer[], int Pos, uint16_t year, uint16_t month, uint16_t day, uint16_t hour, uint16_t minute, uint16_t second, uint16_t msec); // Set struct of DATE_AND_TIME (S7 DATE_AND_TIME)
DTL S7_GetDTLAt(byte Buffer[], int Pos); // Get struct of DTL (S7 DTL)
void S7_SetDTLAt(byte Buffer[], int Pos, uint16_t year, uint16_t month, uint16_t day, uint16_t hour, uint16_t minute, uint16_t second, uint32_t nanosec); // Set struct of DTL (S7 DTL)
#endif // S7_H