snap7.pas 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276
  1. (*=============================================================================|
  2. | PROJECT SNAP7 1.4.0 |
  3. |==============================================================================|
  4. | Copyright (C) 2013, 2014 Davide Nardella |
  5. | All rights reserved. |
  6. |==============================================================================|
  7. | SNAP7 is free software: you can redistribute it and/or modify |
  8. | it under the terms of the Lesser GNU General Public License as published by |
  9. | the Free Software Foundation, either version 3 of the License, or |
  10. | (at your option) any later version. |
  11. | |
  12. | It means that you can distribute your commercial software linked with |
  13. | SNAP7 without the requirement to distribute the source code of your |
  14. | application and without the requirement that your application be itself |
  15. | distributed under LGPL. |
  16. | |
  17. | SNAP7 is distributed in the hope that it will be useful, |
  18. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  19. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  20. | Lesser GNU General Public License for more details. |
  21. | |
  22. | You should have received a copy of the GNU General Public License and a |
  23. | copy of Lesser GNU General Public License along with Snap7. |
  24. | If not, see http://www.gnu.org/licenses/ |
  25. |==============================================================================|
  26. | |
  27. | Object PASCAL Interface Classes |
  28. | |
  29. | Compatibility : |
  30. | Delphi/Embarcadero RAD : All 32/64 bit releases (Windows) |
  31. | FreePascal (1) : 2.4.0+ 32/64 bit (Windows/Unix) |
  32. | |
  33. |=============================================================================*)
  34. unit snap7;
  35. interface
  36. {$IFDEF FPC}
  37. {$MODE DELPHI}
  38. {$ENDIF}
  39. // Old compilers don't define MSWINDOWS
  40. {$IFDEF WIN32}
  41. {$IFNDEF MSWINDOWS}
  42. {$DEFINE MSWINDOWS}
  43. {$ENDIF}
  44. {$ENDIF}
  45. Const
  46. // Library name
  47. {$IFDEF MSWINDOWS}
  48. snaplib = 'snap7.dll';
  49. {$ELSE}
  50. snaplib = 'libsnap7.so'; // valid for all Unix platforms
  51. {$ENDIF}
  52. // Native integrals
  53. {$IFNDEF FPC}
  54. {$IF CompilerVersion<21} // below Delphi 7
  55. Type
  56. NativeUint = LongWord;
  57. NativeInt = LongInt;
  58. {$IFEND}
  59. {$ENDIF}
  60. Type
  61. S7Object = NativeUint; // Platform independent Object reference
  62. // DON'T CONFUSE IT WITH AN OLE OBJECT, IT'S SIMPLY
  63. // AN INTEGER (32 OR 64 BIT) VALUE USED AS HANDLE.
  64. //******************************************************************************
  65. // COMMON
  66. //******************************************************************************
  67. Const
  68. errLibInvalidParam = -1;
  69. errLibInvalidObject = -2;
  70. // CPU status
  71. S7CpuStatusUnknown = $00;
  72. S7CpuStatusRun = $08;
  73. S7CpuStatusStop = $04;
  74. // ISO Errors
  75. errIsoConnect = $00010000; // Connection error
  76. errIsoDisconnect = $00020000; // Disconnect error
  77. errIsoInvalidPDU = $00030000; // Bad format
  78. errIsoInvalidDataSize = $00040000; // Bad Datasize passed to send/recv buffer is invalid
  79. errIsoNullPointer = $00050000; // Null passed as pointer
  80. errIsoShortPacket = $00060000; // A short packet received
  81. errIsoTooManyFragments = $00070000; // Too many packets without EoT flag
  82. errIsoPduOverflow = $00080000; // The sum of fragments data exceded maximum packet size
  83. errIsoSendPacket = $00090000; // An error occurred during send
  84. errIsoRecvPacket = $000A0000; // An error occurred during recv
  85. errIsoInvalidParams = $000B0000; // Invalid TSAP params
  86. errIsoResvd_1 = $000C0000; // Unassigned
  87. errIsoResvd_2 = $000D0000; // Unassigned
  88. errIsoResvd_3 = $000E0000; // Unassigned
  89. errIsoResvd_4 = $000F0000; // Unassigned
  90. // Jobs
  91. JobComplete = 0;
  92. JobPending = 1;
  93. Type
  94. TS7Tag = packed record
  95. Area : integer;
  96. DBNumber : integer;
  97. Start : integer;
  98. Size : integer;
  99. WordLen : integer;
  100. end;
  101. PS7Tag = ^TS7Tag;
  102. //------------------------------------------------------------------------------
  103. // PARAMS LIST
  104. //------------------------------------------------------------------------------
  105. Const
  106. p_u16_LocalPort = 1;
  107. p_u16_RemotePort = 2;
  108. p_i32_PingTimeout = 3;
  109. p_i32_SendTimeout = 4;
  110. p_i32_RecvTimeout = 5;
  111. p_i32_WorkInterval = 6;
  112. p_u16_SrcRef = 7;
  113. p_u16_DstRef = 8;
  114. p_u16_SrcTSap = 9;
  115. p_i32_PDURequest = 10;
  116. p_i32_MaxClients = 11;
  117. p_i32_BSendTimeout = 12;
  118. p_i32_BRecvTimeout = 13;
  119. p_u32_RecoveryTime = 14;
  120. p_u32_KeepAliveTime = 15;
  121. //******************************************************************************
  122. // CLIENT
  123. //******************************************************************************
  124. // Error codes
  125. errNegotiatingPDU = $00100000;
  126. errCliInvalidParams = $00200000;
  127. errCliJobPending = $00300000;
  128. errCliTooManyItems = $00400000;
  129. errCliInvalidWordLen = $00500000;
  130. errCliPartialDataWritten = $00600000;
  131. errCliSizeOverPDU = $00700000;
  132. errCliInvalidPlcAnswer = $00800000;
  133. errCliAddressOutOfRange = $00900000;
  134. errCliInvalidTransportSize = $00A00000;
  135. errCliWriteDataSizeMismatch = $00B00000;
  136. errCliItemNotAvailable = $00C00000;
  137. errCliInvalidValue = $00D00000;
  138. errCliCannotStartPLC = $00E00000;
  139. errCliAlreadyRun = $00F00000;
  140. errCliCannotStopPLC = $01000000;
  141. errCliCannotCopyRamToRom = $01100000;
  142. errCliCannotCompress = $01200000;
  143. errCliAlreadyStop = $01300000;
  144. errCliFunNotAvailable = $01400000;
  145. errCliUploadSequenceFailed = $01500000;
  146. errCliInvalidDataSizeRecvd = $01600000;
  147. errCliInvalidBlockType = $01700000;
  148. errCliInvalidBlockNumber = $01800000;
  149. errCliInvalidBlockSize = $01900000;
  150. errCliDownloadSequenceFailed = $01A00000;
  151. errCliInsertRefused = $01B00000;
  152. errCliDeleteRefused = $01C00000;
  153. errCliNeedPassword = $01D00000;
  154. errCliInvalidPassword = $01E00000;
  155. errCliNoPasswordToSetOrClear = $01F00000;
  156. errCliJobTimeout = $02000000;
  157. errCliPartialDataRead = $02100000;
  158. errCliBufferTooSmall = $02200000;
  159. errCliFunctionRefused = $02300000;
  160. errCliDestroying = $02400000;
  161. errCliInvalidParamNumber = $02500000;
  162. errCliCannotChangeParam = $02600000;
  163. MaxVars = 20; // Max vars that can be transferred with MultiRead/MultiWrite
  164. // Client Connection Type
  165. CONNTYPE_PG = $01; // Connect to the PLC as a PG
  166. CONNTYPE_OP = $02; // Connect to the PLC as an OP
  167. CONNTYPE_BASIC = $03; // Basic connection
  168. // Area ID
  169. S7AreaPE = $81;
  170. S7AreaPA = $82;
  171. S7AreaMK = $83;
  172. S7AreaDB = $84;
  173. S7AreaCT = $1C;
  174. S7AreaTM = $1D;
  175. // Word Length
  176. S7WLBit = $01;
  177. S7WLByte = $02;
  178. S7WLChar = $03;
  179. S7WLWord = $04;
  180. S7WLInt = $05;
  181. S7WLDWord = $06;
  182. S7WLDInt = $07;
  183. S7WLReal = $08;
  184. S7WLDate = $09;
  185. S7WLTOD = $0A;
  186. S7WLTime = $0B;
  187. S7WLS5Time = $0C;
  188. S7WLDT = $0F;
  189. S7WLCounter = $1C;
  190. S7WLTimer = $1D;
  191. // Block type
  192. Block_OB = $38;
  193. Block_DB = $41;
  194. Block_SDB = $42;
  195. Block_FC = $43;
  196. Block_SFC = $44;
  197. Block_FB = $45;
  198. Block_SFB = $46;
  199. // Sub Block Type
  200. SubBlk_OB = $08;
  201. SubBlk_DB = $0A;
  202. SubBlk_SDB = $0B;
  203. SubBlk_FC = $0C;
  204. SubBlk_SFC = $0D;
  205. SubBlk_FB = $0E;
  206. SubBlk_SFB = $0F;
  207. // Block languages
  208. BlockLangAWL = $01;
  209. BlockLangKOP = $02;
  210. BlockLangFUP = $03;
  211. BlockLangSCL = $04;
  212. BlockLangDB = $05;
  213. BlockLangGRAPH = $06;
  214. Type
  215. TS7Buffer = packed array[0..$FFFF] of byte;
  216. PS7Buffer = ^TS7Buffer;
  217. TS7DataItem = packed record
  218. Area : integer;
  219. WordLen : integer;
  220. Result : integer;
  221. DBNumber : integer;
  222. Start : integer;
  223. Amount : integer;
  224. pdata : pbyte;
  225. end;
  226. PS7DataItem = ^TS7DataItem;
  227. TS7DataItems = packed array[0..MaxVars-1] of TS7DataItem;
  228. PS7DataItems = ^TS7DataItems;
  229. TS7BlocksList = packed record
  230. OBCount : integer;
  231. FBCount : integer;
  232. FCCount : integer;
  233. SFBCount : integer;
  234. SFCCount : integer;
  235. DBCount : integer;
  236. SDBCount : integer;
  237. end;
  238. PS7BlocksList = ^TS7BlocksList;
  239. TS7BlockInfo = packed record
  240. BlkType : integer;
  241. BlkNumber : integer;
  242. BlkLang : integer;
  243. BlkFlags : integer;
  244. MC7Size : integer; // The real size in bytes
  245. LoadSize : integer;
  246. LocalData : integer;
  247. SBBLength : integer;
  248. CheckSum : integer;
  249. Version : integer;
  250. // Chars info
  251. CodeDate : packed array[0..10] of AnsiChar;
  252. IntfDate : packed array[0..10] of AnsiChar;
  253. Author : packed array[0..8] of AnsiChar;
  254. Family : packed array[0..8] of AnsiChar;
  255. Header : packed array[0..8] of AnsiChar;
  256. end;
  257. PS7BlockInfo = ^TS7BlockInfo;
  258. TS7BlocksOfType = packed array[0..$1FFF] of word;
  259. PS7BlocksOfType = ^TS7BlocksOfType;
  260. TS7OrderCode = packed record
  261. Code : packed array[0..20] of AnsiChar;
  262. V1 : byte;
  263. V2 : byte;
  264. V3 : byte;
  265. end;
  266. PS7OrderCode = ^TS7OrderCode;
  267. TS7CpuInfo = packed record
  268. ModuleTypeName : packed array[0..32] of AnsiChar;
  269. SerialNumber : packed array[0..24] of AnsiChar;
  270. ASName : packed array[0..24] of AnsiChar;
  271. Copyright : packed array[0..26] of AnsiChar;
  272. ModuleName : packed array[0..24] of AnsiChar;
  273. end;
  274. PS7CpuInfo = ^TS7CpuInfo;
  275. TS7CpInfo = packed record
  276. MaxPduLengt : integer;
  277. MaxConnections : integer;
  278. MaxMpiRate : integer;
  279. MaxBusRate : integer;
  280. end;
  281. PS7CpInfo = ^TS7CpInfo;
  282. // See §33.1 of "System Software for S7-300/400 System and Standard Functions"
  283. // and see SFC51 description too
  284. SZL_HEADER = packed record
  285. LENTHDR : word;
  286. N_DR : word;
  287. end;
  288. PSZL_HEADER = ^SZL_HEADER;
  289. // SZL Record
  290. TS7SZL = packed record
  291. Header : SZL_HEADER;
  292. Data : packed array[0..$3FFF-4] of byte;
  293. end;
  294. PS7SZL = ^TS7SZL;
  295. // List of available SZL IDs : same as SZL but List items are big-endian adjusted
  296. TS7SZLList = packed record
  297. Header : SZL_HEADER;
  298. List : packed array[0..$1FFF-2] of word;
  299. end;
  300. PS7SZLList = ^TS7SZLList;
  301. // See §33.19 of "System Software for S7-300/400 System and Standard Functions"
  302. TS7Protection = packed record
  303. sch_schal : word;
  304. sch_par : word;
  305. sch_rel : word;
  306. bart_sch : word;
  307. anl_sch : word;
  308. end;
  309. PS7Protection = ^TS7Protection;
  310. // C++ time record, functions to convert it from/to TDateTime are provided ;-)
  311. TCPP_tm = packed record
  312. tm_sec : integer;
  313. tm_min : integer;
  314. tm_hour : integer;
  315. tm_mday : integer;
  316. tm_mon : integer;
  317. tm_year : integer;
  318. tm_wday : integer;
  319. tm_yday : integer;
  320. tm_isdst : integer;
  321. end;
  322. PCPP_tm = ^TCPP_tm;
  323. // Client completion callback
  324. TS7CliCompletion = procedure(usrPtr : Pointer; opCode, opResult : integer);
  325. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  326. // Control functions
  327. function Cli_Create : S7Object;
  328. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  329. procedure Cli_Destroy(var Client : S7Object);
  330. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  331. function Cli_ConnectTo(Client : S7Object; Address : PAnsiChar; Rack, Slot : integer) : integer;
  332. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  333. function Cli_SetConnectionParams(Client : S7Object; Address : PAnsiChar; LocalTSAP, RemoteTSAP : word) : integer;
  334. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  335. function Cli_SetConnectionType(Client : S7Object; ConnectionType : word) : integer;
  336. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  337. function Cli_Connect(Client : S7Object) : integer;
  338. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  339. function Cli_Disconnect(Client : S7Object) : integer;
  340. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  341. function Cli_GetParam(Client : S7Object; ParamNumber : integer; pValue : pointer) : integer;
  342. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  343. function Cli_SetParam(Client : S7Object; ParamNumber : integer; pValue : pointer) : integer;
  344. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  345. function Cli_SetAsCallback(Client : S7Object; pCompletion, usrPtr : pointer) : integer;
  346. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  347. // Data I/O functions
  348. function Cli_ReadArea(Client : S7Object; Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  349. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  350. function Cli_WriteArea(Client : S7Object; Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  351. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  352. function Cli_ReadMultiVars(Client : S7Object; Items : PS7DataItems; ItemsCount : integer) : integer;
  353. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  354. function Cli_WriteMultiVars(Client : S7Object; Items : PS7DataItems; ItemsCount : integer) : integer;
  355. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  356. // Data I/O Lean functions
  357. function Cli_DBRead(Client : S7Object; DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  358. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  359. function Cli_DBWrite(Client : S7Object; DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  360. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  361. function Cli_MBRead(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  362. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  363. function Cli_MBWrite(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  364. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  365. function Cli_EBRead(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  366. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  367. function Cli_EBWrite(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  368. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  369. function Cli_ABRead(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  370. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  371. function Cli_ABWrite(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  372. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  373. function Cli_TMRead(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  374. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  375. function Cli_TMWrite(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  376. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  377. function Cli_CTRead(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  378. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  379. function Cli_CTWrite(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  380. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  381. // Directory functions
  382. function Cli_ListBlocks(Client : S7Object; pUsrData : PS7BlocksList) : integer;
  383. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  384. function Cli_GetAgBlockInfo(Client : S7Object; BlockType, BlockNum : integer; pUsrData : PS7BlockInfo) : integer;
  385. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  386. function Cli_GetPgBlockInfo(Client : S7Object; pBlock : pointer; pUsrData : PS7BlockInfo; Size : integer) : integer;
  387. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  388. function Cli_ListBlocksOfType(Client : S7Object; BlockType : integer; pUsrData : PS7BlocksOfType; var ItemsCount : integer) : integer;
  389. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  390. // Blocks functions
  391. function Cli_Upload(Client : S7Object; BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  392. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  393. function Cli_FullUpload(Client : S7Object; BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  394. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  395. function Cli_Download(Client : S7Object; BlockNum : integer; pUsrData : pointer; Size : integer) : integer;
  396. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  397. function Cli_Delete(Client : S7Object; BlockType, BlockNum : integer) : integer;
  398. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  399. function Cli_DBGet(Client : S7Object; DBNumber : integer; pUsrData : pointer; var Size : integer) : integer;
  400. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  401. function Cli_DBFill(Client : S7Object; DBNumber : integer; FillChar : byte) : integer;
  402. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  403. // Date/Time functions
  404. function Cli_GetPlcDateTime(Client : S7Object; var DateTime : TCPP_tm) : integer;
  405. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  406. function Cli_SetPlcDateTime(Client : S7Object; var DateTime : TCPP_tm) : integer;
  407. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  408. function Cli_SetPlcSystemDateTime(Client : S7Object) : integer;
  409. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  410. // System Info functions
  411. function Cli_GetOrderCode(Client : S7Object; pUsrData : PS7OrderCode) : integer;
  412. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  413. function Cli_GetCpuInfo(Client : S7Object; pUsrData : PS7CpuInfo) : integer;
  414. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  415. function Cli_GetCPInfo(Client : S7Object; pUsrData : PS7CpInfo) : integer;
  416. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  417. function Cli_ReadSZL(Client : S7Object; ID, Index : integer; pUsrData : PS7SZL; var Size : integer) : integer;
  418. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  419. function Cli_ReadSZLList(Client : S7Object; pUsrData : PS7SZLList; var ItemsCount : integer) : integer;
  420. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  421. // Control functions
  422. function Cli_PlcHotStart(Client : S7Object) : integer;
  423. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  424. function Cli_PlcColdStart(Client : S7Object) : integer;
  425. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  426. function Cli_PlcStop(Client : S7Object) : integer;
  427. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  428. function Cli_CopyRamToRom(Client : S7Object; Timeout : integer) : integer;
  429. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  430. function Cli_Compress(Client : S7Object; Timeout : integer) : integer;
  431. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  432. function Cli_GetPlcStatus(Client : S7Object; var Status : integer) : integer;
  433. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  434. // Security functions
  435. function Cli_GetProtection(Client : S7Object; pUsrData : PS7Protection) : integer;
  436. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  437. function Cli_SetSessionPassword(Client : S7Object; Password : PAnsiChar) : integer;
  438. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  439. function Cli_ClearSessionPassword(Client : S7Object) : integer;
  440. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  441. // Async functions
  442. function Cli_AsReadArea(Client : S7Object; Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  443. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  444. function Cli_AsWriteArea(Client : S7Object; Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  445. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  446. function Cli_AsDBRead(Client : S7Object; DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  447. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  448. function Cli_AsDBWrite(Client : S7Object; DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  449. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  450. function Cli_AsMBRead(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  451. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  452. function Cli_AsMBWrite(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  453. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  454. function Cli_AsEBRead(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  455. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  456. function Cli_AsEBWrite(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  457. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  458. function Cli_AsABRead(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  459. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  460. function Cli_AsABWrite(Client : S7Object; Start, Size : integer; pUsrData : pointer) : integer;
  461. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  462. function Cli_AsTMRead(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  463. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  464. function Cli_AsTMWrite(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  465. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  466. function Cli_AsCTRead(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  467. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  468. function Cli_AsCTWrite(Client : S7Object; Start, Amount : integer; pUsrData : pointer) : integer;
  469. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  470. function Cli_AsListBlocksOfType(Client : S7Object; BlockType : integer; pUsrData : PS7BlocksOfType; var ItemsCount : integer) : integer;
  471. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  472. function Cli_AsReadSZL(Client : S7Object; ID, Index : integer; pUsrData : PS7SZL; var Size : integer) : integer;
  473. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  474. function Cli_AsReadSZLList(Client : S7Object; pUsrData : PS7SZLList; var ItemsCount : integer) : integer;
  475. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  476. function Cli_AsUpload(Client : S7Object; BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  477. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  478. function Cli_AsFullUpload(Client : S7Object; BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  479. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  480. function Cli_AsDownload(Client : S7Object; BlockNum : integer; pUsrData : pointer; Size : integer) : integer;
  481. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  482. function Cli_AsCopyRamToRom(Client : S7Object; Timeout : integer) : integer;
  483. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  484. function Cli_AsCompress(Client : S7Object; Timeout : integer) : integer;
  485. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  486. function Cli_AsDBGet(Client : S7Object; DBNumber : integer; pUsrData : pointer; var Size : integer) : integer;
  487. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  488. function Cli_AsDBFill(Client : S7Object; DBNumber : integer; FillChar : integer) : integer;
  489. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  490. function Cli_CheckAsCompletion(Client : S7Object; var opResult : integer) : integer;
  491. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  492. function Cli_WaitAsCompletion(Client : S7Object; Timeout : longword) : integer;
  493. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  494. // Low level
  495. function Cli_IsoExchangeBuffer(Client : S7Object; pUsrData : pointer; var Size : integer) : integer;
  496. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  497. // Utility/Misc functions
  498. function Cli_GetExecTime(Client : S7Object; var Time : longword) : integer;
  499. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  500. function Cli_GetLastError(Client : S7Object; var LastError : integer) : integer;
  501. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  502. function Cli_GetPduLength(Client : S7Object; Var Requested, Negotiated : integer) : integer;
  503. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  504. function Cli_ErrorText(Error : integer; Text : PAnsiChar; TextLen : integer) : integer;
  505. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  506. function Cli_GetConnected(Client : S7Object; var IsConnected : integer) : integer;
  507. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  508. //******************************************************************************
  509. // SERVER
  510. //******************************************************************************
  511. Const
  512. mkEvent = 0;
  513. mkLog = 1;
  514. OperationRead = 0;
  515. OperationWrite = 1;
  516. // Server Area ID (use with Register/unregister - Lock/unlock Area)
  517. srvAreaPE = 0;
  518. srvAreaPA = 1;
  519. srvAreaMK = 2;
  520. srvAreaCT = 3;
  521. srvAreaTM = 4;
  522. srvAreaDB = 5;
  523. // Errors
  524. errSrvCannotStart = $00100000; // Server cannot start
  525. errSrvDBNullPointer = $00200000; // Passed null as PData
  526. errSrvAreaAlreadyExists = $00300000; // Area Re-registration
  527. errSrvUnknownArea = $00400000; // Unknown area
  528. errSrvInvalidParams = $00500000; // Invalid param(s) supplied
  529. errSrvTooManyDB = $00600000; // Cannot register DB
  530. errSrvInvalidParamNumber = $00700000; // Invalid param (srv_get/set_param)
  531. errSrvCannotChangeParam = $00800000; // Cannot change because running
  532. // TCP Server Event codes
  533. evcServerStarted = $00000001;
  534. evcServerStopped = $00000002;
  535. evcListenerCannotStart = $00000004;
  536. evcClientAdded = $00000008;
  537. evcClientRejected = $00000010;
  538. evcClientNoRoom = $00000020;
  539. evcClientException = $00000040;
  540. evcClientDisconnected = $00000080;
  541. evcClientTerminated = $00000100;
  542. evcClientsDropped = $00000200;
  543. evcReserved_00000400 = $00000400; // currently unused
  544. evcReserved_00000800 = $00000800; // currently unused
  545. evcReserved_00001000 = $00001000; // currently unused
  546. evcReserved_00002000 = $00002000; // currently unused
  547. evcReserved_00004000 = $00004000; // currently unused
  548. evcReserved_00008000 = $00008000; // currently unused
  549. // S7 Server Event Code
  550. evcPDUincoming = $00010000;
  551. evcDataRead = $00020000;
  552. evcDataWrite = $00040000;
  553. evcNegotiatePDU = $00080000;
  554. evcReadSZL = $00100000;
  555. evcClock = $00200000;
  556. evcUpload = $00400000;
  557. evcDownload = $00800000;
  558. evcDirectory = $01000000;
  559. evcSecurity = $02000000;
  560. evcControl = $04000000;
  561. evcReserved_08000000 = $08000000; // currently unused
  562. evcReserved_10000000 = $10000000; // currently unused
  563. evcReserved_20000000 = $20000000; // currently unused
  564. evcReserved_40000000 = $40000000; // currently unused
  565. evcReserved_80000000 = $80000000; // currently unused
  566. // Masks to enable/disable all
  567. evcAll = $FFFFFFFF;
  568. evcNone = $00000000;
  569. // Event SubCodes
  570. evsUnknown = $0000;
  571. evsStartUpload = $0001;
  572. evsStartDownload = $0001;
  573. evsGetBlockList = $0001;
  574. evsStartListBoT = $0002;
  575. evsListBoT = $0003;
  576. evsGetBlockInfo = $0004;
  577. evsGetClock = $0001;
  578. evsSetClock = $0002;
  579. evsSetPassword = $0001;
  580. evsClrPassword = $0002;
  581. // Event Params : functions group
  582. grProgrammer = $0041;
  583. grCyclicData = $0042;
  584. grBlocksInfo = $0043;
  585. grSZL = $0044;
  586. grPassword = $0045;
  587. grBSend = $0046;
  588. grClock = $0047;
  589. grSecurity = $0045;
  590. // Event Params : control codes
  591. CodeControlUnknown = $0000;
  592. CodeControlColdStart = $0001;
  593. CodeControlWarmStart = $0002;
  594. CodeControlStop = $0003;
  595. CodeControlCompress = $0004;
  596. CodeControlCpyRamRom = $0005;
  597. CodeControlInsDel = $0006;
  598. // Event Result
  599. evrNoError = $0000;
  600. evrFragmentRejected = $0001;
  601. evrMalformedPDU = $0002;
  602. evrSparseBytes = $0003;
  603. evrCannotHandlePDU = $0004;
  604. evrNotImplemented = $0005;
  605. evrErrException = $0006;
  606. evrErrAreaNotFound = $0007;
  607. evrErrOutOfRange = $0008;
  608. evrErrOverPDU = $0009;
  609. evrErrTransportSize = $000A;
  610. evrInvalidGroupUData = $000B;
  611. evrInvalidSZL = $000C;
  612. evrDataSizeMismatch = $000D;
  613. evrCannotUpload = $000E;
  614. evrCannotDownload = $000F;
  615. evrUploadInvalidID = $0010;
  616. evrResNotFound = $0011;
  617. type
  618. // Unix Timestamp, the best compact way to store date/time if we don't need
  619. // millisecond resolution.
  620. time_t = NativeInt;
  621. Type
  622. TSrvEvent = packed record
  623. EvtTime : time_t; // Timestamp
  624. EvtSender : integer; // Sender
  625. EvtCode : longword; // Event code
  626. EvtRetCode : word; // Event result
  627. EvtParam1 : word; // Param 1
  628. EvtParam2 : word; // Param 2
  629. EvtParam3 : word; // Param 3
  630. EvtParam4 : word; // Param 4
  631. end;
  632. PSrvEvent = ^TSrvEvent;
  633. TSrvCallBack = procedure(usrPtr : pointer; PEvent : PSrvEvent; Size : integer);
  634. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  635. TSrvRWAreaCallBack = function(usrPtr : pointer; Sender, Operation : integer; PTag : PS7Tag; pUsrData : pointer) : integer;
  636. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  637. Const
  638. // Server status
  639. SrvStopped = 0;
  640. SrvRunning = 1;
  641. SrvError = 2;
  642. function Srv_Create : S7Object;
  643. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  644. procedure Srv_Destroy(var Server : S7Object);
  645. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  646. function Srv_GetParam(Server : S7Object; ParamNumber : integer; pValue : pointer) : integer;
  647. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  648. function Srv_SetParam(Server : S7Object; ParamNumber : integer; pValue : pointer) : integer;
  649. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  650. function Srv_Start(Server : S7Object) : integer;
  651. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  652. function Srv_StartTo(Server : S7Object; Address : PAnsiChar) : integer;
  653. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  654. function Srv_Stop(Server : S7Object) : integer;
  655. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  656. function Srv_RegisterArea(Server : S7Object; AreaCode : integer; Index : word; pUsrData : pointer; Size : integer) : integer;
  657. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  658. function Srv_UnregisterArea(Server : S7Object; AreaCode : integer; Index : word) : integer;
  659. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  660. function Srv_LockArea(Server : S7Object; AreaCode : integer; Index : word) : integer;
  661. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  662. function Srv_UnlockArea(Server : S7Object; AreaCode : integer; Index : word) : integer;
  663. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  664. function Srv_GetStatus(Server : S7Object; Var ServerStatus, CpuStatus, ClientsCount : integer) : integer;
  665. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  666. function Srv_SetCpuStatus(Server : S7Object; CpuStatus : integer) : integer;
  667. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  668. function Srv_PickEvent(Server : S7Object; var Event : TSrvEvent; var EvtReady : integer) : integer;
  669. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  670. function Srv_ClearEvents(Server : S7Object) : integer;
  671. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  672. function Srv_GetMask(Server : S7Object; MaskKind : integer; Var Mask : longword) : integer;
  673. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  674. function Srv_SetMask(Server : S7Object; MaskKind : integer; Mask : longword) : integer;
  675. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  676. function Srv_SetEventsCallback(Server : S7Object; CallBack, usrPtr : pointer) : integer;
  677. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  678. function Srv_SetReadEventsCallback(Server : S7Object; CallBack, usrPtr : pointer) : integer;
  679. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  680. function Srv_SetRWAreaCallback(Server : S7Object; CallBack, usrPtr : pointer) : integer;
  681. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  682. function Srv_ErrorText(Error : integer; Text : PAnsiChar; TextLen : integer) : integer;
  683. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  684. function Srv_EventText(var Event : TSrvEvent; Text : PAnsiChar; TextLen : integer) : integer;
  685. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  686. //******************************************************************************
  687. // PARTNER
  688. //******************************************************************************
  689. Const
  690. // Partner status
  691. par_stopped = 0; // stopped
  692. par_connecting = 1; // running and active, connecting
  693. par_waiting = 2; // running and waiting for a connection
  694. par_linked = 3; // running and connected : linked
  695. par_sending = 4; // sending data
  696. par_receiving = 5; // receiving data
  697. par_binderror = 6; // error starting passive server
  698. // Errors
  699. errParAddressInUse = $00200000;
  700. errParNoRoom = $00300000;
  701. errServerNoRoom = $00400000;
  702. errParInvalidParams = $00500000;
  703. errParNotLinked = $00600000;
  704. errParBusy = $00700000;
  705. errParFrameTimeout = $00800000;
  706. errParInvalidPDU = $00900000;
  707. errParSendTimeout = $00A00000;
  708. errParRecvTimeout = $00B00000;
  709. errParSendRefused = $00C00000;
  710. errParNegotiatingPDU = $00D00000;
  711. errParSendingBlock = $00E00000;
  712. errParRecvingBlock = $00F00000;
  713. errBindError = $01000000;
  714. errParDestroying = $01100000;
  715. errParInvalidParamNumber = $01200000;
  716. errParCannotChangeParam = $01300000;
  717. errParBufferTooSmall = $01400000;
  718. Type
  719. TParBRecvEvent = procedure(usrPtr : pointer; opResult : integer; R_ID : longword; pdata : pointer; size : integer);
  720. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  721. TParBSendCompletion = procedure(usrPtr : pointer; opResult : integer);
  722. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  723. // Control
  724. function Par_Create(Active : longbool) : S7Object;
  725. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  726. procedure Par_Destroy(var Partner : S7Object);
  727. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  728. function Par_GetParam(Partner : S7Object; ParamNumber : integer; pValue : Pointer) : integer;
  729. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  730. function Par_SetParam(Partner : S7Object; ParamNumber : integer; pValue : Pointer) : integer;
  731. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  732. function Par_Start(Partner : S7Object) : integer;
  733. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  734. function Par_StartTo(Partner : S7Object;
  735. LocalAddress : PAnsiChar;
  736. RemoteAddress : PAnsiChar;
  737. LocalTSAP : word;
  738. RemoteTSAP : word) : integer;
  739. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  740. function Par_Stop(Partner : S7Object) : integer;
  741. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  742. // Data I/O functions : BSend
  743. function Par_BSend(Partner : S7Object; R_ID : longword; pUsrData : pointer; Size : integer) : integer;
  744. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  745. function Par_AsBSend(Partner : S7Object;R_ID : longword; pUsrData : pointer; Size : integer) : integer;
  746. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  747. function Par_CheckAsBSendCompletion(Partner : S7Object; var opResult : integer) : integer;
  748. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  749. function Par_WaitAsBSendCompletion(Partner : S7Object; Timeout : longword) : integer;
  750. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  751. function Par_SetSendCallback(Partner : S7Object; pCompletion, usrPtr : pointer) : integer;
  752. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  753. // Data I/O functions : BRecv
  754. function Par_BRecv(Partner : S7Object; var R_ID : longword; pData : pointer; var Size : integer; Timeout : longword) : integer;
  755. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  756. function Par_CheckAsBRecvCompletion(Partner : S7Object; var opResult : integer; var R_ID : longword; pData : pointer; var Size : integer) : integer;
  757. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  758. function Par_SetRecvCallback(Partner : S7Object; pCompletion, usrPtr : pointer) : integer;
  759. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  760. // Utility functions
  761. function Par_GetTimes(Partner : S7Object; var SendTime : longword; var RecvTime : longword) : integer;
  762. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  763. function Par_GetLastError(Partner : S7Object; var LastError : integer) : integer;
  764. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  765. function Par_GetStatus(Partner : S7Object; Var Status : integer) : integer;
  766. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  767. function Par_GetStats(Partner : S7Object; Var BytesSent, BytesRecv, SendErrors, RecvErrors : longword) : integer;
  768. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  769. function Par_ErrorText(Error : integer; Text : PAnsiChar; TextLen : integer) : integer;
  770. {$IFDEF MSWINDOWS}stdcall;{$ELSE}cdecl;{$ENDIF}
  771. //******************************************************************************
  772. // S7CLIENT CLASS
  773. //******************************************************************************
  774. Type
  775. { TS7Client }
  776. TS7Client = class
  777. private
  778. HC : S7Object;
  779. public
  780. constructor Create;
  781. destructor Destroy; override;
  782. // Control functions
  783. function ConnectTo(Address : AnsiString; Rack, Slot : integer) : integer;
  784. function SetConnectionParams(Address : AnsiString; LocalTSAP, RemoteTSAP : word) : integer;
  785. function SetConnectionType(ConnectionType : word) : integer;
  786. function Connect : integer;
  787. function Disconnect : integer;
  788. function GetParam(ParamNumber : integer; pValue : pointer) : integer;
  789. function SetParam(ParamNumber : integer; pValue : pointer) : integer;
  790. function SetAsCallback(pCompletion, usrPtr : pointer) : integer;
  791. // Data I/O Main functions
  792. function ReadArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  793. function WriteArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  794. function ReadMultiVars(Items : PS7DataItems; ItemsCount : integer) : integer;
  795. function WriteMultiVars(Items : PS7DataItems; ItemsCount : integer) : integer;
  796. // Data I/O Lean functions
  797. function DBRead(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  798. function DBWrite(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  799. function MBRead(Start, Size : integer; pUsrData : pointer) : integer;
  800. function MBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  801. function EBRead(Start, Size : integer; pUsrData : pointer) : integer;
  802. function EBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  803. function ABRead(Start, Size : integer; pUsrData : pointer) : integer;
  804. function ABWrite(Start, Size : integer; pUsrData : pointer) : integer;
  805. function TMRead(Start, Amount : integer; pUsrData : pointer) : integer;
  806. function TMWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  807. function CTRead(Start, Amount : integer; pUsrData : pointer) : integer;
  808. function CTWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  809. // Directory functions
  810. function ListBlocks(pUsrData : PS7BlocksList) : integer;
  811. function GetAgBlockInfo(BlockType, BlockNum : integer; pUsrData : PS7BlockInfo) : integer;
  812. function GetPgBlockInfo(pBlock : pointer; pUsrData : PS7BlockInfo; Size : integer) : integer;
  813. function ListBlocksOfType(BlockType : integer; pUsrData : PS7BlocksOfType; var ItemsCount : integer) : integer;
  814. // Blocks functions
  815. function Upload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  816. function FullUpload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  817. function Download(BlockNum : integer; pUsrData : pointer; Size : integer) : integer;
  818. function Delete(BlockType, BlockNum : integer) : integer;
  819. function DBGet(DBNumber : integer; pUsrData : pointer; var Size : integer) : integer;
  820. function DBFill(DBNumber : integer; FillChar : integer) : integer;
  821. // Date/Time functions
  822. function GetPlcDateTime(Var DateTime : TDateTime) : integer;
  823. function SetPlcDateTime(Var DateTime : TDateTime) : integer;
  824. function SetPlcSystemDateTime : integer;
  825. // System Info functions
  826. function GetOrderCode(pUsrData : PS7OrderCode) : integer;
  827. function GetCpuInfo(pUsrData : PS7CpuInfo) : integer;
  828. function GetCPInfo(pUsrData : PS7CpInfo) : integer;
  829. function ReadSZL(ID, Index : integer; pUsrData : PS7SZL; var Size : integer) : integer;
  830. function ReadSZLList(pUsrData : PS7SZLList; var ItemsCount : integer) : integer;
  831. // Control functions
  832. function PlcHotStart : integer;
  833. function PlcColdStart : integer;
  834. function PlcStop : integer;
  835. function CopyRamToRom(Timeout : integer) : integer;
  836. function Compress(Timeout : integer) : integer;
  837. function GetPlcStatus(var Status : integer) : integer;
  838. // Security functions
  839. function GetProtection(pUsrData : PS7Protection) : integer;
  840. function SetSessionPassword(Password : AnsiString) : integer;
  841. function ClearSessionPassword : integer;
  842. // Async functions
  843. function AsReadArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  844. function AsWriteArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  845. function AsDBRead(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  846. function AsDBWrite(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  847. function AsMBRead(Start, Size : integer; pUsrData : pointer) : integer;
  848. function AsMBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  849. function AsEBRead(Start, Size : integer; pUsrData : pointer) : integer;
  850. function AsEBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  851. function AsABRead(Start, Size : integer; pUsrData : pointer) : integer;
  852. function AsABWrite(Start, Size : integer; pUsrData : pointer) : integer;
  853. function AsTMRead(Start, Amount : integer; pUsrData : pointer) : integer;
  854. function AsTMWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  855. function AsCTRead(Start, Amount : integer; pUsrData : pointer) : integer;
  856. function AsCTWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  857. function AsListBlocksOfType(BlockType : integer; pUsrData : PS7BlocksOfType; var ItemsCount : integer) : integer;
  858. function AsReadSZL(ID, Index : integer; pUsrData : PS7SZL; var Size : integer) : integer;
  859. function AsReadSZLList(pUsrData : PS7SZLList; var ItemsCount : integer) : integer;
  860. function AsUpload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  861. function AsFullUpload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  862. function AsDownload(BlockNum : integer; pUsrData : pointer; Size : integer) : integer;
  863. function AsCopyRamToRom(Timeout : integer) : integer;
  864. function AsCompress(Timeout : integer) : integer;
  865. function AsDBGet(DBNumber : integer; pUsrData : pointer; var Size : integer) : integer;
  866. function AsDBFill(DBNumber : integer; FillChar : integer) : integer;
  867. function CheckAsCompletion(var opResult : integer) : boolean;
  868. function WaitAsCompletion(Timeout : longword) : integer;
  869. // Low level
  870. function IsoExchangeBuffer(pUsrData : pointer; var Size : integer) : integer;
  871. // Utility/Misc functions
  872. function Time : longword;
  873. function LastError : integer;
  874. function PduLength : integer;
  875. function PduRequested : integer;
  876. function PlcStatus : integer;
  877. function Connected : boolean;
  878. end;
  879. //******************************************************************************
  880. // SNAP7SERVER CLASS
  881. //******************************************************************************
  882. TS7Server = class
  883. private
  884. HS : S7Object;
  885. function GetEventsMask: longword;
  886. function GetLogMask: longword;
  887. procedure SetEventsMask(const Value: longword);
  888. procedure SetLogMask(const Value: longword);
  889. function GetStatus(Var ServerStatus, CpuStatus, ClientsCount : integer) : integer;
  890. function GetClientsCount: integer;
  891. function GetCpuStatus: integer;
  892. function GetServerStatus: integer;
  893. procedure SetCpuStatus(const Value: integer);
  894. public
  895. constructor Create;
  896. destructor Destroy; override;
  897. // Control
  898. function Start : integer;
  899. function StartTo(Address : String) : integer;
  900. function Stop : integer;
  901. function GetParam(ParamNumber : integer; pValue : pointer) : integer;
  902. function SetParam(ParamNumber : integer; pValue : pointer) : integer;
  903. // Resources
  904. function RegisterArea(AreaCode : integer; Index : integer; pUsrData : pointer; Size : integer) : integer;
  905. function UnregisterArea(AreaCode : integer; Index : integer) : integer;
  906. function LockArea(AreaCode : integer; Index : integer) : integer;
  907. function UnlockArea(AreaCode : integer; Index : integer) : integer;
  908. // Events
  909. function PickEvent(var Event : TSrvEvent) : boolean;
  910. function ClearEvents : integer;
  911. function SetEventsCallback(CallBack, usrPtr : pointer) : integer;
  912. function SetReadEventsCallback(CallBack, usrPtr : pointer) : integer;
  913. function SetRWAreaCallback(CallBack, usrPtr : pointer) : integer;
  914. // Properties
  915. property EventsMask : longword read GetEventsMask write SetEventsMask;
  916. property LogMask : longword read GetLogMask write SetLogMask;
  917. property ServerStatus : integer read GetServerStatus;
  918. property CpuStatus : integer read GetCpuStatus write SetCpuStatus;
  919. property ClientsCount : integer read GetClientsCount;
  920. end;
  921. //******************************************************************************
  922. // SNAP7PARTNER CLASS
  923. //******************************************************************************
  924. TS7Partner = class
  925. private
  926. HP : S7Object;
  927. FBytesSent : longword;
  928. FBytesRecv : longword;
  929. FSendErrors : longword;
  930. FRecvErrors : longword;
  931. FActive: boolean;
  932. procedure GetStatistics;
  933. function GetLastError : integer;
  934. function GetBytesRecv: integer;
  935. function GetBytesSent: integer;
  936. function GetRecvErrors: integer;
  937. function GetRecvTime: longword;
  938. function GetSendErrors: integer;
  939. function GetSendTime: longword;
  940. function GetStatus: integer;
  941. function GetLinked: boolean;
  942. public
  943. constructor Create(AsActive : boolean);
  944. destructor Destroy; override;
  945. function GetParam(ParamNumber : integer; pValue : Pointer) : integer;
  946. function SetParam(ParamNumber : integer; pValue : Pointer) : integer;
  947. function Start : integer;
  948. function StartTo(LocalAddress, RemoteAddress : AnsiString;
  949. LocalTSAP, RemoteTSAP : word ) : integer;
  950. function Stop : integer;
  951. // Block send
  952. function BSend(R_ID : longword; pUsrData : pointer; size : integer) : integer;
  953. function AsBSend(R_ID : longword; pUsrData : pointer; size : integer) : integer;
  954. function CheckAsBSendCompletion(var opResult : integer) : boolean;
  955. function WaitAsBSendCompletion(Timeout : longword) : integer;
  956. function SetSendCallback(pSendCompletion, usrPtr : pointer) : integer;
  957. // Block recv
  958. function BRecv(Timeout : longword; var R_ID : longword;
  959. pUsrData : pointer; var Size : integer) : integer;
  960. function CheckAsBRecvCompletion(var opResult : integer; var R_ID : longword;
  961. pUsrData : pointer; var Size : integer) : boolean;
  962. function SetRecvCallback(pRecvCompletion, usrPtr : pointer) : integer;
  963. // Read only properties
  964. property Active : boolean read FActive;
  965. property Status : integer read GetStatus;
  966. property Linked : boolean read GetLinked;
  967. property BytesSent : integer read GetBytesSent;
  968. property BytesRecv : integer read GetBytesRecv;
  969. property SendErrors : integer read GetSendErrors;
  970. property RecvErrors : integer read GetRecvErrors;
  971. property LastError : integer read GetLastError;
  972. property SendTime : longword read GetSendTime;
  973. property RecvTime : longword read GetRecvTime;
  974. end;
  975. //******************************************************************************
  976. // S7 CONVERSION CLASS
  977. //******************************************************************************
  978. TS7Type = (S7Int, S7DInt, S7Word, S7DWord, S7Real, S7DT_To_DateTime, DateTime_To_S7DT);
  979. TS7Helper = class
  980. private
  981. function GetInt(pval: pointer): smallint;
  982. procedure SetInt(pval: pointer; const Value: smallint);
  983. function GetWord(pval: pointer): word;
  984. procedure SetWord(pval: pointer; const Value: word);
  985. function GetDInt(pval: pointer): longint;
  986. procedure SetDInt(pval: pointer; const Value: longint);
  987. function GetDWord(pval: pointer): longword;
  988. procedure SetDWord(pval: pointer; const Value: longword);
  989. function GetDateTime(pval: pointer): TDateTime;
  990. procedure SetDateTime(pval: pointer; const Value: TDateTime);
  991. function GetReal(pval: pointer): single;
  992. procedure SetReal(pval: pointer; const Value: single);
  993. function GetBit(pval: pointer; BitIndex: integer): boolean;
  994. procedure SetBit(pval: pointer; BitIndex: integer; const Value: boolean);
  995. public
  996. procedure Reverse(pval : pointer; const S7Type : TS7Type);
  997. property ValBit[pval : pointer; BitIndex : integer] : boolean read GetBit write SetBit;
  998. property ValInt[pval : pointer] : smallint read GetInt write SetInt;
  999. property ValDInt[pval : pointer] : longint read GetDInt write SetDInt;
  1000. property ValWord[pval : pointer] : word read GetWord write SetWord;
  1001. property ValDWord[pval : pointer] : longword read GetDWord write SetDWord;
  1002. property ValReal[pval : pointer] : single read GetReal write SetReal;
  1003. property ValDateTime[pval : pointer] : TDateTime read GetDateTime write SetDateTime;
  1004. end;
  1005. // Error text
  1006. function CliErrorText(Error : integer) : string;
  1007. function SrvErrorText(Error : integer) : string;
  1008. function ParErrorText(Error : integer) : string;
  1009. function SrvEventText(var Event : TSrvEvent) : string;
  1010. Var
  1011. S7 : TS7Helper;
  1012. implementation
  1013. Uses
  1014. DateUtils,
  1015. SysUtils;
  1016. Const
  1017. TextLen = 1024;
  1018. //------------------------------------------------------------------------------
  1019. // C++ Datatime conversion helpers
  1020. //------------------------------------------------------------------------------
  1021. function DateTimeToCPP_tm(T : TDateTime) : TCPP_tm;
  1022. Var
  1023. YY,MM,DD,HH,NN,SS,DOW,MS : word;
  1024. begin
  1025. DecodeDateFully(T,YY,MM,DD,DOW);
  1026. DecodeTime(T,HH,NN,SS,MS);
  1027. with Result do
  1028. begin
  1029. tm_year :=YY-1900;
  1030. tm_mon :=MM-1;
  1031. tm_mday :=DD;
  1032. tm_hour :=HH;
  1033. tm_min :=NN;
  1034. tm_sec :=SS;
  1035. tm_wday :=DOW-1;
  1036. tm_isdst:=-1; // Info not available
  1037. end;
  1038. end;
  1039. //------------------------------------------------------------------------------
  1040. function CPP_tmToDateTime(var T : TCPP_tm) : TDateTime;
  1041. Var
  1042. Date, Time : TDateTime;
  1043. begin
  1044. with T do
  1045. begin
  1046. if TryEncodeDate(tm_year+1900,tm_mon+1,tm_mday,Date) then
  1047. begin
  1048. if TryEncodeTime(tm_hour,tm_min,tm_sec,0,Time) then
  1049. Result:=Date+Time
  1050. else
  1051. Result:=0;
  1052. end
  1053. else
  1054. Result:=0;
  1055. end;
  1056. end;
  1057. //******************************************************************************
  1058. // CLIENT FORWARDS
  1059. //******************************************************************************
  1060. function Cli_Create; external snaplib name 'Cli_Create';
  1061. procedure Cli_Destroy; external snaplib name 'Cli_Destroy';
  1062. function Cli_ConnectTo; external snaplib name 'Cli_ConnectTo';
  1063. function Cli_SetConnectionParams; external snaplib name 'Cli_SetConnectionParams';
  1064. function Cli_SetConnectionType; external snaplib name 'Cli_SetConnectionType';
  1065. function Cli_Disconnect; external snaplib name 'Cli_Disconnect';
  1066. function Cli_Connect; external snaplib name 'Cli_Connect';
  1067. function Cli_GetParam; external snaplib name 'Cli_GetParam';
  1068. function Cli_SetParam; external snaplib name 'Cli_SetParam';
  1069. function Cli_SetAsCallback; external snaplib name 'Cli_SetAsCallback';
  1070. function Cli_ReadArea; external snaplib name 'Cli_ReadArea';
  1071. function Cli_WriteArea; external snaplib name 'Cli_WriteArea';
  1072. function Cli_ReadMultiVars; external snaplib name 'Cli_ReadMultiVars';
  1073. function Cli_WriteMultiVars; external snaplib name 'Cli_WriteMultiVars';
  1074. function Cli_DBRead; external snaplib name 'Cli_DBRead';
  1075. function Cli_DBWrite; external snaplib name 'Cli_DBWrite';
  1076. function Cli_MBRead; external snaplib name 'Cli_MBRead';
  1077. function Cli_MBWrite; external snaplib name 'Cli_MBWrite';
  1078. function Cli_EBRead; external snaplib name 'Cli_EBRead';
  1079. function Cli_EBWrite; external snaplib name 'Cli_EBWrite';
  1080. function Cli_ABRead; external snaplib name 'Cli_ABRead';
  1081. function Cli_ABWrite; external snaplib name 'Cli_ABWrite';
  1082. function Cli_TMRead; external snaplib name 'Cli_TMRead';
  1083. function Cli_TMWrite; external snaplib name 'Cli_TMWrite';
  1084. function Cli_CTRead; external snaplib name 'Cli_CTRead';
  1085. function Cli_CTWrite; external snaplib name 'Cli_CTWrite';
  1086. function Cli_ListBlocks; external snaplib name 'Cli_ListBlocks';
  1087. function Cli_GetAgBlockInfo; external snaplib name 'Cli_GetAgBlockInfo';
  1088. function Cli_GetPgBlockInfo; external snaplib name 'Cli_GetPgBlockInfo';
  1089. function Cli_ListBlocksOfType; external snaplib name 'Cli_ListBlocksOfType';
  1090. function Cli_Upload; external snaplib name 'Cli_Upload';
  1091. function Cli_FullUpload; external snaplib name 'Cli_FullUpload';
  1092. function Cli_Download; external snaplib name 'Cli_Download';
  1093. function Cli_Delete; external snaplib name 'Cli_Delete';
  1094. function Cli_GetPlcDateTime; external snaplib name 'Cli_GetPlcDateTime';
  1095. function Cli_SetPlcDateTime; external snaplib name 'Cli_SetPlcDateTime';
  1096. function Cli_SetPlcSystemDateTime; external snaplib name 'Cli_SetPlcSystemDateTime';
  1097. function Cli_GetOrderCode; external snaplib name 'Cli_GetOrderCode';
  1098. function Cli_GetCpuInfo; external snaplib name 'Cli_GetCpuInfo';
  1099. function Cli_GetCPInfo; external snaplib name 'Cli_GetCpInfo';
  1100. function Cli_ReadSZL; external snaplib name 'Cli_ReadSZL';
  1101. function Cli_ReadSZLList; external snaplib name 'Cli_ReadSZLList';
  1102. function Cli_PlcHotStart; external snaplib name 'Cli_PlcHotStart';
  1103. function Cli_PlcColdStart; external snaplib name 'Cli_PlcColdStart';
  1104. function Cli_PlcStop; external snaplib name 'Cli_PlcStop';
  1105. function Cli_CopyRamToRom; external snaplib name 'Cli_CopyRamToRom';
  1106. function Cli_Compress; external snaplib name 'Cli_Compress';
  1107. function Cli_GetPlcStatus; external snaplib name 'Cli_GetPlcStatus';
  1108. function Cli_GetProtection; external snaplib name 'Cli_GetProtection';
  1109. function Cli_SetSessionPassword; external snaplib name 'Cli_SetSessionPassword';
  1110. function Cli_ClearSessionPassword; external snaplib name 'Cli_ClearSessionPassword';
  1111. function Cli_DBGet; external snaplib name 'Cli_DBGet';
  1112. function Cli_DBFill; external snaplib name 'Cli_DBFill';
  1113. function Cli_GetExecTime; external snaplib name 'Cli_GetExecTime';
  1114. function Cli_GetPduLength; external snaplib name 'Cli_GetPduLength';
  1115. function Cli_GetLastError; external snaplib name 'Cli_GetLastError';
  1116. function Cli_AsReadArea; external snaplib name 'Cli_AsReadArea';
  1117. function Cli_AsWriteArea; external snaplib name 'Cli_AsWriteArea';
  1118. function Cli_AsDBRead; external snaplib name 'Cli_AsDBRead';
  1119. function Cli_AsDBWrite; external snaplib name 'Cli_AsDBWrite';
  1120. function Cli_AsMBRead; external snaplib name 'Cli_AsMBRead';
  1121. function Cli_AsMBWrite; external snaplib name 'Cli_AsMBWrite';
  1122. function Cli_AsEBRead; external snaplib name 'Cli_AsEBRead';
  1123. function Cli_AsEBWrite; external snaplib name 'Cli_AsEBWrite';
  1124. function Cli_AsABRead; external snaplib name 'Cli_AsABRead';
  1125. function Cli_AsABWrite; external snaplib name 'Cli_AsABWrite';
  1126. function Cli_AsTMRead; external snaplib name 'Cli_AsTMRead';
  1127. function Cli_AsTMWrite; external snaplib name 'Cli_AsTMWrite';
  1128. function Cli_AsCTRead; external snaplib name 'Cli_AsCTRead';
  1129. function Cli_AsCTWrite; external snaplib name 'Cli_AsCTWrite';
  1130. function Cli_AsListBlocksOfType; external snaplib name 'Cli_AsListBlocksOfType';
  1131. function Cli_AsReadSZL; external snaplib name 'Cli_AsReadSZL';
  1132. function Cli_AsReadSZLList; external snaplib name 'Cli_AsReadSZLList';
  1133. function Cli_AsUpload; external snaplib name 'Cli_AsUpload';
  1134. function Cli_AsFullUpload; external snaplib name 'Cli_AsFullUpload';
  1135. function Cli_AsDownload; external snaplib name 'Cli_AsDownload';
  1136. function Cli_AsCopyRamToRom; external snaplib name 'Cli_AsCopyRamToRom';
  1137. function Cli_AsCompress; external snaplib name 'Cli_AsCompress';
  1138. function Cli_AsDBGet; external snaplib name 'Cli_AsDBGet';
  1139. function Cli_AsDBFill; external snaplib name 'Cli_AsDBFill';
  1140. function Cli_CheckAsCompletion; external snaplib name 'Cli_CheckAsCompletion';
  1141. function Cli_WaitAsCompletion; external snaplib name 'Cli_WaitAsCompletion';
  1142. function Cli_IsoExchangeBuffer; external snaplib name 'Cli_IsoExchangeBuffer';
  1143. function Cli_ErrorText; external snaplib name 'Cli_ErrorText';
  1144. function Cli_GetConnected; external snaplib name 'Cli_GetConnected';
  1145. //******************************************************************************
  1146. // SERVER FORWARDS
  1147. //******************************************************************************
  1148. function Srv_Create; external snaplib name 'Srv_Create';
  1149. procedure Srv_Destroy; external snaplib name 'Srv_Destroy';
  1150. function Srv_GetParam; external snaplib name 'Srv_GetParam';
  1151. function Srv_SetParam; external snaplib name 'Srv_SetParam';
  1152. function Srv_Start; external snaplib name 'Srv_Start';
  1153. function Srv_StartTo; external snaplib name 'Srv_StartTo';
  1154. function Srv_Stop; external snaplib name 'Srv_Stop';
  1155. function Srv_RegisterArea; external snaplib name 'Srv_RegisterArea';
  1156. function Srv_UnregisterArea; external snaplib name 'Srv_UnregisterArea';
  1157. function Srv_LockArea; external snaplib name 'Srv_LockArea';
  1158. function Srv_UnlockArea; external snaplib name 'Srv_UnlockArea';
  1159. function Srv_GetStatus; external snaplib name 'Srv_GetStatus';
  1160. function Srv_SetCpuStatus; external snaplib name 'Srv_SetCpuStatus';
  1161. function Srv_PickEvent; external snaplib name 'Srv_PickEvent';
  1162. function Srv_ClearEvents; external snaplib name 'Srv_ClearEvents';
  1163. function Srv_GetMask; external snaplib name 'Srv_GetMask';
  1164. function Srv_SetMask; external snaplib name 'Srv_SetMask';
  1165. function Srv_SetEventsCallback; external snaplib name 'Srv_SetEventsCallback';
  1166. function Srv_SetReadEventsCallback; external snaplib name 'Srv_SetReadEventsCallback';
  1167. function Srv_SetRWAreaCallback; external snaplib name 'Srv_SetRWAreaCallback';
  1168. function Srv_ErrorText; external snaplib name 'Srv_ErrorText';
  1169. function Srv_EventText; external snaplib name 'Srv_EventText';
  1170. //******************************************************************************
  1171. // PARTNER FORWARDS
  1172. //******************************************************************************
  1173. function Par_Create; external snaplib name 'Par_Create';
  1174. procedure Par_Destroy; external snaplib name 'Par_Destroy';
  1175. function Par_GetParam; external snaplib name 'Par_GetParam';
  1176. function Par_SetParam; external snaplib name 'Par_SetParam';
  1177. function Par_Start; external snaplib name 'Par_Start';
  1178. function Par_StartTo; external snaplib name 'Par_StartTo';
  1179. function Par_Stop; external snaplib name 'Par_Stop';
  1180. function Par_BSend; external snaplib name 'Par_BSend';
  1181. function Par_AsBSend; external snaplib name 'Par_AsBSend';
  1182. function Par_CheckAsBSendCompletion; external snaplib name 'Par_CheckAsBSendCompletion';
  1183. function Par_WaitAsBSendCompletion; external snaplib name 'Par_WaitAsBSendCompletion';
  1184. function Par_SetSendCallback; external snaplib name 'Par_SetSendCallback';
  1185. function Par_BRecv; external snaplib name 'Par_BRecv';
  1186. function Par_CheckAsBRecvCompletion; external snaplib name 'Par_CheckAsBRecvCompletion';
  1187. function Par_SetRecvCallback; external snaplib name 'Par_SetRecvCallback';
  1188. function Par_GetTimes; external snaplib name 'Par_GetTimes';
  1189. function Par_GetLastError; external snaplib name 'Par_GetLastError';
  1190. function Par_GetStatus; external snaplib name 'Par_GetStatus';
  1191. function Par_GetStats; external snaplib name 'Par_GetStats';
  1192. function Par_ErrorText; external snaplib name 'Par_ErrorText';
  1193. //******************************************************************************
  1194. // TS7Client CLASS IMPLEMENTATION
  1195. //******************************************************************************
  1196. constructor TS7Client.Create;
  1197. begin
  1198. inherited;
  1199. HC:=Cli_Create;
  1200. end;
  1201. //------------------------------------------------------------------------------
  1202. destructor TS7Client.Destroy;
  1203. begin
  1204. Cli_Destroy(HC);
  1205. inherited;
  1206. end;
  1207. //------------------------------------------------------------------------------
  1208. function TS7Client.ConnectTo(Address : AnsiString; Rack,Slot : integer) : integer;
  1209. begin
  1210. Result:=Cli_ConnectTo(HC,PAnsiChar(Address), Rack, Slot)
  1211. end;
  1212. //------------------------------------------------------------------------------
  1213. function TS7Client.SetConnectionParams(Address: AnsiString; LocalTSAP, RemoteTSAP: word ) : integer;
  1214. begin
  1215. Result:=Cli_SetConnectionParams(HC,PAnsiChar(Address), LocalTSAP, RemoteTSAP)
  1216. end;
  1217. //------------------------------------------------------------------------------
  1218. function TS7Client.SetConnectionType(ConnectionType : word ) : integer;
  1219. begin
  1220. Result:=Cli_SetConnectionType(HC, ConnectionType)
  1221. end;
  1222. //------------------------------------------------------------------------------
  1223. function TS7Client.Connect : integer;
  1224. begin
  1225. Result:=Cli_Connect(HC)
  1226. end;
  1227. //------------------------------------------------------------------------------
  1228. function TS7Client.Disconnect : integer;
  1229. begin
  1230. Result:=Cli_Disconnect(HC)
  1231. end;
  1232. //------------------------------------------------------------------------------
  1233. function TS7Client.SetAsCallback(pCompletion, usrPtr : pointer) : integer;
  1234. begin
  1235. Result:=Cli_SetAsCallback(HC,pCompletion,usrPtr)
  1236. end;
  1237. //------------------------------------------------------------------------------
  1238. function TS7Client.ReadArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  1239. begin
  1240. Result:=Cli_ReadArea(HC,Area,DBNumber,Start,Amount,WordLen,pUsrData)
  1241. end;
  1242. //------------------------------------------------------------------------------
  1243. function TS7Client.WaitAsCompletion(Timeout: longword): integer;
  1244. begin
  1245. Result:=Cli_WaitAsCompletion(HC,Timeout)
  1246. end;
  1247. //------------------------------------------------------------------------------
  1248. function TS7Client.WriteArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  1249. begin
  1250. Result:=Cli_WriteArea(HC,Area,DBNumber,Start,Amount,WordLen,pUsrData)
  1251. end;
  1252. //------------------------------------------------------------------------------
  1253. function TS7Client.ReadMultiVars(Items : PS7DataItems; ItemsCount : integer) : integer;
  1254. begin
  1255. Result:=Cli_ReadMultiVars(HC,Items,ItemsCount)
  1256. end;
  1257. //------------------------------------------------------------------------------
  1258. function TS7Client.WriteMultiVars(Items : PS7DataItems; ItemsCount : integer) : integer;
  1259. begin
  1260. Result:=Cli_WriteMultiVars(HC,Items,ItemsCount)
  1261. end;
  1262. //------------------------------------------------------------------------------
  1263. function TS7Client.DBRead(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  1264. begin
  1265. Result:=Cli_DBRead(HC,DBNumber,Start,Size,pUsrData)
  1266. end;
  1267. //------------------------------------------------------------------------------
  1268. function TS7Client.DBWrite(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  1269. begin
  1270. Result:=Cli_DBWrite(HC,DBNumber,Start,Size,pUsrData)
  1271. end;
  1272. //------------------------------------------------------------------------------
  1273. function TS7Client.MBRead(Start, Size : integer; pUsrData : pointer) : integer;
  1274. begin
  1275. Result:=Cli_MBRead(HC,Start,Size,pUsrData)
  1276. end;
  1277. //------------------------------------------------------------------------------
  1278. function TS7Client.MBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  1279. begin
  1280. Result:=Cli_MBWrite(HC,Start,Size,pUsrData)
  1281. end;
  1282. //------------------------------------------------------------------------------
  1283. function TS7Client.EBRead(Start, Size : integer; pUsrData : pointer) : integer;
  1284. begin
  1285. Result:=Cli_EBRead(HC,Start,Size,pUsrData)
  1286. end;
  1287. //------------------------------------------------------------------------------
  1288. function TS7Client.EBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  1289. begin
  1290. Result:=Cli_EBWrite(HC,Start,Size,pUsrData)
  1291. end;
  1292. //------------------------------------------------------------------------------
  1293. function TS7Client.ABRead(Start, Size : integer; pUsrData : pointer) : integer;
  1294. begin
  1295. Result:=Cli_ABRead(HC,Start,Size,pUsrData)
  1296. end;
  1297. //------------------------------------------------------------------------------
  1298. function TS7Client.ABWrite(Start, Size : integer; pUsrData : pointer) : integer;
  1299. begin
  1300. Result:=Cli_ABWrite(HC,Start,Size,pUsrData)
  1301. end;
  1302. //------------------------------------------------------------------------------
  1303. function TS7Client.TMRead(Start, Amount : integer; pUsrData : pointer) : integer;
  1304. begin
  1305. Result:=Cli_TMRead(HC,Start,Amount,pUsrData)
  1306. end;
  1307. //------------------------------------------------------------------------------
  1308. function TS7Client.TMWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  1309. begin
  1310. Result:=Cli_TMWrite(HC,Start,Amount,pUsrData)
  1311. end;
  1312. //------------------------------------------------------------------------------
  1313. function TS7Client.CTRead(Start, Amount : integer; pUsrData : pointer) : integer;
  1314. begin
  1315. Result:=Cli_CTRead(HC,Start,Amount,pUsrData)
  1316. end;
  1317. //------------------------------------------------------------------------------
  1318. function TS7Client.CTWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  1319. begin
  1320. Result:=Cli_CTWrite(HC,Start,Amount,pUsrData)
  1321. end;
  1322. //------------------------------------------------------------------------------
  1323. function TS7Client.ListBlocks(pUsrData : PS7BlocksList) : integer;
  1324. begin
  1325. Result:=Cli_ListBlocks(HC,pUsrData)
  1326. end;
  1327. //------------------------------------------------------------------------------
  1328. function TS7Client.GetAgBlockInfo(BlockType, BlockNum : integer; pUsrData : PS7BlockInfo) : integer;
  1329. begin
  1330. Result:=Cli_GetAgBlockInfo(HC,BlockType,BlockNum,pUsrData)
  1331. end;
  1332. //------------------------------------------------------------------------------
  1333. function TS7Client.GetPgBlockInfo(pBlock : pointer; pUsrData : PS7BlockInfo; Size : integer) : integer;
  1334. begin
  1335. Result:=Cli_GetPgBlockInfo(HC,pBlock,pUsrData,Size)
  1336. end;
  1337. //------------------------------------------------------------------------------
  1338. function TS7Client.ListBlocksOfType(BlockType : integer; pUsrData : PS7BlocksOfType; var ItemsCount : integer) : integer;
  1339. begin
  1340. Result:=Cli_ListBlocksOfType(HC,BlockType,pUsrData,ItemsCount)
  1341. end;
  1342. //------------------------------------------------------------------------------
  1343. function TS7Client.Upload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  1344. begin
  1345. Result:=Cli_Upload(HC,BlockType,BlockNum,pUsrData,Size)
  1346. end;
  1347. //------------------------------------------------------------------------------
  1348. function TS7Client.FullUpload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  1349. begin
  1350. Result:=Cli_FullUpload(HC,BlockType,BlockNum,pUsrData,Size)
  1351. end;
  1352. //------------------------------------------------------------------------------
  1353. function TS7Client.Download(BlockNum : integer; pUsrData : pointer; Size : integer) : integer;
  1354. begin
  1355. Result:=Cli_Download(HC,BlockNum,pUsrData,Size)
  1356. end;
  1357. //------------------------------------------------------------------------------
  1358. function TS7Client.Delete(BlockType, BlockNum : integer) : integer;
  1359. begin
  1360. Result:=Cli_Delete(HC,BlockType,BlockNum)
  1361. end;
  1362. //------------------------------------------------------------------------------
  1363. function TS7Client.DBGet(DBNumber : integer; pUsrData : pointer; var Size : integer) : integer;
  1364. begin
  1365. Result:=Cli_DBGet(HC,DBNumber,pUsrData,Size)
  1366. end;
  1367. //------------------------------------------------------------------------------
  1368. function TS7Client.DBFill(DBNumber : integer; FillChar : integer) : integer;
  1369. begin
  1370. Result:=Cli_DBFill(HC,DBNumber,FillChar)
  1371. end;
  1372. //------------------------------------------------------------------------------
  1373. function TS7Client.GetPlcDateTime(Var DateTime : TDateTime) : integer;
  1374. Var
  1375. CPP_tm : TCPP_tm;
  1376. begin
  1377. Result:=Cli_GetPlcDateTime(HC,CPP_tm);
  1378. if Result=0 then
  1379. DateTime:=CPP_tmToDateTime(CPP_tm);
  1380. end;
  1381. //------------------------------------------------------------------------------
  1382. function TS7Client.GetParam(ParamNumber : integer; pValue: pointer): integer;
  1383. begin
  1384. Result:=Cli_GetParam(HC, ParamNumber, pValue);
  1385. end;
  1386. //------------------------------------------------------------------------------
  1387. function TS7Client.SetParam(ParamNumber : integer; pValue: pointer): integer;
  1388. begin
  1389. Result:=Cli_SetParam(HC, ParamNumber, pValue);
  1390. end;
  1391. //------------------------------------------------------------------------------
  1392. function TS7Client.SetPlcDateTime(Var DateTime : TDateTime) : integer;
  1393. Var
  1394. CPP_tm : TCPP_tm;
  1395. begin
  1396. CPP_tm:=DateTimeToCPP_tm(DateTime);
  1397. Result:=Cli_SetPlcDateTime(HC,CPP_tm);
  1398. end;
  1399. //------------------------------------------------------------------------------
  1400. function TS7Client.SetPlcSystemDateTime : integer;
  1401. begin
  1402. Result:=Cli_SetPlcSystemDateTime(HC)
  1403. end;
  1404. //------------------------------------------------------------------------------
  1405. function TS7Client.GetOrderCode(pUsrData : PS7OrderCode) : integer;
  1406. begin
  1407. Result:=Cli_GetOrderCode(HC,pUsrData)
  1408. end;
  1409. //------------------------------------------------------------------------------
  1410. function TS7Client.GetCpuInfo(pUsrData : PS7CpuInfo) : integer;
  1411. begin
  1412. Result:=Cli_GetCpuInfo(HC,pUsrData)
  1413. end;
  1414. //------------------------------------------------------------------------------
  1415. function TS7Client.GetCPInfo(pUsrData : PS7CpInfo) : integer;
  1416. begin
  1417. Result:=Cli_GetCPInfo(HC,pUsrData)
  1418. end;
  1419. //------------------------------------------------------------------------------
  1420. function TS7Client.ReadSZL(ID, Index : integer; pUsrData : PS7SZL; var Size : integer) : integer;
  1421. begin
  1422. Result:=Cli_ReadSZL(HC,ID,Index,pUsrData,Size)
  1423. end;
  1424. //------------------------------------------------------------------------------
  1425. function TS7Client.ReadSZLList(pUsrData : PS7SZLList; var ItemsCount : integer) : integer;
  1426. begin
  1427. Result:=Cli_ReadSZLList(HC,pUsrData,ItemsCount)
  1428. end;
  1429. //------------------------------------------------------------------------------
  1430. function TS7Client.PlcHotStart : integer;
  1431. begin
  1432. Result:=Cli_PlcHotStart(HC)
  1433. end;
  1434. //------------------------------------------------------------------------------
  1435. function TS7Client.PlcColdStart : integer;
  1436. begin
  1437. Result:=Cli_PlcColdStart(HC)
  1438. end;
  1439. //------------------------------------------------------------------------------
  1440. function TS7Client.PlcStatus: integer;
  1441. Var
  1442. Return : integer;
  1443. begin
  1444. Return:=Cli_GetPlcStatus(HC, Result);
  1445. if (Return<>0) then
  1446. Result:=Return;
  1447. end;
  1448. //------------------------------------------------------------------------------
  1449. function TS7Client.Connected: boolean;
  1450. Var
  1451. IsConnected : integer;
  1452. begin
  1453. if Cli_GetConnected(HC, IsConnected)=0 then
  1454. Result:=IsConnected<>0
  1455. else
  1456. Result:=false;
  1457. end;
  1458. //------------------------------------------------------------------------------
  1459. function TS7Client.PlcStop : integer;
  1460. begin
  1461. Result:=Cli_PlcStop(HC)
  1462. end;
  1463. //------------------------------------------------------------------------------
  1464. function TS7Client.CopyRamToRom(Timeout : integer) : integer;
  1465. begin
  1466. Result:=Cli_CopyRamToRom(HC,Timeout)
  1467. end;
  1468. //------------------------------------------------------------------------------
  1469. function TS7Client.Compress(Timeout : integer) : integer;
  1470. begin
  1471. Result:=Cli_Compress(HC,Timeout)
  1472. end;
  1473. //------------------------------------------------------------------------------
  1474. function TS7Client.GetPlcStatus(var Status : integer) : integer;
  1475. begin
  1476. Result:=Cli_GetPlcStatus(HC,Status)
  1477. end;
  1478. //------------------------------------------------------------------------------
  1479. function TS7Client.GetProtection(pUsrData : PS7Protection) : integer;
  1480. begin
  1481. Result:=Cli_GetProtection(HC,pUsrData)
  1482. end;
  1483. //------------------------------------------------------------------------------
  1484. function TS7Client.SetSessionPassword(Password : AnsiString) : integer;
  1485. begin
  1486. Result:=Cli_SetSessionPassword(HC,PAnsiChar(Password))
  1487. end;
  1488. //------------------------------------------------------------------------------
  1489. function TS7Client.ClearSessionPassword : integer;
  1490. begin
  1491. Result:=Cli_ClearSessionPassword(HC)
  1492. end;
  1493. //------------------------------------------------------------------------------
  1494. function TS7Client.AsReadArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  1495. begin
  1496. Result:=Cli_AsReadArea(HC,Area,DBNumber,Start,Amount,WordLen,pUsrData)
  1497. end;
  1498. //------------------------------------------------------------------------------
  1499. function TS7Client.AsWriteArea(Area, DBNumber, Start, Amount, WordLen : integer; pUsrData : pointer) : integer;
  1500. begin
  1501. Result:=Cli_AsWriteArea(HC,Area,DBNumber,Start,Amount,WordLen,pUsrData)
  1502. end;
  1503. //------------------------------------------------------------------------------
  1504. function TS7Client.AsDBRead(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  1505. begin
  1506. Result:=Cli_AsDBRead(HC,DBNumber,Start,Size,pUsrData)
  1507. end;
  1508. //------------------------------------------------------------------------------
  1509. function TS7Client.AsDBWrite(DBNumber, Start, Size : integer; pUsrData : pointer) : integer;
  1510. begin
  1511. Result:=Cli_AsDBWrite(HC,DBNumber,Start,Size,pUsrData)
  1512. end;
  1513. //------------------------------------------------------------------------------
  1514. function TS7Client.AsMBRead(Start, Size : integer; pUsrData : pointer) : integer;
  1515. begin
  1516. Result:=Cli_AsMBRead(HC,Start,Size,pUsrData)
  1517. end;
  1518. //------------------------------------------------------------------------------
  1519. function TS7Client.AsMBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  1520. begin
  1521. Result:=Cli_AsMBWrite(HC,Start,Size,pUsrData)
  1522. end;
  1523. //------------------------------------------------------------------------------
  1524. function TS7Client.AsEBRead(Start, Size : integer; pUsrData : pointer) : integer;
  1525. begin
  1526. Result:=Cli_AsEBRead(HC,Start,Size,pUsrData)
  1527. end;
  1528. //------------------------------------------------------------------------------
  1529. function TS7Client.AsEBWrite(Start, Size : integer; pUsrData : pointer) : integer;
  1530. begin
  1531. Result:=Cli_AsEBWrite(HC,Start,Size,pUsrData)
  1532. end;
  1533. //------------------------------------------------------------------------------
  1534. function TS7Client.AsABRead(Start, Size : integer; pUsrData : pointer) : integer;
  1535. begin
  1536. Result:=Cli_AsABRead(HC,Start,Size,pUsrData)
  1537. end;
  1538. //------------------------------------------------------------------------------
  1539. function TS7Client.AsABWrite(Start, Size : integer; pUsrData : pointer) : integer;
  1540. begin
  1541. Result:=Cli_AsABWrite(HC,Start,Size,pUsrData)
  1542. end;
  1543. //------------------------------------------------------------------------------
  1544. function TS7Client.AsTMRead(Start, Amount : integer; pUsrData : pointer) : integer;
  1545. begin
  1546. Result:=Cli_AsTMRead(HC,Start,Amount,pUsrData)
  1547. end;
  1548. //------------------------------------------------------------------------------
  1549. function TS7Client.AsTMWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  1550. begin
  1551. Result:=Cli_AsTMWrite(HC,Start,Amount,pUsrData)
  1552. end;
  1553. //------------------------------------------------------------------------------
  1554. function TS7Client.AsCTRead(Start, Amount : integer; pUsrData : pointer) : integer;
  1555. begin
  1556. Result:=Cli_AsCTRead(HC,Start,Amount,pUsrData)
  1557. end;
  1558. //------------------------------------------------------------------------------
  1559. function TS7Client.AsCTWrite(Start, Amount : integer; pUsrData : pointer) : integer;
  1560. begin
  1561. Result:=Cli_AsCTWrite(HC,Start,Amount,pUsrData)
  1562. end;
  1563. //------------------------------------------------------------------------------
  1564. function TS7Client.AsListBlocksOfType(BlockType : integer; pUsrData : PS7BlocksOfType; var ItemsCount : integer) : integer;
  1565. begin
  1566. Result:=Cli_AsListBlocksOfType(HC,BlockType,pUsrData,ItemsCount)
  1567. end;
  1568. //------------------------------------------------------------------------------
  1569. function TS7Client.AsReadSZL(ID, Index : integer; pUsrData : PS7SZL; var Size : integer) : integer;
  1570. begin
  1571. Result:=Cli_AsReadSZL(HC,ID,Index,pUsrData,Size)
  1572. end;
  1573. //------------------------------------------------------------------------------
  1574. function TS7Client.AsReadSZLList(pUsrData: PS7SZLList;
  1575. var ItemsCount: integer): integer;
  1576. begin
  1577. Result:=Cli_AsReadSZLList(HC,pUsrData,ItemsCount)
  1578. end;
  1579. //------------------------------------------------------------------------------
  1580. function TS7Client.AsUpload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  1581. begin
  1582. Result:=Cli_AsUpload(HC,BlockType,BlockNum,pUsrData,Size)
  1583. end;
  1584. //------------------------------------------------------------------------------
  1585. function TS7Client.AsFullUpload(BlockType, BlockNum : integer; pUsrData : pointer; var Size : integer) : integer;
  1586. begin
  1587. Result:=Cli_AsFullUpload(HC,BlockType,BlockNum,pUsrData,Size)
  1588. end;
  1589. //------------------------------------------------------------------------------
  1590. function TS7Client.AsDownload(BlockNum : integer; pUsrData : pointer; Size : integer) : integer;
  1591. begin
  1592. Result:=Cli_AsDownload(HC,BlockNum,pUsrData,Size)
  1593. end;
  1594. //------------------------------------------------------------------------------
  1595. function TS7Client.AsCopyRamToRom(Timeout : integer) : integer;
  1596. begin
  1597. Result:=Cli_AsCopyRamToRom(HC,Timeout)
  1598. end;
  1599. //------------------------------------------------------------------------------
  1600. function TS7Client.AsCompress(Timeout : integer) : integer;
  1601. begin
  1602. Result:=Cli_AsCompress(HC,Timeout)
  1603. end;
  1604. //------------------------------------------------------------------------------
  1605. function TS7Client.AsDBGet(DBNumber : integer; pUsrData : pointer; var Size : integer) : integer;
  1606. begin
  1607. Result:=Cli_AsDBGet(HC,DBNumber,pUsrData,Size)
  1608. end;
  1609. //------------------------------------------------------------------------------
  1610. function TS7Client.AsDBFill(DBNumber : integer; FillChar : integer) : integer;
  1611. begin
  1612. Result:=Cli_AsDBFill(HC,DBNumber,FillChar)
  1613. end;
  1614. //------------------------------------------------------------------------------
  1615. function TS7Client.CheckAsCompletion(var opResult : integer) : boolean;
  1616. begin
  1617. Result:=Cli_CheckAsCompletion(HC,opResult)=JobComplete;
  1618. end;
  1619. //------------------------------------------------------------------------------
  1620. function TS7Client.IsoExchangeBuffer(pUsrData : pointer; var Size : integer) : integer;
  1621. begin
  1622. Result:=Cli_IsoExchangeBuffer(HC,pUsrData,Size)
  1623. end;
  1624. //------------------------------------------------------------------------------
  1625. function TS7Client.Time : longword;
  1626. Var
  1627. Return : integer;
  1628. begin
  1629. Return:=Cli_GetExecTime(HC,Result);
  1630. if Return<>0 then
  1631. Result:=longword(-1);
  1632. end;
  1633. //------------------------------------------------------------------------------
  1634. function TS7Client.LastError : integer;
  1635. begin
  1636. Cli_GetLastError(HC,Result);
  1637. end;
  1638. //------------------------------------------------------------------------------
  1639. function TS7Client.PduLength : integer;
  1640. Var
  1641. Requested : integer;
  1642. begin
  1643. Cli_GetPduLength(HC, Requested, Result);
  1644. end;
  1645. //------------------------------------------------------------------------------
  1646. function TS7Client.PduRequested: integer;
  1647. Var
  1648. PduLength : integer;
  1649. begin
  1650. Cli_GetPduLength(HC, Result, PduLength);
  1651. end;
  1652. //******************************************************************************
  1653. // TS7Server CLASS IMPLEMENTATION
  1654. //******************************************************************************
  1655. constructor TS7Server.Create;
  1656. begin
  1657. inherited Create;
  1658. HS:=Srv_Create;
  1659. end;
  1660. //------------------------------------------------------------------------------
  1661. destructor TS7Server.Destroy;
  1662. begin
  1663. if HS<>0 then
  1664. Srv_Destroy(HS);
  1665. inherited;
  1666. end;
  1667. //------------------------------------------------------------------------------
  1668. function TS7Server.ClearEvents: integer;
  1669. begin
  1670. Result:=Srv_ClearEvents(HS)
  1671. end;
  1672. //------------------------------------------------------------------------------
  1673. function TS7Server.PickEvent(var Event: TSrvEvent) : boolean;
  1674. Var
  1675. EvtReady : integer;
  1676. begin
  1677. if Srv_PickEvent(HS, Event, EvtReady)=0 then
  1678. Result := EvtReady<>0
  1679. else
  1680. Result:=False;
  1681. end;
  1682. //------------------------------------------------------------------------------
  1683. function TS7Server.GetClientsCount: integer;
  1684. Var
  1685. ServerStatus, CpuStatus : integer;
  1686. begin
  1687. if GetStatus(ServerStatus, CpuStatus, Result)<>0 then
  1688. Result:=0;
  1689. end;
  1690. //------------------------------------------------------------------------------
  1691. function TS7Server.GetCpuStatus: integer;
  1692. Var
  1693. ServerStatus, ClientsCount : integer;
  1694. begin
  1695. if GetStatus(ServerStatus, Result, ClientsCount)<>0 then
  1696. Result:=0;
  1697. end;
  1698. //------------------------------------------------------------------------------
  1699. function TS7Server.GetEventsMask: longword;
  1700. begin
  1701. if Srv_GetMask(HS, mkEvent, Result)<>0 then
  1702. Result:=0;
  1703. end;
  1704. //------------------------------------------------------------------------------
  1705. function TS7Server.GetLogMask: longword;
  1706. begin
  1707. if Srv_GetMask(HS, mkLog, Result)<>0 then
  1708. Result:=0;
  1709. end;
  1710. //------------------------------------------------------------------------------
  1711. function TS7Server.GetServerStatus: integer;
  1712. Var
  1713. CpuStatus, ClientsCount : integer;
  1714. begin
  1715. if GetStatus(Result, CpuStatus, ClientsCount)<>0 then
  1716. Result:=0;
  1717. end;
  1718. //------------------------------------------------------------------------------
  1719. function TS7Server.GetStatus(var ServerStatus, CpuStatus,
  1720. ClientsCount: integer): integer;
  1721. begin
  1722. Result:=Srv_GetStatus(HS, ServerStatus, CpuStatus, ClientsCount);
  1723. end;
  1724. //------------------------------------------------------------------------------
  1725. function TS7Server.LockArea(AreaCode, Index: integer): integer;
  1726. begin
  1727. Result:=Srv_LockArea(HS, AreaCode, Index);
  1728. end;
  1729. //------------------------------------------------------------------------------
  1730. function TS7Server.RegisterArea(AreaCode, Index: integer; pUsrData: pointer;
  1731. Size: integer): integer;
  1732. begin
  1733. Result:=Srv_RegisterArea(HS,AreaCode,Index,pUsrData,Size);
  1734. end;
  1735. //------------------------------------------------------------------------------
  1736. procedure TS7Server.SetCpuStatus(const Value: integer);
  1737. begin
  1738. Srv_SetCpuStatus(HS, Value);
  1739. end;
  1740. //------------------------------------------------------------------------------
  1741. function TS7Server.SetEventsCallback(CallBack, usrPtr: pointer): integer;
  1742. begin
  1743. Result:=Srv_SetEventsCallback(HS,CallBack,usrPtr);
  1744. end;
  1745. //------------------------------------------------------------------------------
  1746. function TS7Server.SetReadEventsCallback(CallBack, usrPtr: pointer): integer;
  1747. begin
  1748. Result:=Srv_SetReadEventsCallback(HS,CallBack,usrPtr);
  1749. end;
  1750. //------------------------------------------------------------------------------
  1751. function TS7Server.SetRWAreaCallback(CallBack, usrPtr : pointer) : integer;
  1752. begin
  1753. Result:=Srv_SetRWAreaCallback(HS,CallBack,usrPtr);
  1754. end;
  1755. //------------------------------------------------------------------------------
  1756. procedure TS7Server.SetEventsMask(const Value: longword);
  1757. begin
  1758. Srv_SetMask(HS, mkEvent, Value);
  1759. end;
  1760. //------------------------------------------------------------------------------
  1761. procedure TS7Server.SetLogMask(const Value: longword);
  1762. begin
  1763. Srv_SetMask(HS, mkLog, Value);
  1764. end;
  1765. //------------------------------------------------------------------------------
  1766. function TS7Server.GetParam(ParamNumber : integer; pValue: pointer): integer;
  1767. begin
  1768. Result:=Srv_GetParam(HS, ParamNumber ,pValue)
  1769. end;
  1770. //------------------------------------------------------------------------------
  1771. function TS7Server.SetParam(ParamNumber : integer; pValue: pointer): integer;
  1772. begin
  1773. Result:=Srv_SetParam(HS, ParamNumber ,pValue)
  1774. end;
  1775. //------------------------------------------------------------------------------
  1776. function TS7Server.Start: integer;
  1777. begin
  1778. Result:=Srv_Start(HS)
  1779. end;
  1780. //------------------------------------------------------------------------------
  1781. function TS7Server.StartTo(Address: String): integer;
  1782. begin
  1783. Result:=Srv_StartTo(HS, PAnsiChar(AnsiString(Address)));
  1784. end;
  1785. //------------------------------------------------------------------------------
  1786. function TS7Server.Stop: integer;
  1787. begin
  1788. Result:=Srv_Stop(HS)
  1789. end;
  1790. //------------------------------------------------------------------------------
  1791. function TS7Server.UnlockArea(AreaCode, Index: integer): integer;
  1792. begin
  1793. Result:=Srv_UnlockArea(HS,AreaCode,Index)
  1794. end;
  1795. //------------------------------------------------------------------------------
  1796. function TS7Server.UnregisterArea(AreaCode, Index: integer): integer;
  1797. begin
  1798. Result:=Srv_UnregisterArea(HS,AreaCode, Index)
  1799. end;
  1800. //******************************************************************************
  1801. // TS7Partner CLASS IMPLEMENTATION
  1802. //******************************************************************************
  1803. function TS7Partner.AsBSend(R_ID: longword; pUsrData: pointer;
  1804. size: integer): integer;
  1805. begin
  1806. Result:=Par_AsBSend(HP, R_ID, pUsrData, Size);
  1807. end;
  1808. //------------------------------------------------------------------------------
  1809. function TS7Partner.BRecv(Timeout: longword; var R_ID: longword;
  1810. pUsrData: pointer; var Size: integer): integer;
  1811. begin
  1812. Result:=Par_BRecv(HP, R_ID, pUsrData, Size, Timeout);
  1813. end;
  1814. //------------------------------------------------------------------------------
  1815. function TS7Partner.BSend(R_ID: longword; pUsrData: pointer;
  1816. size: integer): integer;
  1817. begin
  1818. Result:=Par_BSend(HP, R_ID, pUsrData, Size);
  1819. end;
  1820. //------------------------------------------------------------------------------
  1821. function TS7Partner.CheckAsBRecvCompletion(var opResult: integer;
  1822. var R_ID: longword; pUsrData: pointer; var Size: integer): boolean;
  1823. begin
  1824. Result:=Par_CheckAsBRecvCompletion(HP, opResult, R_ID, pUsrData, Size)=JobComplete;
  1825. end;
  1826. //------------------------------------------------------------------------------
  1827. function TS7Partner.CheckAsBSendCompletion(var opResult: integer): boolean;
  1828. begin
  1829. Result:=Par_CheckAsBSendCompletion(HP, opResult)=JobComplete;
  1830. end;
  1831. //------------------------------------------------------------------------------
  1832. constructor TS7Partner.Create(AsActive: boolean);
  1833. begin
  1834. HP := Par_Create(AsActive);
  1835. end;
  1836. //------------------------------------------------------------------------------
  1837. destructor TS7Partner.Destroy;
  1838. begin
  1839. Par_Destroy(HP);
  1840. inherited;
  1841. end;
  1842. //------------------------------------------------------------------------------
  1843. function TS7Partner.GetBytesRecv: integer;
  1844. begin
  1845. GetStatistics;
  1846. Result:=FBytesRecv;
  1847. end;
  1848. //------------------------------------------------------------------------------
  1849. function TS7Partner.GetBytesSent: integer;
  1850. begin
  1851. GetStatistics;
  1852. Result:=FBytesSent;
  1853. end;
  1854. //------------------------------------------------------------------------------
  1855. function TS7Partner.GetLastError: integer;
  1856. begin
  1857. if Par_GetLastError(HP, Result)<>0 then
  1858. Result:=errLibInvalidObject;
  1859. end;
  1860. //------------------------------------------------------------------------------
  1861. function TS7Partner.GetLinked: boolean;
  1862. begin
  1863. Result:=Status=par_linked;
  1864. end;
  1865. //------------------------------------------------------------------------------
  1866. function TS7Partner.GetRecvErrors: integer;
  1867. begin
  1868. GetStatistics;
  1869. Result:=FRecvErrors;
  1870. end;
  1871. //------------------------------------------------------------------------------
  1872. function TS7Partner.GetRecvTime: longword;
  1873. Var
  1874. FSendTime : longword;
  1875. begin
  1876. if Par_GetTimes(HP, FSendTime, Result)<>0 then
  1877. Result:=0;
  1878. end;
  1879. //------------------------------------------------------------------------------
  1880. function TS7Partner.GetSendErrors: integer;
  1881. begin
  1882. GetStatistics;
  1883. Result:=FSendErrors;
  1884. end;
  1885. //------------------------------------------------------------------------------
  1886. function TS7Partner.GetSendTime: longword;
  1887. Var
  1888. FRecvTime : longword;
  1889. begin
  1890. if Par_GetTimes(HP, Result, FRecvTime)<>0 then
  1891. Result:=0;
  1892. end;
  1893. //------------------------------------------------------------------------------
  1894. procedure TS7Partner.GetStatistics;
  1895. begin
  1896. if Par_GetStats(HP, FBytesSent, FBytesRecv, FSendErrors, FRecvErrors)<>0 then
  1897. begin
  1898. FBytesSent :=0;
  1899. FBytesRecv :=0;
  1900. FSendErrors:=0;
  1901. FRecvErrors:=0;
  1902. end;
  1903. end;
  1904. //------------------------------------------------------------------------------
  1905. function TS7Partner.GetStatus: integer;
  1906. begin
  1907. if Par_GetStatus(HP, Result)<>0 then
  1908. Result:=errLibInvalidObject;
  1909. end;
  1910. //------------------------------------------------------------------------------
  1911. function TS7Partner.GetParam(ParamNumber: integer; pValue: Pointer): integer;
  1912. begin
  1913. Result:=Par_SetParam(HP, ParamNumber, pValue);
  1914. end;
  1915. //------------------------------------------------------------------------------
  1916. function TS7Partner.SetParam(ParamNumber: integer; pValue: Pointer): integer;
  1917. begin
  1918. Result:=Par_SetParam(HP, ParamNumber, pValue);
  1919. end;
  1920. //------------------------------------------------------------------------------
  1921. function TS7Partner.SetRecvCallback(pRecvCompletion, usrPtr: pointer): integer;
  1922. begin
  1923. Result:=Par_SetRecvCallback(HP, pRecvCompletion, usrPtr);
  1924. end;
  1925. //------------------------------------------------------------------------------
  1926. function TS7Partner.SetSendCallback(pSendCompletion, usrPtr: pointer): integer;
  1927. begin
  1928. Result:=Par_SetSendCallback(HP, pSendCompletion, usrPtr);
  1929. end;
  1930. //------------------------------------------------------------------------------
  1931. function TS7Partner.Start: integer;
  1932. begin
  1933. Result:=Par_Start(HP);
  1934. end;
  1935. //------------------------------------------------------------------------------
  1936. function TS7Partner.StartTo(LocalAddress, RemoteAddress: AnsiString; LocalTSAP,
  1937. RemoteTSAP: word): integer;
  1938. begin
  1939. Result:=Par_StartTo(HP, PAnsiChar(LocalAddress), PAnsiChar(RemoteAddress),
  1940. LocalTSAP, RemoteTSAP);
  1941. end;
  1942. //------------------------------------------------------------------------------
  1943. function TS7Partner.Stop: integer;
  1944. begin
  1945. Result:=Par_Stop(HP);
  1946. end;
  1947. //------------------------------------------------------------------------------
  1948. function TS7Partner.WaitAsBSendCompletion(Timeout: longword): integer;
  1949. begin
  1950. Result:=Par_WaitAsBSendCompletion(HP, Timeout);
  1951. end;
  1952. //******************************************************************************
  1953. // S7 CLASS IMPLEMENTATION
  1954. //******************************************************************************
  1955. function TS7Helper.GetBit(pval: pointer; BitIndex: integer): boolean;
  1956. Const
  1957. Mask : array[0..7] of byte = ($01,$02,$04,$08,$10,$20,$40,$80);
  1958. begin
  1959. if BitIndex<0 then BitIndex:=0;
  1960. if BitIndex>7 then BitIndex:=7;
  1961. Result:=pbyte(pval)^ and Mask[BitIndex] <> 0;
  1962. end;
  1963. //------------------------------------------------------------------------------
  1964. function TS7Helper.GetDateTime(pval: pointer): TDateTime;
  1965. Type
  1966. S7DT = packed array[0..7] of byte;
  1967. Var
  1968. Buffer : ^S7DT;
  1969. YY,MM,DD,HH,NN,SS,MS : word;
  1970. C,D,U : integer;
  1971. function BCD(const B: byte): word;
  1972. begin
  1973. Result:=(B and $0F) + ((B shr 4) * 10);
  1974. end;
  1975. begin
  1976. Buffer:=pval;
  1977. YY:= Buffer^[0];
  1978. if YY>137 then // 137 dec = 89 BCD
  1979. YY:=1900+BCD(YY)
  1980. else
  1981. YY:=2000+BCD(YY);
  1982. MM:=BCD(Buffer^[1]);
  1983. DD:=BCD(Buffer^[2]);
  1984. HH:=BCD(Buffer^[3]);
  1985. NN:=BCD(Buffer^[4]);
  1986. SS:=BCD(Buffer^[5]);
  1987. // Millisec
  1988. MS:=Buffer^[6];
  1989. MS:=(MS shl 8)+Buffer^[7];
  1990. // Last 4 bit are Day of Week
  1991. MS:=MS shr 4;
  1992. // Hex to Int
  1993. C:=((MS and $0F00) shr 8) * 100;
  1994. D:=((MS and $00F0) shr 4) * 10;
  1995. U:= (MS and $000F);
  1996. MS:=C+D+U;
  1997. TryEncodeDateTime(YY,MM,DD,HH,NN,SS,MS,Result);
  1998. end;
  1999. //------------------------------------------------------------------------------
  2000. function TS7Helper.GetDInt(pval: pointer): longint;
  2001. Var
  2002. DW : packed array[0..3] of byte absolute Result;
  2003. begin
  2004. DW[0]:=pbyte(NativeInt(pval)+3)^;
  2005. DW[1]:=pbyte(NativeInt(pval)+2)^;
  2006. DW[2]:=pbyte(NativeInt(pval)+1)^;
  2007. DW[3]:=pbyte(pval)^;
  2008. end;
  2009. //------------------------------------------------------------------------------
  2010. function TS7Helper.GetDWord(pval: pointer): longword;
  2011. Var
  2012. DW : packed array[0..3] of byte absolute Result;
  2013. begin
  2014. DW[0]:=pbyte(NativeInt(pval)+3)^;
  2015. DW[1]:=pbyte(NativeInt(pval)+2)^;
  2016. DW[2]:=pbyte(NativeInt(pval)+1)^;
  2017. DW[3]:=pbyte(pval)^;
  2018. end;
  2019. //------------------------------------------------------------------------------
  2020. function TS7Helper.GetInt(pval: pointer): smallint;
  2021. Var
  2022. BW : packed array[0..1] of byte absolute Result;
  2023. begin
  2024. BW[0]:=pbyte(NativeInt(pval)+1)^;
  2025. BW[1]:=pbyte(pval)^;
  2026. end;
  2027. //------------------------------------------------------------------------------
  2028. function TS7Helper.GetReal(pval: pointer): single;
  2029. Var
  2030. DW : packed array[0..3] of byte absolute Result;
  2031. begin
  2032. DW[0]:=pbyte(NativeInt(pval)+3)^;
  2033. DW[1]:=pbyte(NativeInt(pval)+2)^;
  2034. DW[2]:=pbyte(NativeInt(pval)+1)^;
  2035. DW[3]:=pbyte(pval)^;
  2036. end;
  2037. //------------------------------------------------------------------------------
  2038. function TS7Helper.GetWord(pval: pointer): word;
  2039. Var
  2040. BW : packed array[0..1] of byte absolute Result;
  2041. begin
  2042. BW[0]:=pbyte(NativeInt(pval)+1)^;
  2043. BW[1]:=pbyte(pval)^;
  2044. end;
  2045. //------------------------------------------------------------------------------
  2046. procedure TS7Helper.Reverse(pval: pointer; const S7Type: TS7Type);
  2047. Var
  2048. DT : TDateTime;
  2049. begin
  2050. case S7Type of
  2051. S7Int,
  2052. S7Word: SetWord(pval, pword(pval)^);
  2053. S7DInt,
  2054. S7DWord,
  2055. S7Real: SetDWord(pval, plongword(pval)^);
  2056. S7DT_To_DateTime: pDateTime(pval)^:=GetDateTime(pval);
  2057. DateTime_To_S7DT: begin
  2058. DT:=pdateTime(pval)^;
  2059. SetDateTime(pval, DT);
  2060. end;
  2061. end;
  2062. end;
  2063. //------------------------------------------------------------------------------
  2064. procedure TS7Helper.SetBit(pval: pointer; BitIndex: integer; const Value: boolean);
  2065. Const
  2066. Mask : array[0..7] of byte = ($01,$02,$04,$08,$10,$20,$40,$80);
  2067. begin
  2068. if BitIndex<0 then BitIndex:=0;
  2069. if BitIndex>7 then BitIndex:=7;
  2070. if Value then
  2071. pbyte(pval)^ := pbyte(pval)^ or Mask[BitIndex]
  2072. else
  2073. pbyte(pval)^ := pbyte(pval)^ and not Mask[BitIndex];
  2074. end;
  2075. //------------------------------------------------------------------------------
  2076. procedure TS7Helper.SetDateTime(pval: pointer; const Value: TDateTime);
  2077. Type
  2078. DATE_AND_TIME = packed array[1..8] of byte;
  2079. pDT = ^DATE_AND_TIME;
  2080. function BCD(Value : word) : byte;
  2081. begin
  2082. Result:=((Value div 10) shl 4) OR (Value mod 10);
  2083. end;
  2084. function BCDW(Value : word) : word;
  2085. Var
  2086. AppC, AppD : word;
  2087. begin
  2088. AppC :=(Value div 100);
  2089. Dec(Value,AppC * 100);
  2090. AppD :=(Value div 10);
  2091. Dec(Value,AppD * 10);
  2092. Result:=(AppC shl 8) + (AppD shl 4) + Value;
  2093. end;
  2094. Var
  2095. DT : pDT;
  2096. MsDOW, AYear, AMonth, ADay,
  2097. AHour, AMinute, ASecond, AMilliSecond: Word;
  2098. begin
  2099. DT:=pval;
  2100. DecodeDateTime(Value,AYear, AMonth, ADay, AHour, AMinute, ASecond, AMilliSecond);
  2101. if AYear>1999 then
  2102. AYear:=AYear-2000
  2103. else
  2104. AYear:=AYear-1900;
  2105. DT^[1]:=BCD(AYear);
  2106. DT^[2]:=BCD(AMonth);
  2107. DT^[3]:=BCD(ADay);
  2108. DT^[4]:=BCD(AHour);
  2109. DT^[5]:=BCD(AMinute);
  2110. DT^[6]:=BCD(ASecond);
  2111. MsDOW:=(BCDW(AMillisecond) shl 4) + DayOfWeek(Value)+1;
  2112. DT^[7]:=HI(MsDOW);
  2113. DT^[8]:=LO(MsDOW);
  2114. end;
  2115. //------------------------------------------------------------------------------
  2116. procedure TS7Helper.SetDInt(pval: pointer; const Value: longint);
  2117. Var
  2118. DW : packed array[0..3] of byte absolute value;
  2119. begin
  2120. pbyte(pval)^:=DW[3];
  2121. pbyte(NativeInt(pval)+1)^:=DW[2];
  2122. pbyte(NativeInt(pval)+2)^:=DW[1];
  2123. pbyte(NativeInt(pval)+3)^:=DW[0];
  2124. end;
  2125. //------------------------------------------------------------------------------
  2126. procedure TS7Helper.SetDWord(pval: pointer; const Value: longword);
  2127. Var
  2128. DW : packed array[0..3] of byte absolute value;
  2129. begin
  2130. pbyte(pval)^:=DW[3];
  2131. pbyte(NativeInt(pval)+1)^:=DW[2];
  2132. pbyte(NativeInt(pval)+2)^:=DW[1];
  2133. pbyte(NativeInt(pval)+3)^:=DW[0];
  2134. end;
  2135. //------------------------------------------------------------------------------
  2136. procedure TS7Helper.SetInt(pval: pointer; const Value: smallint);
  2137. Var
  2138. BW : packed array[0..1] of byte absolute value;
  2139. begin
  2140. pbyte(NativeInt(pval)+1)^:=BW[0];
  2141. pbyte(pval)^:=BW[1];
  2142. end;
  2143. //------------------------------------------------------------------------------
  2144. procedure TS7Helper.SetReal(pval: pointer; const Value: single);
  2145. Var
  2146. DW : packed array[0..3] of byte absolute value;
  2147. begin
  2148. pbyte(pval)^:=DW[3];
  2149. pbyte(NativeInt(pval)+1)^:=DW[2];
  2150. pbyte(NativeInt(pval)+2)^:=DW[1];
  2151. pbyte(NativeInt(pval)+3)^:=DW[0];
  2152. end;
  2153. //------------------------------------------------------------------------------
  2154. procedure TS7Helper.SetWord(pval: pointer; const Value: word);
  2155. Var
  2156. BW : packed array[0..1] of byte absolute value;
  2157. begin
  2158. pbyte(NativeInt(pval)+1)^:=BW[0];
  2159. pbyte(pval)^:=BW[1];
  2160. end;
  2161. //******************************************************************************
  2162. // TEXT ROUTINES
  2163. //******************************************************************************
  2164. function CliErrorText(Error : integer) : string;
  2165. Var
  2166. Text : packed array[0..TextLen-1] of AnsiChar;
  2167. begin
  2168. if Cli_ErrorText(Error, @Text, TextLen)=0 then
  2169. Result:=String(Text)
  2170. else
  2171. Result:='LIB : Error getting text';
  2172. end;
  2173. //---------------------------------------------------------------------------
  2174. function SrvErrorText(Error : integer) : string;
  2175. Var
  2176. Text : packed array[0..TextLen-1] of AnsiChar;
  2177. begin
  2178. if Srv_ErrorText(Error, @Text, TextLen)=0 then
  2179. Result:=String(Text)
  2180. else
  2181. Result:='LIB : Error getting text';
  2182. end;
  2183. //---------------------------------------------------------------------------
  2184. function ParErrorText(Error : integer) : string;
  2185. Var
  2186. Text : packed array[0..TextLen-1] of AnsiChar;
  2187. begin
  2188. if Par_ErrorText(Error, @Text, TextLen)=0 then
  2189. Result:=String(Text)
  2190. else
  2191. Result:='LIB : Error getting text';
  2192. end;
  2193. //---------------------------------------------------------------------------
  2194. function SrvEventText(var Event : TSrvEvent) : string;
  2195. Var
  2196. Text : packed array[0..TextLen-1] of AnsiChar;
  2197. begin
  2198. if Srv_EventText(Event, @Text, TextLen)=0 then
  2199. Result:=String(Text)
  2200. else
  2201. Result:='LIB : Error getting text';
  2202. end;
  2203. initialization
  2204. S7 := TS7Helper.Create;
  2205. finalization
  2206. S7.Free;
  2207. end.