rllib  1
rlsiemenstcp.h
Go to the documentation of this file.
1 /***************************************************************************
2  rlsiemenstcp.h - description
3  -------------------
4  begin : Mon Mar 08 2004
5  copyright : (C) 2004 by R. Lehrig
6  email : lehrig@t-online.de
7 
8  S7_200 update : Wed Mar 21 2007
9  copyright : (C) 2007 by Aljosa Merljak
10  Email : aljosa.merljak@datapan.si
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This library is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
17  * published by the Free Software Foundation *
18  * *
19  ***************************************************************************/
20 #ifndef _RL_SIEMENS_TCP_H_
21 #define _RL_SIEMENS_TCP_H_
22 
23 #include "rldefine.h"
24 #include "rlsocket.h"
25 
130 class rlSiemensTCP : public rlSocket
131 {
132 public:
133  enum ORG
134  {
135  ORG_DB = 1,
136  ORG_M = 2,
137  ORG_E = 3,
138  ORG_A = 4,
139  ORG_PEPA = 5,
140  ORG_Z = 6,
141  ORG_T = 7
142  };
143  enum PLC_TYPE
144  {
146  S7_200 = 1,
147  S7_300 = 2,
148  S7_400 = 3,
149  S5 = 4,
151  S7_1200 = 6, // patch from user slammera from our forum (8 Nov 2012)
152  LOGO = 7 // LOGO! 0BA7, according to jjmg_engenharia from our forum (3 Sep 2013)
153  };
155  {
156  WriteBit = 1,
158  };
159  rlSiemensTCP(const char *adr, int _plc_type=rlSiemensTCP::ANY_SIEMENS_COMPATIBLE_PLC, int _fetch_write = 1, int function = -1, int rack_slot = -1);
160  virtual ~rlSiemensTCP();
163  int getDefaultConnectBlock(unsigned char *connect_block);
164  int setConnectBlock(const unsigned char *connect_block);
165  int getConnectBlock(unsigned char *connect_block);
166  int write(int org, int dbnr, int start_adr, int length, const unsigned char *buf, int function=WriteByte);
167  int fetch(int org, int dbnr, int start_adr, int length, unsigned char *buf);
168 private:
169  void doConnect();
170  int read_iso(unsigned char *buf);
171  int write_iso(unsigned char *buf, int len);
172  int getOrg(int org);
173  int write_bit(int& i, int org, int dbnr, int start_adr, int len, const unsigned char *buf);
174  int write_byte(int& i, int org, int dbnr, int start_adr, int length, const unsigned char *buf);
175  typedef struct
176  {
177  unsigned char version;
178  unsigned char reserved;
179  unsigned char length_high;
180  unsigned char length_low;
181  }IH; // iso header
182  typedef struct
183  {
184  unsigned char ident[2];
185  unsigned char header_len;
186  unsigned char ident_op_code;
187  unsigned char op_code_len;
188  unsigned char op_code;
189  unsigned char ident_org_block;
190  unsigned char len_org_block;
191  unsigned char org_block;
192  unsigned char dbnr;
193  unsigned char start_adr[2];
194  unsigned char len[2];
195  unsigned char spare1;
196  unsigned char spare1_len;
197  }WH; // write header
198  typedef struct
199  {
200  unsigned char ident[2];
201  unsigned char header_len;
202  unsigned char ident_op_code;
203  unsigned char op_code_len;
204  unsigned char op_code;
205  unsigned char ack_block;
206  unsigned char ack_block_len;
207  unsigned char error_block;
208  unsigned char spare1;
209  unsigned char spare1_len;
210  unsigned char spare2[5];
211  }WA; // write ack
212  typedef struct
213  {
214  unsigned char ident[2];
215  unsigned char header_len;
216  unsigned char ident_op_code;
217  unsigned char op_code_len;
218  unsigned char op_code;
219  unsigned char ident_org_block;
220  unsigned char len_org_block;
221  unsigned char org_block;
222  unsigned char dbnr;
223  unsigned char start_adr[2];
224  unsigned char len[2];
225  unsigned char spare1;
226  unsigned char spare1_len;
227  }FH; // fetch header
228  typedef struct
229  {
230  unsigned char ident[2];
231  unsigned char header_len;
232  unsigned char ident_op_code;
233  unsigned char op_code_len;
234  unsigned char op_code;
235  unsigned char ack_block;
236  unsigned char ack_block_len;
237  unsigned char error_block;
238  unsigned char spare1;
239  unsigned char spare1_len;
240  unsigned char spare2[5];
241  }FA; // fetch ack
247  int function, rack_slot;
248  int plc_type;
250  unsigned char pdu[2048];
251  int use_cb;
252  unsigned char cb[22];
253 };
254 
255 #endif
unsigned char ack_block_len
Definition: rlsiemenstcp.h:206
unsigned char spare1_len
Definition: rlsiemenstcp.h:196
unsigned char error_block
Definition: rlsiemenstcp.h:207
virtual ~rlSiemensTCP()
unsigned char op_code
Definition: rlsiemenstcp.h:204
unsigned char len_org_block
Definition: rlsiemenstcp.h:220
int write_iso(unsigned char *buf, int len)
unsigned char spare1
Definition: rlsiemenstcp.h:195
unsigned char version
Definition: rlsiemenstcp.h:177
unsigned char ident_org_block
Definition: rlsiemenstcp.h:219
unsigned char ack_block_len
Definition: rlsiemenstcp.h:236
unsigned char error_block
Definition: rlsiemenstcp.h:237
unsigned char org_block
Definition: rlsiemenstcp.h:191
unsigned char length_low
Definition: rlsiemenstcp.h:180
unsigned char op_code
Definition: rlsiemenstcp.h:188
unsigned char op_code_len
Definition: rlsiemenstcp.h:187
unsigned char len_org_block
Definition: rlsiemenstcp.h:190
unsigned char header_len
Definition: rlsiemenstcp.h:185
unsigned char spare1
Definition: rlsiemenstcp.h:238
unsigned char op_code_len
Definition: rlsiemenstcp.h:233
unsigned char dbnr
Definition: rlsiemenstcp.h:222
unsigned char org_block
Definition: rlsiemenstcp.h:221
int read_iso(unsigned char *buf)
int setConnectBlock(const unsigned char *connect_block)
unsigned char pdu[2048]
Definition: rlsiemenstcp.h:250
unsigned char ack_block
Definition: rlsiemenstcp.h:235
unsigned char dbnr
Definition: rlsiemenstcp.h:192
int getConnectBlock(unsigned char *connect_block)
unsigned char ack_block
Definition: rlsiemenstcp.h:205
unsigned char header_len
Definition: rlsiemenstcp.h:201
char adr[132]
Definition: rlsocket.h:261
int getDefaultConnectBlock(unsigned char *connect_block)
int getOrg(int org)
unsigned char op_code
Definition: rlsiemenstcp.h:218
int write_bit(int &i, int org, int dbnr, int start_adr, int len, const unsigned char *buf)
unsigned char spare1_len
Definition: rlsiemenstcp.h:226
unsigned char ident_op_code
Definition: rlsiemenstcp.h:232
int fetch(int org, int dbnr, int start_adr, int length, unsigned char *buf)
void doConnect()
unsigned char spare1_len
Definition: rlsiemenstcp.h:209
unsigned char ident_op_code
Definition: rlsiemenstcp.h:216
unsigned char ident_op_code
Definition: rlsiemenstcp.h:186
unsigned char ident_op_code
Definition: rlsiemenstcp.h:202
unsigned char spare1_len
Definition: rlsiemenstcp.h:239
unsigned char reserved
Definition: rlsiemenstcp.h:178
unsigned char header_len
Definition: rlsiemenstcp.h:231
unsigned char op_code_len
Definition: rlsiemenstcp.h:203
unsigned char spare1
Definition: rlsiemenstcp.h:208
int write_byte(int &i, int org, int dbnr, int start_adr, int length, const unsigned char *buf)
int write(int org, int dbnr, int start_adr, int length, const unsigned char *buf, int function=WriteByte)
unsigned char spare1
Definition: rlsiemenstcp.h:225
unsigned char op_code_len
Definition: rlsiemenstcp.h:217
unsigned char cb[22]
Definition: rlsiemenstcp.h:252
unsigned char header_len
Definition: rlsiemenstcp.h:215
unsigned char op_code
Definition: rlsiemenstcp.h:234
unsigned char length_high
Definition: rlsiemenstcp.h:179
unsigned char ident_org_block
Definition: rlsiemenstcp.h:189
rlSiemensTCP(const char *adr, int _plc_type=rlSiemensTCP::ANY_SIEMENS_COMPATIBLE_PLC, int _fetch_write=1, int function=-1, int rack_slot=-1)