Advertisement
Guest User

Untitled

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