-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths7connection.h
163 lines (136 loc) · 4.89 KB
/
s7connection.h
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
/******************************************************************************
* *File: s7connection.h *
* *Date: 2013-06-01 *
* *Version: 1.0 *
* *Author(s): Jochen Bauer <[email protected]> *
* Lukas Kern <[email protected]> *
* Carsten Klein <[email protected]> *
* *
* *License information: *
* *
* Copyright (C) [2013] [Jochen Bauer, Lukas Kern, Carsten Klein] *
* *
* This file is part of PLCANALYZER. PLCANALYZER is free software; you can *
* redistribute it and/or modify it under the terms of the GNU General *
* Public License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301, USA. *
* *
* *Program name: PLCANALYZER *
* *What this program does: Connects to most SIMATIC S7/S5 Controllers *
* * Reads memory areas *
* * Draws a graph over time for operands *
* *Have fun! *
******************************************************************************/
#ifndef S7CONNECTION_H
#define S7CONNECTION_H
#include <QMessageBox>
#include <QDebug>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cstdint>
#ifdef LINUX
#include <unistd.h>
#include <sys/time.h>
#include <fcntl.h>
#define UNIX_STYLE
#endif
#ifdef BCCWIN
#include <windows.h>
#include <time.h>
#include <windows.h>
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#define WIN_STYLE
#endif
#include "nodave.h"
#include "openS7online.h"
#include "openSocket.h"
// Verfügbare Anzeigeformate
#define AnzFormatBinaer 1
#define AnzFormatBool 2
#define AnzFormatDezimal 3
#define AnzFormatHexadezimal 4
#define AnzFormatGleitpunkt 5
#define AnzFormatZeichen 6
// Datenlänge in Bit
#define DatLenBit 1
#define DatLenByte 8
#define DatLenWord 16
#define DatLenDWord 32
// Connection Settings
struct ConSets
{
int localMPI;
int useProto;
int speed;
int plcMPI;
int plc2MPI;
int rack;
int slot;
QString IP_Adr;
};
// Union Datentypen
union OutputTypes
{
bool Bit;
char Byte;
int16_t Int;
int32_t DInt;
float Real;
};
// Connection Slot
struct ConSlot
{
int iAdrBereich;
int iDBnummer;
int iStartAdr;
int iBitnummer;
int iDatenlaenge;
int iAnzFormat;
QColor graphColor;
OutputTypes RetVal;
};
class S7Connection
{
private:
// Private Variables
_daveOSserialType fds;
daveInterface * di;
daveConnection * dc, *dc2;
bool initSuccess;
// Private Functions
public:
// Public Functions
// Class constructor
S7Connection();
// Class deconstructor
~S7Connection();
// Opens the Connection witch is set in MyConSets
bool startConnection(WId WndHandle);
// Disconnect from PLC, and frees all reserved memory
void disconnect();
// Currently only a certain operand is read. To be thrown away or rewritten!
int getValue();
// Returns the connection status
bool isConnected();
// Reads all variables handed in the Slotvector and writes them back
void readSlots(QVector<ConSlot> &cSlot, int iAmountSlots);
// Value output in the desired format from handed slot
QString interpret(ConSlot &cSlot);
// Value output just in decimal oder or float format for graph output
QString interpret(ConSlot &cSlot, bool bGraphOutput);
// Public Variables
// Declaire pointer for connection settings
ConSets* MyConSet;
};
#endif // S7CONNECTION_H