rlSiemensTCP Class Reference

#include <rlsiemenstcp.h>

Inheritance diagram for rlSiemensTCP:
Inheritance graph
[legend]
Collaboration diagram for rlSiemensTCP:
Collaboration graph
[legend]

List of all members.

Classes

struct  FA
struct  FH
struct  IH
struct  WA
struct  WH

Public Types

enum  ORG {
  ORG_DB = 1, ORG_M = 2, ORG_E = 3, ORG_A = 4,
  ORG_PEPA = 5, ORG_Z = 6, ORG_T = 7
}
enum  PLC_TYPE {
  S7_200 = 1, S7_300 = 2, S7_400 = 3, S5 = 4,
  RACK_SLOT = 5
}
enum  SiemensFunctionCodes { WriteBit = 1, WriteByte = 2 }

Public Member Functions

 rlSiemensTCP (const char *adr, int _plc_type, int _fetch_write=1, int function=-1, int rack_slot=-1)
virtual ~rlSiemensTCP ()
int write (int org, int dbnr, int start_adr, int length, const unsigned char *buf, int function=WriteByte)
int fetch (int org, int dbnr, int start_adr, int length, unsigned char *buf)

Private Member Functions

void doConnect ()
int read_iso (unsigned char *buf)
int write_iso (unsigned char *buf, int len)
int getOrg (int org)
int write_bit (int &i, int org, int dbnr, int start_adr, int len, const unsigned char *buf)
int write_byte (int &i, int org, int dbnr, int start_adr, int length, const unsigned char *buf)

Private Attributes

WH wh
WA wa
FH fh
FA fa
IH ih
int function
int rack_slot
int plc_type
int fetch_write
unsigned char pdu [2048]

Detailed Description

class for communication with Siemens PLC's via TCP

Definition at line 29 of file rlsiemenstcp.h.


Member Enumeration Documentation

Enumerator:
ORG_DB 
ORG_M 
ORG_E 
ORG_A 
ORG_PEPA 
ORG_Z 
ORG_T 

Definition at line 32 of file rlsiemenstcp.h.

00033   {
00034     ORG_DB   = 1,
00035     ORG_M    = 2,
00036     ORG_E    = 3,
00037     ORG_A    = 4,
00038     ORG_PEPA = 5,
00039     ORG_Z    = 6,
00040     ORG_T    = 7
00041   };

Enumerator:
S7_200 
S7_300 
S7_400 
S5 
RACK_SLOT 

Definition at line 42 of file rlsiemenstcp.h.

00043   {
00044     S7_200    = 1,
00045     S7_300    = 2,
00046     S7_400    = 3,
00047     S5        = 4,
00048     RACK_SLOT = 5
00049   };

Enumerator:
WriteBit 
WriteByte 

Definition at line 50 of file rlsiemenstcp.h.

00051   {
00052     WriteBit   = 1,
00053     WriteByte  = 2
00054   };


Constructor & Destructor Documentation

rlSiemensTCP::rlSiemensTCP ( const char *  adr,
int  _plc_type,
int  _fetch_write = 1,
int  function = -1,
int  rack_slot = -1 
)

Definition at line 37 of file rlsiemenstcp.cpp.

00038              :rlSocket(a,ISO_PORT,1)
00039 {
00040   plc_type = _plc_type;
00041   fetch_write = _fetch_write;
00042   function = _function;
00043   rack_slot = _rack_slot;
00044   doConnect();
00045 }

rlSiemensTCP::~rlSiemensTCP (  )  [virtual]

Definition at line 47 of file rlsiemenstcp.cpp.

00048 {
00049   rlSocket::disconnect();
00050 }


Member Function Documentation

void rlSiemensTCP::doConnect (  )  [private]

Definition at line 52 of file rlsiemenstcp.cpp.

00053 {
00054   int i,i2,ret,length;
00055   static const unsigned char s7_200_connect_block[] =
00056     {3,0,0,22,0x11,0xE0,0x00,0x00,0x00,0x01,0x00,0xC1,2,'M','W',0xC2,2,'M','W',0xC0,1,9};
00057   static const unsigned char s7_300_connect_block[] =
00058     {3,0,0,22,0x11,0xE0,0x00,0x00,0x00,0x01,0x00,0xC1,2,1  ,0  ,0xC2,2,1  ,2  ,0xC0,1,9};
00059   static const unsigned char s7_400_connect_block[] =
00060     {3,0,0,22,0x11,0xE0,0x00,0x00,0x00,0x01,0x00,0xC1,2,1  ,0  ,0xC2,2,1  ,3  ,0xC0,1,9};
00061   static const unsigned char other_connect_block[] =
00062     {3,0,0,22,0x11,0xE0,0x00,0x00,0x00,0x01,0x00,0xC1,2,1  ,0  ,0xC2,2,0  ,1  ,0xC0,1,9};
00063   unsigned char connect_block[22];
00064 
00065   unsigned char connect_block2[] = 
00066     {0x03,0x00,0x00,0x19,0x02,0xF0,0x80,0x32,0x01,0x00,0x00,0xCC,0xC1,0x00,0x08,0x00,0x00,0xF0,0x00,0x00,0x01,0x00,0x01,0x03,0xC0};  
00067   unsigned char buf[512];
00068 
00069   if     (plc_type == S7_200) memcpy(connect_block,s7_200_connect_block,sizeof(connect_block));
00070   else if(plc_type == S7_300) memcpy(connect_block,s7_300_connect_block,sizeof(connect_block));
00071   else if(plc_type == S7_400) memcpy(connect_block,s7_400_connect_block,sizeof(connect_block));
00072   else                        memcpy(connect_block,other_connect_block,sizeof(connect_block));
00073 
00074   // according to an unproofen theory siemens chooses the TSAP as follows
00075   // connect_block[17] = 2; Function (1=PG,2=OP,3=Step7Basic)
00076   // connect_block[18] = upper_3_bit_is_rack / lower_5_bit_is_slot
00077   // Hint: use tcpdump to figure it out (host = ip_adr of your PLC)
00078   // tcpdump -A -i eth0 -t -q -s 0 "host 192.168.1.14 && port 102"
00079   if(function  != -1) connect_block[17] = function;
00080   if(rack_slot != -1) connect_block[18] = rack_slot;
00081 
00082   for(i=0; i<3; i++)
00083   {
00084     if(rlSocket::connect() >= 0)
00085     {
00086       // exchange TSAP
00087       rlDebugPrintf("write connect_block\n");
00088       rlSocket::write(connect_block,sizeof(connect_block));
00089       ret = rlSocket::read(&ih,sizeof(ih),TIMEOUT);
00090       rlDebugPrintf("read ih ret=%d\n",ret);
00091       if(ret <= 0) { rlSocket::disconnect(); continue; }
00092       length = ih.length_high*256 + ih.length_low;
00093       rlDebugPrintf("read buf length=%d\n",length);
00094       ret = rlSocket::read(buf,length-sizeof(ih),TIMEOUT);
00095       rlDebugPrintf("read buf ret=%d\n",ret);
00096       if(ret <= 0) { rlSocket::disconnect(); continue; }
00097       if(length == 22)
00098       {
00099         for(i2=0; i2<3; i2++)
00100         {
00101           rlDebugPrintf("write connect_block2\n");
00102           rlSocket::write(connect_block2,sizeof(connect_block2));
00103           ret = rlSocket::read(&ih,sizeof(ih),TIMEOUT);
00104           rlDebugPrintf("read2 ih ret=%d\n",ret);
00105           length = ih.length_high*256 + ih.length_low;
00106           rlDebugPrintf("read2 buf length=%d\n",length);
00107           ret = rlSocket::read(buf,length-sizeof(ih),TIMEOUT);
00108           rlDebugPrintf("read2 buf ret=%d\n",ret);
00109           if(ret <= 0) { rlSocket::disconnect(); continue; }
00110           if(ret > 0) 
00111           {
00112             rlDebugPrintf("connect success\n");
00113             return;
00114           }  
00115         }
00116         rlSocket::disconnect();
00117         return;
00118       }
00119     }
00120     else
00121     {
00122       rlsleep(100);
00123       rlDebugPrintf("connect failed\n");
00124     }
00125   }
00126 }

int rlSiemensTCP::fetch ( int  org,
int  dbnr,
int  start_adr,
int  length,
unsigned char *  buf 
)

Definition at line 357 of file rlsiemenstcp.cpp.

00358 {
00359   int i,ret,len_byte,length;
00360 
00361   if(rlSocket::isConnected() == 0) doConnect();
00362   if(rlSocket::isConnected() == 0) return -1;
00363 
00364   len_byte = len;
00365   //if(org == ORG_DB) len_byte *= 2;
00366   //if(org == ORG_Z)  len_byte *= 2;
00367   //if(org == ORG_T)  len_byte *= 2;
00368 
00369   if((plc_type == S5 || plc_type == S7_300 || plc_type == S7_400) && fetch_write == 1)
00370   {
00371     length = sizeof(ih) + sizeof(fh);
00372     ih.version  = 3;
00373     ih.reserved = 0;
00374     ih.length_high = length / 256;
00375     ih.length_low  = length & 0x0ff;
00376     fh.ident[0]        = 'S';
00377     fh.ident[1]        = '5';
00378     fh.header_len      = 16;
00379     fh.ident_op_code   = 1;
00380     fh.op_code_len     = 3;
00381     fh.op_code         = 5;
00382     fh.ident_org_block = 3;
00383     fh.len_org_block   = 8;
00384     fh.org_block       = (unsigned char) org;
00385     fh.dbnr            = (unsigned char) dbnr;
00386     fh.start_adr[0]    = (unsigned char) start_adr / 256;
00387     fh.start_adr[1]    = (unsigned char) start_adr & 0x0ff;;
00388     fh.len[0]          = (unsigned char) len / 256;
00389     fh.len[1]          = (unsigned char) len & 0x0ff;;
00390     fh.spare1          = 0x0ff;
00391     fh.spare1_len      = 2;
00392     ret = rlSocket::write(&ih,sizeof(ih));
00393     rlDebugPrintf("fetch write ih ret=%d\n",ret);
00394     if(ret < 0) return ret;  
00395     ret = rlSocket::write(&fh,sizeof(fh));
00396     rlDebugPrintf("fetch write fh ret=%d\n",ret);
00397     if(ret < 0) return ret;
00398     ret = rlSocket::read(&ih,sizeof(ih),TIMEOUT);
00399     rlDebugPrintf("fetch read ih ret=%d\n",ret);
00400     if(ret <= 0) return ret;
00401     ret = rlSocket::read(&fa,sizeof(fa),TIMEOUT);
00402     rlDebugPrintf("fetch read fa ret=%d\n",ret);
00403     if(ret <= 0) return ret;
00404     if(fa.error_block != 0) return -1;
00405     ret = rlSocket::read(buf,len_byte,TIMEOUT);
00406     rlDebugPrintf("fetch read buf ret=%d\n",ret);
00407     if(ret <= 0) return ret;
00408   }
00409   else
00410   {
00411     i = 0;
00412     pdu[i++] = 0x02;  // [0]
00413     pdu[i++] = 0xF0;  // [0]
00414     pdu[i++] = 0x80;  // [0]
00415     pdu[i++] = 0x32;  // [0]
00416     pdu[i++] = 0x01;  // [0]
00417     pdu[i++] = 0x00;  // [0]
00418     pdu[i++] = 0x00;  // [0]
00419     pdu[i++] = 0x00;  // [0]
00420     pdu[i++] = 0x00;  // [0]
00421     pdu[i++] = 0x00;  // [0]
00422     pdu[i++] = 0x0E;  // [0]
00423     pdu[i++] = 0x00;  // [0]
00424     pdu[i++] = 0x00;  // [0]
00425     pdu[i++] = 0x04;  // [0]  read
00426     pdu[i++] = 0x01;  // [1]
00427     pdu[i++] = 0x12;  // [2]
00428     pdu[i++] = 0x0A;  // [3]
00429     pdu[i++] = 0x10;  // [4]
00430     pdu[i++] = 0x02;  // [5] 
00431     pdu[i++] = len_byte / 256;              //0x00;  // [6]  len/bytes
00432     pdu[i++] = len_byte & 0x0ff;            //0x40;  // [7]  len/bytes
00433     pdu[i++] = dbnr / 256;                  //0x00;  // [8]  dbnum
00434     pdu[i++] = dbnr & 0x0ff;                //0x01;  // [9]  dbnum
00435     pdu[i++] = getOrg(org);                 //10 
00436     pdu[i] =  (start_adr/256) & 0x0ff;      //0x00;  // [11] start adr/bits
00437     if (plc_type == S7_200) pdu[i] = start_adr / 0x10000;
00438     i++;
00439     pdu[i++] = ((start_adr*8)/256) & 0x0ff; //0x00;  // [12] start adr/bits
00440     pdu[i++] =  (start_adr*8)      & 0x0ff; //0x00;  // [13] start adr/bits
00441     ret = write_iso(pdu,i);
00442     if(ret < 0) return ret;
00443     ret = read_iso(pdu);
00444     if(ret < 0) return ret;    
00445     if(pdu[15] != 0x04) return -1;
00446     if(pdu[16] != 0x01) return -1;
00447     i = 21;
00448     if(ret < i+len_byte) return -1;
00449     for(int ibuf = 0; ibuf < len_byte; ibuf++)
00450     {
00451       buf[ibuf] = pdu[i++];
00452     }
00453   }
00454 
00455   return len_byte;
00456 }

int rlSiemensTCP::getOrg ( int  org  )  [private]

Definition at line 128 of file rlsiemenstcp.cpp.

00129 {
00130   int ret;
00131   switch(org)
00132   {
00133     case ORG_DB:   ret = 0x84;  break;    //[10] Datenbaustein
00134     case ORG_M:    ret = 0x83;  break;    //[10] Merker
00135     case ORG_E:    ret = 0x81;  break;    //[10] Eingang
00136     case ORG_A:    ret = 0x82;  break;    //[10] Ausgang
00137     case ORG_PEPA: ret = 0x84;  break;    //[10] not tested
00138     case ORG_Z:    ret = 0x84;  break;    //[10] not tested
00139     case ORG_T:    ret = 29;    break;    //[10] Timer
00140     default:       return 0x83; break;
00141   }
00142   return ret;
00143 }

int rlSiemensTCP::read_iso ( unsigned char *  buf  )  [private]

Definition at line 458 of file rlsiemenstcp.cpp.

00459 {
00460   int i,ret,len;
00461 
00462   ret = rlSocket::read(&ih,sizeof(ih),TIMEOUT);
00463   if(ret < 0)                 { rlSocket::disconnect(); return ret; }
00464   if(ih.version != 3)         { rlSocket::disconnect(); return -1;  }
00465   len = ih.length_high*256 + ih.length_low - 4;
00466   if(len <= 0)                { rlSocket::disconnect(); return -1;  }
00467   if(len > (int) sizeof(pdu)) { rlSocket::disconnect(); return -1;  }
00468   ret = rlSocket::read(buf,len,TIMEOUT);
00469   if(ret < 0)                 { rlSocket::disconnect(); return ret; }
00470   if(rlDebugPrintfState != 0)
00471   {
00472     ::printf("read_iso() len=%d\n", len);
00473     for(i=0; i<len; i++) ::printf("%02x,",buf[i]);
00474     ::printf("\n");
00475   }
00476   return len;
00477 }

int rlSiemensTCP::write ( int  org,
int  dbnr,
int  start_adr,
int  length,
const unsigned char *  buf,
int  function = WriteByte 
)
  

Definition at line 145 of file rlsiemenstcp.cpp.

00146 {
00147   int i,ibuf,ret,len_byte,length;
00148   if(rlSocket::isConnected() == 0) doConnect();
00149   if(rlSocket::isConnected() == 0) return -1;
00150 
00151   len_byte = len;
00152   //if(org == ORG_DB) len_byte *= 2;
00153   //if(org == ORG_Z)  len_byte *= 2;
00154   //if(org == ORG_T)  len_byte *= 2;
00155   
00156   if((plc_type == S5 || plc_type == S7_300 || plc_type == S7_400) && fetch_write == 1)
00157   {
00158     rlDebugPrintf("using fetch_write\n");
00159     length = sizeof(ih) + sizeof(wh) + len_byte;
00160     ih.version  = 3;
00161     ih.reserved = 0;
00162     ih.length_high = length / 256;
00163     ih.length_low  = length & 0x0ff;
00164     wh.ident[0]        = 'S';
00165     wh.ident[1]        = '5';
00166     wh.header_len      = 16;
00167     wh.ident_op_code   = 1;
00168     wh.op_code_len     = 3;
00169     wh.op_code         = 3;
00170     wh.ident_org_block = 3;
00171     wh.len_org_block   = 8;
00172     wh.org_block       = (unsigned char) org;
00173     wh.dbnr            = (unsigned char) dbnr;
00174     wh.start_adr[0]    = (unsigned char) start_adr / 256;
00175     wh.start_adr[1]    = (unsigned char) start_adr & 0x0ff;;
00176     wh.len[0]          = (unsigned char) len / 256;
00177     wh.len[1]          = (unsigned char) len & 0x0ff;;
00178     wh.spare1          = 0x0ff;
00179     wh.spare1_len      = 2;
00180     ret = rlSocket::write(&ih,sizeof(ih));
00181     rlDebugPrintf("write ih ret=%d\n",ret);
00182     if(ret < 0) return ret;
00183     ret = rlSocket::write(&wh,sizeof(wh));
00184     rlDebugPrintf("write wh ret=%d\n",ret);
00185     if(ret < 0) return ret;
00186     ret = rlSocket::write(buf,len_byte);
00187     rlDebugPrintf("write buf ret=%d\n",ret);
00188     if(ret < 0) return ret;
00189     ret = rlSocket::read(&ih,sizeof(ih),TIMEOUT);
00190     rlDebugPrintf("read ih ret=%d\n",ret);
00191     if(ret <= 0) return ret;
00192     ret = rlSocket::read(&wa,sizeof(wa),TIMEOUT);
00193     rlDebugPrintf("read wa ret=%d\n",ret);
00194     if(ret <= 0) return ret;
00195     if(wa.error_block != 0) return -1;
00196   }
00197   else
00198   {
00199     rlDebugPrintf("not using fetch_write\n");
00200     i = 0;
00201     pdu[i++] = 0x02;
00202     pdu[i++] = 0xF0;
00203     pdu[i++] = 0x80;
00204     pdu[i++] = 0x32;
00205     pdu[i++] = 0x01;
00206     pdu[i++] = 0x00;
00207     pdu[i++] = 0x00;
00208     pdu[i++] = 0x00;
00209     pdu[i++] = 0x00;
00210     pdu[i++] = 0x00;
00211     // The S7 update by Aljosa Merljak was tested on S7_200 only
00212     // You could set your plc_type to S7_200 also, even if you have S7_300 || S7_400
00213     // But only the else part has been tested with S7_300 and S7_400 up to now
00214     //if(plc_type == S7_200)
00215     // Hi Ken, currently only S7_200 was tested with this. But try if this also works with S7_400
00216     if(plc_type == S7_200 || plc_type == S7_300 || plc_type == S7_400)
00217     {
00218       ret = 0;
00219       switch(function)
00220       {
00221          case WriteBit:   ret = write_bit  (i, org, dbnr, start_adr, len, buf); break;
00222          case WriteByte:  ret = write_byte (i, org, dbnr, start_adr, len, buf); break;
00223       }
00224       if(ret < 0) return ret;
00225     }
00226     else
00227     {
00228       pdu[i++] = 0x0E;
00229       pdu[i++] = 0x00;
00230       pdu[i++] = 0x08;
00231       pdu[i++] = 0x05; //0 write
00232       pdu[i++] = 0x01; //1
00233       pdu[i++] = 0x12; //2
00234       pdu[i++] = 0x0A; //3
00235       pdu[i++] = 0x10; //4
00236       pdu[i++] = 0x02; //5
00237       pdu[i++] = len_byte / 256;   //6 0x00;
00238       pdu[i++] = len_byte & 0x0ff; //7 0x04;
00239       pdu[i++] = dbnr / 256;       //8 0x00;
00240       pdu[i++] = dbnr & 0x0ff;     //9 0x00;
00241       pdu[i++] = getOrg(org);      //10 
00242       pdu[i++] =  (start_adr/256)    & 0x0ff; //0x00;  // [11] start adr/bits
00243       pdu[i++] = ((start_adr*8)/256) & 0x0ff; //0x00;  // [12] start adr/bits
00244       pdu[i++] =  (start_adr*8)      & 0x0ff; //0x00;  // [13] start adr/bits
00245       pdu[i++] = 0x00;
00246       pdu[i++] = 0x04;
00247       pdu[i++] = 0x00;
00248       pdu[i++] = 0x20;
00249       for(ibuf=0; ibuf<len_byte; ibuf++)
00250       {
00251         pdu[i++] = buf[ibuf];
00252         if(i > (int) sizeof(pdu)) return -1;
00253       }
00254     }  
00255     ret = write_iso(pdu,i);
00256     if(ret < 0) return ret;
00257     ret = read_iso(pdu);
00258     if(ret < 0) return ret;
00259     if(pdu[15] != 0x05) return -1;
00260     if(pdu[16] != 0x01) return -1;
00261 
00262     // CODE from Víctor Centelles
00263     if(pdu[17] != 0xff)
00264     {
00265       if(pdu[17] == 0x0a){
00266         fprintf( stderr, " > Error: Trying to access a DB that does not exist\n");
00267         fprintf( stderr, "          Please, check that DB is set.   (error code: 10 (0x0a))\n");
00268         return -(pdu[17]);
00269       }
00270       else if(pdu[17] == 0x05){
00271         fprintf(stderr, " > Error: Trying to access an address that does not exist.\n");
00272         fprintf(stderr, "          Please, check the address range. (error code: 5 (0x05))\n");
00273         return -(pdu[17]);
00274       }
00275       else if(pdu[17] == 0x07){
00276         fprintf(stderr, " > Error: the write data size doesn't fit item size\n"); // NO TESTED!!!
00277         fprintf(stderr, "          Please, check the data size.     (error code: 7 (0x07))\n");
00278         return -(pdu[17]);
00279       }
00280       else{
00281         fprintf(stderr, " > Error: unknown error  (código %x!=0xff)\n", pdu[17]);
00282         return -(pdu[17]);
00283       }
00284     }
00285   }
00286 
00287   return len_byte;
00288 }

int rlSiemensTCP::write_bit ( int &  i,
int  org,
int  dbnr,
int  start_adr,
int  len,
const unsigned char *  buf 
) [private]

Definition at line 290 of file rlsiemenstcp.cpp.

00291 {
00292   int j;
00293   pdu[i++] = 14 + 12 * (len - 1);
00294   pdu[i++] = 0x00;
00295   pdu[i++] = 6 * len - 1;
00296   pdu[i++] = 0x05;
00297   pdu[i++] = len;    
00298   for(j=0; j<len; j++)
00299   {
00300     pdu[i++] = 0x12;
00301     pdu[i++] = 0x0a;
00302     pdu[i++] = 0x10;
00303     pdu[i++] = 0x01;
00304     pdu[i++] = len / 256;        //6 0x00;
00305     pdu[i++] = 0x01;             //7 number of bytes in group
00306     pdu[i++] = dbnr / 256;       //8 0x00;
00307     pdu[i++] = dbnr & 0x0ff;     //9 0x00;
00308     pdu[i++] = getOrg(org);      //10 
00309     pdu[i++] =  (start_adr / 8)  / 0x10000;
00310     pdu[i++] = (start_adr / 256) & 0x0ff; //0x00;  // [12] start adr/bits
00311     pdu[i++] =  (start_adr + j)  & 0x0ff; //0x00;  // [13] start adr/bits     
00312   }
00313   for(j=0; j<len; j++)
00314   {
00315     pdu[i++] = 0x00;
00316     pdu[i++] = 0x03;
00317     pdu[i++] = 0x00;
00318     pdu[i++] = 0x01;
00319     pdu[i++] = (buf[j]>0) ? 0x01 : 0x00;
00320     if(j < len - 1 ) pdu[i++] = 0x00;
00321     if(i > (int) sizeof(pdu)) return -1;
00322   }
00323   return i;
00324 }

int rlSiemensTCP::write_byte ( int &  i,
int  org,
int  dbnr,
int  start_adr,
int  length,
const unsigned char *  buf 
) [private]

Definition at line 326 of file rlsiemenstcp.cpp.

00327 {
00328   pdu[i++] = 0x0e;
00329   pdu[i++] = 0x00;
00330   pdu[i++] = 5 + len - 1;
00331   pdu[i++] = 0x05;
00332   pdu[i++] = 0x01;
00333   pdu[i++] = 0x12;
00334   pdu[i++] = 0x0a;
00335   pdu[i++] = 0x10;
00336   pdu[i++] = 0x02;
00337   pdu[i++] = len / 256;   //6 0x00;
00338   pdu[i++] = len;         //7 number of bytes
00339   pdu[i++] = dbnr / 256;       //8 0x00;
00340   pdu[i++] = dbnr & 0x0ff;     //9 0x00;
00341   pdu[i++] = getOrg(org);      //10 
00342   pdu[i++] =      start_adr      / 0x10000;
00343   pdu[i++] = ((start_adr*8)/256) & 0x0ff; //0x00;  // [12] start adr/bits
00344   pdu[i++] =   (start_adr*8)     & 0x0ff; //0x00;  // [13] start adr/bits     
00345   pdu[i++] = 0x00;
00346   pdu[i++] = 0x04;
00347   pdu[i++] = (len * 8) / 256;
00348   pdu[i++] = (len * 8) & 0xff;
00349   for(int ibuf=0; ibuf<len; ibuf++)
00350   {
00351     pdu[i++] = buf[ibuf];
00352     if(i > (int) sizeof(pdu)) return -1;
00353   }
00354   return i;
00355 }

int rlSiemensTCP::write_iso ( unsigned char *  buf,
int  len 
) [private]

Definition at line 479 of file rlsiemenstcp.cpp.

00480 {
00481   int i,ret;
00482 
00483   if(rlSocket::isConnected() == 0) doConnect();
00484   if(rlSocket::isConnected() == 0) return -1;
00485   ih.version  = 3;
00486   ih.reserved = 0;
00487   ih.length_high = (len+4) / 256;
00488   ih.length_low  = (len+4) & 0x0ff;
00489   ret = rlSocket::write(&ih,sizeof(ih));
00490   if(ret < 0) { rlSocket::disconnect(); return ret; }  
00491   ret = rlSocket::write(buf,len);
00492   if(ret < 0) { rlSocket::disconnect(); return ret; }
00493   if(rlDebugPrintfState != 0)
00494   {
00495     ::printf("write_iso() len=%d\n", len);
00496     for(i=0; i<len; i++) ::printf("%02x,",buf[i]);
00497     ::printf("\n");
00498   }
00499   return len;
00500 }


Member Data Documentation

FA rlSiemensTCP::fa [private]

Definition at line 138 of file rlsiemenstcp.h.

Definition at line 142 of file rlsiemenstcp.h.

FH rlSiemensTCP::fh [private]

Definition at line 137 of file rlsiemenstcp.h.

int rlSiemensTCP::function [private]

Definition at line 140 of file rlsiemenstcp.h.

IH rlSiemensTCP::ih [private]

Definition at line 139 of file rlsiemenstcp.h.

unsigned char rlSiemensTCP::pdu[2048] [private]

Definition at line 143 of file rlsiemenstcp.h.

int rlSiemensTCP::plc_type [private]

Definition at line 141 of file rlsiemenstcp.h.

int rlSiemensTCP::rack_slot [private]

Definition at line 140 of file rlsiemenstcp.h.

WA rlSiemensTCP::wa [private]

Definition at line 136 of file rlsiemenstcp.h.

WH rlSiemensTCP::wh [private]

Definition at line 135 of file rlsiemenstcp.h.


The documentation for this class was generated from the following files:
Generated on Mon Aug 30 20:16:16 2010 for rllib by  doxygen 1.6.3