rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
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 
126 class rlSiemensTCP : public rlSocket
127 {
128 public:
129  enum ORG
130  {
131  ORG_DB = 1,
132  ORG_M = 2,
133  ORG_E = 3,
134  ORG_A = 4,
135  ORG_PEPA = 5,
136  ORG_Z = 6,
137  ORG_T = 7
138  };
139  enum PLC_TYPE
140  {
142  S7_200 = 1,
143  S7_300 = 2,
144  S7_400 = 3,
145  S5 = 4,
147  S7_1200 = 6 // patch from user slammera from our forum (8 Nov 2012)
148  };
150  {
151  WriteBit = 1,
153  };
154  rlSiemensTCP(const char *adr, int _plc_type=rlSiemensTCP::ANY_SIEMENS_COMPATIBLE_PLC, int _fetch_write = 1, int function = -1, int rack_slot = -1);
155  virtual ~rlSiemensTCP();
158  int getDefaultConnectBlock(unsigned char *connect_block);
159  int setConnectBlock(const unsigned char *connect_block);
160  int getConnectBlock(unsigned char *connect_block);
161  int write(int org, int dbnr, int start_adr, int length, const unsigned char *buf, int function=WriteByte);
162  int fetch(int org, int dbnr, int start_adr, int length, unsigned char *buf);
163 private:
164  void doConnect();
165  int read_iso(unsigned char *buf);
166  int write_iso(unsigned char *buf, int len);
167  int getOrg(int org);
168  int write_bit(int& i, int org, int dbnr, int start_adr, int len, const unsigned char *buf);
169  int write_byte(int& i, int org, int dbnr, int start_adr, int length, const unsigned char *buf);
170  typedef struct
171  {
172  unsigned char version;
173  unsigned char reserved;
174  unsigned char length_high;
175  unsigned char length_low;
176  }IH; // iso header
177  typedef struct
178  {
179  unsigned char ident[2];
180  unsigned char header_len;
181  unsigned char ident_op_code;
182  unsigned char op_code_len;
183  unsigned char op_code;
184  unsigned char ident_org_block;
185  unsigned char len_org_block;
186  unsigned char org_block;
187  unsigned char dbnr;
188  unsigned char start_adr[2];
189  unsigned char len[2];
190  unsigned char spare1;
191  unsigned char spare1_len;
192  }WH; // write header
193  typedef struct
194  {
195  unsigned char ident[2];
196  unsigned char header_len;
197  unsigned char ident_op_code;
198  unsigned char op_code_len;
199  unsigned char op_code;
200  unsigned char ack_block;
201  unsigned char ack_block_len;
202  unsigned char error_block;
203  unsigned char spare1;
204  unsigned char spare1_len;
205  unsigned char spare2[5];
206  }WA; // write ack
207  typedef struct
208  {
209  unsigned char ident[2];
210  unsigned char header_len;
211  unsigned char ident_op_code;
212  unsigned char op_code_len;
213  unsigned char op_code;
214  unsigned char ident_org_block;
215  unsigned char len_org_block;
216  unsigned char org_block;
217  unsigned char dbnr;
218  unsigned char start_adr[2];
219  unsigned char len[2];
220  unsigned char spare1;
221  unsigned char spare1_len;
222  }FH; // fetch header
223  typedef struct
224  {
225  unsigned char ident[2];
226  unsigned char header_len;
227  unsigned char ident_op_code;
228  unsigned char op_code_len;
229  unsigned char op_code;
230  unsigned char ack_block;
231  unsigned char ack_block_len;
232  unsigned char error_block;
233  unsigned char spare1;
234  unsigned char spare1_len;
235  unsigned char spare2[5];
236  }FA; // fetch ack
242  int function, rack_slot;
243  int plc_type;
245  unsigned char pdu[2048];
246  int use_cb;
247  unsigned char cb[22];
248 };
249 
250 #endif