snap7.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. | C++ Snap 7 classes Implementation |
  28. | |
  29. |=============================================================================*/
  30. #include "snap7.h"
  31. //==============================================================================
  32. // CLIENT
  33. //==============================================================================
  34. TS7Client::TS7Client()
  35. {
  36. Client=Cli_Create();
  37. }
  38. //---------------------------------------------------------------------------
  39. TS7Client::~TS7Client()
  40. {
  41. Cli_Destroy(&Client);
  42. }
  43. //---------------------------------------------------------------------------
  44. int TS7Client::Connect()
  45. {
  46. return Cli_Connect(Client);
  47. }
  48. //---------------------------------------------------------------------------
  49. int TS7Client::ConnectTo(const char *RemAddress, int Rack, int Slot)
  50. {
  51. return Cli_ConnectTo(Client, RemAddress, Rack, Slot);
  52. }
  53. //---------------------------------------------------------------------------
  54. int TS7Client::SetConnectionParams(const char *RemAddress, word LocalTSAP, word RemoteTSAP)
  55. {
  56. return Cli_SetConnectionParams(Client, RemAddress, LocalTSAP, RemoteTSAP);
  57. }
  58. //---------------------------------------------------------------------------
  59. int TS7Client::SetConnectionType(word ConnectionType)
  60. {
  61. return Cli_SetConnectionType(Client, ConnectionType);
  62. }
  63. //---------------------------------------------------------------------------
  64. int TS7Client::Disconnect()
  65. {
  66. return Cli_Disconnect(Client);
  67. }
  68. //---------------------------------------------------------------------------
  69. int TS7Client::GetParam(int ParamNumber, void *pValue)
  70. {
  71. return Cli_GetParam(Client, ParamNumber, pValue);
  72. }
  73. //---------------------------------------------------------------------------
  74. int TS7Client::SetParam(int ParamNumber, void *pValue)
  75. {
  76. return Cli_SetParam(Client, ParamNumber, pValue);
  77. }
  78. //---------------------------------------------------------------------------
  79. int TS7Client::ReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
  80. {
  81. return Cli_ReadArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  82. }
  83. //---------------------------------------------------------------------------
  84. int TS7Client::WriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
  85. {
  86. return Cli_WriteArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  87. }
  88. //---------------------------------------------------------------------------
  89. int TS7Client::ReadMultiVars(PS7DataItem Item, int ItemsCount)
  90. {
  91. return Cli_ReadMultiVars(Client, Item, ItemsCount);
  92. }
  93. //---------------------------------------------------------------------------
  94. int TS7Client::WriteMultiVars(PS7DataItem Item, int ItemsCount)
  95. {
  96. return Cli_WriteMultiVars(Client, Item, ItemsCount);
  97. }
  98. //---------------------------------------------------------------------------
  99. int TS7Client::DBRead(int DBNumber, int Start, int Size, void *pUsrData)
  100. {
  101. return Cli_DBRead(Client, DBNumber, Start, Size, pUsrData);
  102. }
  103. //---------------------------------------------------------------------------
  104. int TS7Client::DBWrite(int DBNumber, int Start, int Size, void *pUsrData)
  105. {
  106. return Cli_DBWrite(Client, DBNumber, Start, Size, pUsrData);
  107. }
  108. //---------------------------------------------------------------------------
  109. int TS7Client::MBRead(int Start, int Size, void *pUsrData)
  110. {
  111. return Cli_MBRead(Client, Start, Size, pUsrData);
  112. }
  113. //---------------------------------------------------------------------------
  114. int TS7Client::MBWrite(int Start, int Size, void *pUsrData)
  115. {
  116. return Cli_MBWrite(Client, Start, Size, pUsrData);
  117. }
  118. //---------------------------------------------------------------------------
  119. int TS7Client::EBRead(int Start, int Size, void *pUsrData)
  120. {
  121. return Cli_EBRead(Client, Start, Size, pUsrData);
  122. }
  123. //---------------------------------------------------------------------------
  124. int TS7Client::EBWrite(int Start, int Size, void *pUsrData)
  125. {
  126. return Cli_EBWrite(Client, Start, Size, pUsrData);
  127. }
  128. //---------------------------------------------------------------------------
  129. int TS7Client::ABRead(int Start, int Size, void *pUsrData)
  130. {
  131. return Cli_ABRead(Client, Start, Size, pUsrData);
  132. }
  133. //---------------------------------------------------------------------------
  134. int TS7Client::ABWrite(int Start, int Size, void *pUsrData)
  135. {
  136. return Cli_ABWrite(Client, Start, Size, pUsrData);
  137. }
  138. //---------------------------------------------------------------------------
  139. int TS7Client::TMRead(int Start, int Amount, void *pUsrData)
  140. {
  141. return Cli_TMRead(Client, Start, Amount, pUsrData);
  142. }
  143. //---------------------------------------------------------------------------
  144. int TS7Client::TMWrite(int Start, int Amount, void *pUsrData)
  145. {
  146. return Cli_TMWrite(Client, Start, Amount, pUsrData);
  147. }
  148. //---------------------------------------------------------------------------
  149. int TS7Client::CTRead(int Start, int Amount, void *pUsrData)
  150. {
  151. return Cli_CTRead(Client, Start, Amount, pUsrData);
  152. }
  153. //---------------------------------------------------------------------------
  154. int TS7Client::CTWrite(int Start, int Amount, void *pUsrData)
  155. {
  156. return Cli_CTWrite(Client, Start, Amount, pUsrData);
  157. }
  158. //---------------------------------------------------------------------------
  159. int TS7Client::ListBlocks(PS7BlocksList pUsrData)
  160. {
  161. return Cli_ListBlocks(Client, pUsrData);
  162. }
  163. //---------------------------------------------------------------------------
  164. int TS7Client::GetAgBlockInfo(int BlockType, int BlockNum, PS7BlockInfo pUsrData)
  165. {
  166. return Cli_GetAgBlockInfo(Client, BlockType, BlockNum, pUsrData);
  167. }
  168. //---------------------------------------------------------------------------
  169. int TS7Client::GetPgBlockInfo(void *pBlock, PS7BlockInfo pUsrData, int Size)
  170. {
  171. return Cli_GetPgBlockInfo(Client, pBlock, pUsrData, Size);
  172. }
  173. //---------------------------------------------------------------------------
  174. int TS7Client::ListBlocksOfType(int BlockType, TS7BlocksOfType *pUsrData, int *ItemsCount)
  175. {
  176. return Cli_ListBlocksOfType(Client, BlockType, pUsrData, ItemsCount);
  177. }
  178. //---------------------------------------------------------------------------
  179. int TS7Client::Upload(int BlockType, int BlockNum, void *pUsrData, int *Size)
  180. {
  181. return Cli_Upload(Client, BlockType, BlockNum, pUsrData, Size);
  182. }
  183. //---------------------------------------------------------------------------
  184. int TS7Client::FullUpload(int BlockType, int BlockNum, void *pUsrData, int *Size)
  185. {
  186. return Cli_FullUpload(Client, BlockType, BlockNum, pUsrData, Size);
  187. }
  188. //---------------------------------------------------------------------------
  189. int TS7Client::Download(int BlockNum, void *pUsrData, int Size)
  190. {
  191. return Cli_Download(Client, BlockNum, pUsrData, Size);
  192. }
  193. //---------------------------------------------------------------------------
  194. int TS7Client::Delete(int BlockType, int BlockNum)
  195. {
  196. return Cli_Delete(Client, BlockType, BlockNum);
  197. }
  198. //---------------------------------------------------------------------------
  199. int TS7Client::DBGet(int DBNumber, void *pUsrData, int *Size)
  200. {
  201. return Cli_DBGet(Client, DBNumber, pUsrData, Size);
  202. }
  203. //---------------------------------------------------------------------------
  204. int TS7Client::DBFill(int DBNumber, int FillChar)
  205. {
  206. return Cli_DBFill(Client, DBNumber, FillChar);
  207. }
  208. //---------------------------------------------------------------------------
  209. int TS7Client::GetPlcDateTime(tm *DateTime)
  210. {
  211. return Cli_GetPlcDateTime(Client, DateTime);
  212. }
  213. //---------------------------------------------------------------------------
  214. int TS7Client::SetPlcDateTime(tm *DateTime)
  215. {
  216. return Cli_SetPlcDateTime(Client, DateTime);
  217. }
  218. //---------------------------------------------------------------------------
  219. int TS7Client::SetPlcSystemDateTime()
  220. {
  221. return Cli_SetPlcSystemDateTime(Client);
  222. }
  223. //---------------------------------------------------------------------------
  224. int TS7Client::GetOrderCode(PS7OrderCode pUsrData)
  225. {
  226. return Cli_GetOrderCode(Client, pUsrData);
  227. }
  228. //---------------------------------------------------------------------------
  229. int TS7Client::GetCpuInfo(PS7CpuInfo pUsrData)
  230. {
  231. return Cli_GetCpuInfo(Client, pUsrData);
  232. }
  233. //---------------------------------------------------------------------------
  234. int TS7Client::GetCpInfo(PS7CpInfo pUsrData)
  235. {
  236. return Cli_GetCpInfo(Client, pUsrData);
  237. }
  238. //---------------------------------------------------------------------------
  239. int TS7Client::ReadSZL(int ID, int Index, PS7SZL pUsrData, int *Size)
  240. {
  241. return Cli_ReadSZL(Client, ID, Index, pUsrData, Size);
  242. }
  243. //---------------------------------------------------------------------------
  244. int TS7Client::ReadSZLList(PS7SZLList pUsrData, int *ItemsCount)
  245. {
  246. return Cli_ReadSZLList(Client, pUsrData, ItemsCount);
  247. }
  248. //---------------------------------------------------------------------------
  249. int TS7Client::PlcHotStart()
  250. {
  251. return Cli_PlcHotStart(Client);
  252. }
  253. //---------------------------------------------------------------------------
  254. int TS7Client::PlcColdStart()
  255. {
  256. return Cli_PlcColdStart(Client);
  257. }
  258. //---------------------------------------------------------------------------
  259. int TS7Client::PlcStop()
  260. {
  261. return Cli_PlcStop(Client);
  262. }
  263. //---------------------------------------------------------------------------
  264. int TS7Client::CopyRamToRom(int Timeout)
  265. {
  266. return Cli_CopyRamToRom(Client, Timeout);
  267. }
  268. //---------------------------------------------------------------------------
  269. int TS7Client::Compress(int Timeout)
  270. {
  271. return Cli_Compress(Client, Timeout);
  272. }
  273. //---------------------------------------------------------------------------
  274. int TS7Client::GetProtection(PS7Protection pUsrData)
  275. {
  276. return Cli_GetProtection(Client, pUsrData);
  277. }
  278. //---------------------------------------------------------------------------
  279. int TS7Client::SetSessionPassword(char *Password)
  280. {
  281. return Cli_SetSessionPassword(Client, Password);
  282. }
  283. //---------------------------------------------------------------------------
  284. int TS7Client::ClearSessionPassword()
  285. {
  286. return Cli_ClearSessionPassword(Client);
  287. }
  288. //---------------------------------------------------------------------------
  289. int TS7Client::ExecTime()
  290. {
  291. int Time;
  292. int Result = Cli_GetExecTime(Client, &Time);
  293. if (Result==0)
  294. return Time;
  295. else
  296. return Result;
  297. }
  298. //---------------------------------------------------------------------------
  299. int TS7Client::LastError()
  300. {
  301. int LastError;
  302. int Result =Cli_GetLastError(Client, &LastError);
  303. if (Result==0)
  304. return LastError;
  305. else
  306. return Result;
  307. }
  308. //---------------------------------------------------------------------------
  309. int TS7Client::PDULength()
  310. {
  311. int Requested, Negotiated;
  312. if (Cli_GetPduLength(Client, &Requested, &Negotiated)==0)
  313. return Negotiated;
  314. else
  315. return 0;
  316. }
  317. //---------------------------------------------------------------------------
  318. int TS7Client::PDURequested()
  319. {
  320. int Requested, Negotiated;
  321. if (Cli_GetPduLength(Client, &Requested, &Negotiated)==0)
  322. return Requested;
  323. else
  324. return 0;
  325. }
  326. //---------------------------------------------------------------------------
  327. int TS7Client::PlcStatus()
  328. {
  329. int Status;
  330. int Result = Cli_GetPlcStatus(Client, &Status);
  331. if (Result==0)
  332. return Status;
  333. else
  334. return Result;
  335. }
  336. //---------------------------------------------------------------------------
  337. bool TS7Client::Connected()
  338. {
  339. int ClientStatus;
  340. if (Cli_GetConnected(Client ,&ClientStatus)==0)
  341. return ClientStatus!=0;
  342. else
  343. return false;
  344. }
  345. //---------------------------------------------------------------------------
  346. int TS7Client::SetAsCallback(pfn_CliCompletion pCompletion, void *usrPtr)
  347. {
  348. return Cli_SetAsCallback(Client, pCompletion, usrPtr);
  349. }
  350. //---------------------------------------------------------------------------
  351. bool TS7Client::CheckAsCompletion(int *opResult)
  352. {
  353. return Cli_CheckAsCompletion(Client ,opResult)==JobComplete;
  354. }
  355. //---------------------------------------------------------------------------
  356. int TS7Client::WaitAsCompletion(longword Timeout)
  357. {
  358. return Cli_WaitAsCompletion(Client, Timeout);
  359. }
  360. //---------------------------------------------------------------------------
  361. int TS7Client::AsReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
  362. {
  363. return Cli_AsReadArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  364. }
  365. //---------------------------------------------------------------------------
  366. int TS7Client::AsWriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
  367. {
  368. return Cli_AsWriteArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  369. }
  370. //---------------------------------------------------------------------------
  371. int TS7Client::AsListBlocksOfType(int BlockType, PS7BlocksOfType pUsrData, int *ItemsCount)
  372. {
  373. return Cli_AsListBlocksOfType(Client, BlockType, pUsrData, ItemsCount);
  374. }
  375. //---------------------------------------------------------------------------
  376. int TS7Client::AsReadSZL(int ID, int Index, PS7SZL pUsrData, int *Size)
  377. {
  378. return Cli_AsReadSZL(Client, ID, Index, pUsrData, Size);
  379. }
  380. //---------------------------------------------------------------------------
  381. int TS7Client::AsReadSZLList(PS7SZLList pUsrData, int *ItemsCount)
  382. {
  383. return Cli_AsReadSZLList(Client, pUsrData, ItemsCount);
  384. }
  385. //---------------------------------------------------------------------------
  386. int TS7Client::AsUpload(int BlockType, int BlockNum, void *pUsrData, int *Size)
  387. {
  388. return Cli_AsUpload(Client, BlockType, BlockNum, pUsrData, Size);
  389. }
  390. //---------------------------------------------------------------------------
  391. int TS7Client::AsFullUpload(int BlockType, int BlockNum, void *pUsrData, int *Size)
  392. {
  393. return Cli_AsFullUpload(Client, BlockType, BlockNum, pUsrData, Size);
  394. }
  395. //---------------------------------------------------------------------------
  396. int TS7Client::AsDownload(int BlockNum, void *pUsrData, int Size)
  397. {
  398. return Cli_AsDownload(Client, BlockNum, pUsrData, Size);
  399. }
  400. //---------------------------------------------------------------------------
  401. int TS7Client::AsCopyRamToRom(int Timeout)
  402. {
  403. return Cli_AsCopyRamToRom(Client, Timeout);
  404. }
  405. //---------------------------------------------------------------------------
  406. int TS7Client::AsCompress(int Timeout)
  407. {
  408. return Cli_AsCompress(Client, Timeout);
  409. }
  410. //---------------------------------------------------------------------------
  411. int TS7Client::AsDBRead(int DBNumber, int Start, int Size, void *pUsrData)
  412. {
  413. return Cli_AsDBRead(Client, DBNumber, Start, Size, pUsrData);
  414. }
  415. //---------------------------------------------------------------------------
  416. int TS7Client::AsDBWrite(int DBNumber, int Start, int Size, void *pUsrData)
  417. {
  418. return Cli_AsDBWrite(Client, DBNumber, Start, Size, pUsrData);
  419. }
  420. //---------------------------------------------------------------------------
  421. int TS7Client::AsMBRead(int Start, int Size, void *pUsrData)
  422. {
  423. return Cli_AsMBRead(Client, Start, Size, pUsrData);
  424. }
  425. //---------------------------------------------------------------------------
  426. int TS7Client::AsMBWrite(int Start, int Size, void *pUsrData)
  427. {
  428. return Cli_AsMBWrite(Client, Start, Size, pUsrData);
  429. }
  430. //---------------------------------------------------------------------------
  431. int TS7Client::AsEBRead(int Start, int Size, void *pUsrData)
  432. {
  433. return Cli_AsEBRead(Client, Start, Size, pUsrData);
  434. }
  435. //---------------------------------------------------------------------------
  436. int TS7Client::AsEBWrite(int Start, int Size, void *pUsrData)
  437. {
  438. return Cli_AsEBWrite(Client, Start, Size, pUsrData);
  439. }
  440. //---------------------------------------------------------------------------
  441. int TS7Client::AsABRead(int Start, int Size, void *pUsrData)
  442. {
  443. return Cli_AsABRead(Client, Start, Size, pUsrData);
  444. }
  445. //---------------------------------------------------------------------------
  446. int TS7Client::AsABWrite(int Start, int Size, void *pUsrData)
  447. {
  448. return Cli_AsABWrite(Client, Start, Size, pUsrData);
  449. }
  450. //---------------------------------------------------------------------------
  451. int TS7Client::AsTMRead(int Start, int Amount, void *pUsrData)
  452. {
  453. return Cli_AsTMRead(Client, Start, Amount, pUsrData);
  454. }
  455. //---------------------------------------------------------------------------
  456. int TS7Client::AsTMWrite(int Start, int Amount, void *pUsrData)
  457. {
  458. return Cli_AsTMWrite(Client, Start, Amount, pUsrData);
  459. }
  460. //---------------------------------------------------------------------------
  461. int TS7Client::AsCTRead(int Start, int Amount, void *pUsrData)
  462. {
  463. return Cli_AsCTRead(Client, Start, Amount, pUsrData);
  464. }
  465. //---------------------------------------------------------------------------
  466. int TS7Client::AsCTWrite(int Start, int Amount, void *pUsrData)
  467. {
  468. return Cli_AsCTWrite(Client, Start, Amount, pUsrData);
  469. }
  470. //---------------------------------------------------------------------------
  471. int TS7Client::AsDBGet(int DBNumber, void *pUsrData, int *Size)
  472. {
  473. return Cli_AsDBGet(Client, DBNumber, pUsrData, Size);
  474. }
  475. //---------------------------------------------------------------------------
  476. int TS7Client::AsDBFill(int DBNumber, int FillChar)
  477. {
  478. return Cli_AsDBFill(Client, DBNumber, FillChar);
  479. }
  480. //==============================================================================
  481. // SERVER
  482. //==============================================================================
  483. TS7Server::TS7Server()
  484. {
  485. Server=Srv_Create();
  486. }
  487. //---------------------------------------------------------------------------
  488. TS7Server::~TS7Server()
  489. {
  490. Srv_Destroy(&Server);
  491. }
  492. //---------------------------------------------------------------------------
  493. int TS7Server::Start()
  494. {
  495. return Srv_Start(Server);
  496. }
  497. //---------------------------------------------------------------------------
  498. int TS7Server::StartTo(const char *Address)
  499. {
  500. return Srv_StartTo(Server, Address);
  501. }
  502. //---------------------------------------------------------------------------
  503. int TS7Server::Stop()
  504. {
  505. return Srv_Stop(Server);
  506. }
  507. //---------------------------------------------------------------------------
  508. int TS7Server::GetParam(int ParamNumber, void *pValue)
  509. {
  510. return Srv_GetParam(Server, ParamNumber, pValue);
  511. }
  512. //---------------------------------------------------------------------------
  513. int TS7Server::SetParam(int ParamNumber, void *pValue)
  514. {
  515. return Srv_SetParam(Server, ParamNumber, pValue);
  516. }
  517. //---------------------------------------------------------------------------
  518. int TS7Server::SetEventsCallback(pfn_SrvCallBack PCallBack, void *UsrPtr)
  519. {
  520. return Srv_SetEventsCallback(Server, PCallBack, UsrPtr);
  521. }
  522. //---------------------------------------------------------------------------
  523. int TS7Server::SetReadEventsCallback(pfn_SrvCallBack PCallBack, void *UsrPtr)
  524. {
  525. return Srv_SetReadEventsCallback(Server, PCallBack, UsrPtr);
  526. }
  527. //---------------------------------------------------------------------------
  528. int TS7Server::SetRWAreaCallback(pfn_RWAreaCallBack PCallBack, void *UsrPtr)
  529. {
  530. return Srv_SetRWAreaCallback(Server, PCallBack, UsrPtr);
  531. }
  532. //---------------------------------------------------------------------------
  533. bool TS7Server::PickEvent(TSrvEvent *pEvent)
  534. {
  535. int EvtReady;
  536. if (Srv_PickEvent(Server, pEvent, &EvtReady)==0)
  537. return EvtReady!=0;
  538. else
  539. return false;
  540. }
  541. //---------------------------------------------------------------------------
  542. void TS7Server::ClearEvents()
  543. {
  544. Srv_ClearEvents(Server);
  545. }
  546. //---------------------------------------------------------------------------
  547. longword TS7Server::GetEventsMask()
  548. {
  549. longword Mask;
  550. int Result = Srv_GetMask(Server, mkEvent, &Mask);
  551. if (Result==0)
  552. return Mask;
  553. else
  554. return 0;
  555. }
  556. //---------------------------------------------------------------------------
  557. longword TS7Server::GetLogMask()
  558. {
  559. longword Mask;
  560. int Result = Srv_GetMask(Server, mkLog, &Mask);
  561. if (Result==0)
  562. return Mask;
  563. else
  564. return 0;
  565. }
  566. //---------------------------------------------------------------------------
  567. void TS7Server::SetEventsMask(longword Mask)
  568. {
  569. Srv_SetMask(Server, mkEvent, Mask);
  570. }
  571. //---------------------------------------------------------------------------
  572. void TS7Server::SetLogMask(longword Mask)
  573. {
  574. Srv_SetMask(Server, mkLog, Mask);
  575. }
  576. //---------------------------------------------------------------------------
  577. int TS7Server::RegisterArea(int AreaCode, word Index, void *pUsrData, word Size)
  578. {
  579. return Srv_RegisterArea(Server, AreaCode, Index, pUsrData, Size);
  580. }
  581. //---------------------------------------------------------------------------
  582. int TS7Server::UnregisterArea(int AreaCode, word Index)
  583. {
  584. return Srv_UnregisterArea(Server, AreaCode, Index);
  585. }
  586. //---------------------------------------------------------------------------
  587. int TS7Server::LockArea(int AreaCode, word Index)
  588. {
  589. return Srv_LockArea(Server, AreaCode, Index);
  590. }
  591. //---------------------------------------------------------------------------
  592. int TS7Server::UnlockArea(int AreaCode, word Index)
  593. {
  594. return Srv_UnlockArea(Server, AreaCode, Index);
  595. }
  596. //---------------------------------------------------------------------------
  597. int TS7Server::ServerStatus()
  598. {
  599. int ServerStatus, CpuStatus, ClientsCount;
  600. int Result =Srv_GetStatus(Server, &ServerStatus, &CpuStatus, &ClientsCount);
  601. if (Result==0)
  602. return ServerStatus;
  603. else
  604. return Result;
  605. }
  606. //---------------------------------------------------------------------------
  607. int TS7Server::GetCpuStatus()
  608. {
  609. int ServerStatus, CpuStatus, ClientsCount;
  610. int Result =Srv_GetStatus(Server, &ServerStatus, &CpuStatus, &ClientsCount);
  611. if (Result==0)
  612. return CpuStatus;
  613. else
  614. return Result;
  615. }
  616. //---------------------------------------------------------------------------
  617. int TS7Server::ClientsCount()
  618. {
  619. int ServerStatus, CpuStatus, ClientsCount;
  620. int Result =Srv_GetStatus(Server, &ServerStatus, &CpuStatus, &ClientsCount);
  621. if (Result==0)
  622. return ClientsCount;
  623. else
  624. return Result;
  625. }
  626. //---------------------------------------------------------------------------
  627. int TS7Server::SetCpuStatus(int Status)
  628. {
  629. return Srv_SetCpuStatus(Server, Status);
  630. }
  631. //==============================================================================
  632. // PARTNER
  633. //==============================================================================
  634. TS7Partner::TS7Partner(bool Active)
  635. {
  636. Partner=Par_Create(int(Active));
  637. }
  638. //---------------------------------------------------------------------------
  639. TS7Partner::~TS7Partner()
  640. {
  641. Par_Destroy(&Partner);
  642. }
  643. //---------------------------------------------------------------------------
  644. int TS7Partner::GetParam(int ParamNumber, void *pValue)
  645. {
  646. return Par_GetParam(Partner, ParamNumber, pValue);
  647. }
  648. //---------------------------------------------------------------------------
  649. int TS7Partner::SetParam(int ParamNumber, void *pValue)
  650. {
  651. return Par_SetParam(Partner, ParamNumber, pValue);
  652. }
  653. //---------------------------------------------------------------------------
  654. int TS7Partner::Start()
  655. {
  656. return Par_Start(Partner);
  657. }
  658. //---------------------------------------------------------------------------
  659. int TS7Partner::StartTo(const char *LocalAddress, const char *RemoteAddress, int LocalTSAP, int RemoteTSAP)
  660. {
  661. return Par_StartTo(Partner, LocalAddress, RemoteAddress, LocalTSAP, RemoteTSAP);
  662. }
  663. //---------------------------------------------------------------------------
  664. int TS7Partner::Stop()
  665. {
  666. return Par_Stop(Partner);
  667. }
  668. //---------------------------------------------------------------------------
  669. int TS7Partner::BSend(longword R_ID, void *pUsrData, int Size)
  670. {
  671. return Par_BSend(Partner, R_ID, pUsrData, Size);
  672. }
  673. //---------------------------------------------------------------------------
  674. int TS7Partner::AsBSend(longword R_ID, void *pUsrData, int Size)
  675. {
  676. return Par_AsBSend(Partner, R_ID, pUsrData, Size);
  677. }
  678. //---------------------------------------------------------------------------
  679. bool TS7Partner::CheckAsBSendCompletion(int *opResult)
  680. {
  681. return Par_CheckAsBSendCompletion(Partner ,opResult)==JobComplete;
  682. }
  683. //---------------------------------------------------------------------------
  684. int TS7Partner::WaitAsBSendCompletion(longword Timeout)
  685. {
  686. return Par_WaitAsBSendCompletion(Partner, Timeout);
  687. }
  688. //---------------------------------------------------------------------------
  689. int TS7Partner::SetSendCallback(pfn_ParSendCompletion pCompletion, void *usrPtr)
  690. {
  691. return Par_SetSendCallback(Partner, pCompletion, usrPtr);
  692. }
  693. //---------------------------------------------------------------------------
  694. int TS7Partner::BRecv(longword *R_ID, void *pUsrData, int *Size, longword Timeout)
  695. {
  696. return Par_BRecv(Partner, R_ID, pUsrData, Size, Timeout);
  697. }
  698. //---------------------------------------------------------------------------
  699. bool TS7Partner::CheckAsBRecvCompletion(int *opResult, longword *R_ID, void *pUsrData, int *Size)
  700. {
  701. return Par_CheckAsBRecvCompletion(Partner, opResult, R_ID, pUsrData, Size) == JobComplete;
  702. }
  703. //---------------------------------------------------------------------------
  704. int TS7Partner::SetRecvCallback(pfn_ParRecvCallBack pCallback, void *usrPtr)
  705. {
  706. return Par_SetRecvCallback(Partner, pCallback, usrPtr);
  707. }
  708. //---------------------------------------------------------------------------
  709. int TS7Partner::Status()
  710. {
  711. int ParStatus;
  712. int Result = Par_GetStatus(Partner, &ParStatus);
  713. if (Result==0)
  714. return ParStatus;
  715. else
  716. return Result;
  717. }
  718. //---------------------------------------------------------------------------
  719. int TS7Partner::LastError()
  720. {
  721. int Error;
  722. int Result = Par_GetLastError(Partner, &Error);
  723. if (Result==0)
  724. return Error;
  725. else
  726. return Result;
  727. }
  728. //---------------------------------------------------------------------------
  729. int TS7Partner::GetTimes(longword *SendTime, longword *RecvTime)
  730. {
  731. return Par_GetTimes(Partner, SendTime, RecvTime);
  732. }
  733. //---------------------------------------------------------------------------
  734. int TS7Partner::GetStats(longword *BytesSent, longword *BytesRecv, longword *ErrSend, longword *ErrRecv)
  735. {
  736. return Par_GetStats(Partner, BytesSent, BytesRecv, ErrSend, ErrRecv);
  737. }
  738. //---------------------------------------------------------------------------
  739. bool TS7Partner::Linked()
  740. {
  741. return Status()==par_linked;
  742. }
  743. //==============================================================================
  744. // Text routines
  745. //==============================================================================
  746. TextString CliErrorText(int Error)
  747. {
  748. char text[TextLen];
  749. Cli_ErrorText(Error, text, TextLen);
  750. return TextString(text);
  751. }
  752. //---------------------------------------------------------------------------
  753. TextString SrvErrorText(int Error)
  754. {
  755. char text[TextLen];
  756. Srv_ErrorText(Error, text, TextLen);
  757. return TextString(text);
  758. }
  759. //---------------------------------------------------------------------------
  760. TextString ParErrorText(int Error)
  761. {
  762. char text[TextLen];
  763. Par_ErrorText(Error, text, TextLen);
  764. return TextString(text);
  765. }
  766. //---------------------------------------------------------------------------
  767. TextString SrvEventText(TSrvEvent *Event)
  768. {
  769. char text[TextLen];
  770. Srv_EventText(Event, text, TextLen);
  771. return TextString(text);
  772. }