cnap.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #include "cnap.h"
  2. //==============================================================================
  3. // CLIENT
  4. //==============================================================================
  5. TS7Client::TS7Client()
  6. {
  7. Client = Cli_Create();
  8. }
  9. //---------------------------------------------------------------------------
  10. TS7Client::~TS7Client()
  11. {
  12. Cli_Destroy(Client);
  13. }
  14. //---------------------------------------------------------------------------
  15. int TS7Client::Connect()
  16. {
  17. return Cli_Connect(Client);
  18. }
  19. //---------------------------------------------------------------------------
  20. int TS7Client::ConnectTo(const char* RemAddress, int Rack, int Slot)
  21. {
  22. return Cli_ConnectTo(Client, RemAddress, Rack, Slot);
  23. }
  24. //---------------------------------------------------------------------------
  25. int TS7Client::SetConnectionParams(const char* RemAddress, word LocalTSAP, word RemoteTSAP)
  26. {
  27. return Cli_SetConnectionParams(Client, RemAddress, LocalTSAP, RemoteTSAP);
  28. }
  29. //---------------------------------------------------------------------------
  30. int TS7Client::SetConnectionType(word ConnectionType)
  31. {
  32. return Cli_SetConnectionType(Client, ConnectionType);
  33. }
  34. //---------------------------------------------------------------------------
  35. int TS7Client::Disconnect()
  36. {
  37. return Cli_Disconnect(Client);
  38. }
  39. //---------------------------------------------------------------------------
  40. int TS7Client::GetParam(int ParamNumber, void* pValue)
  41. {
  42. return Cli_GetParam(Client, ParamNumber, pValue);
  43. }
  44. //---------------------------------------------------------------------------
  45. int TS7Client::SetParam(int ParamNumber, void* pValue)
  46. {
  47. return Cli_SetParam(Client, ParamNumber, pValue);
  48. }
  49. //---------------------------------------------------------------------------
  50. int TS7Client::ReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData)
  51. {
  52. return Cli_ReadArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  53. }
  54. //---------------------------------------------------------------------------
  55. int TS7Client::WriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData)
  56. {
  57. return Cli_WriteArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  58. }
  59. //---------------------------------------------------------------------------
  60. int TS7Client::ReadMultiVars(PS7DataItem Item, int ItemsCount)
  61. {
  62. return Cli_ReadMultiVars(Client, Item, ItemsCount);
  63. }
  64. //---------------------------------------------------------------------------
  65. int TS7Client::WriteMultiVars(PS7DataItem Item, int ItemsCount)
  66. {
  67. return Cli_WriteMultiVars(Client, Item, ItemsCount);
  68. }
  69. //---------------------------------------------------------------------------
  70. int TS7Client::DBRead(int DBNumber, int Start, int Size, void* pUsrData)
  71. {
  72. return Cli_DBRead(Client, DBNumber, Start, Size, pUsrData);
  73. }
  74. //---------------------------------------------------------------------------
  75. int TS7Client::DBWrite(int DBNumber, int Start, int Size, void* pUsrData)
  76. {
  77. return Cli_DBWrite(Client, DBNumber, Start, Size, pUsrData);
  78. }
  79. //---------------------------------------------------------------------------
  80. int TS7Client::MBRead(int Start, int Size, void* pUsrData)
  81. {
  82. return Cli_MBRead(Client, Start, Size, pUsrData);
  83. }
  84. //---------------------------------------------------------------------------
  85. int TS7Client::MBWrite(int Start, int Size, void* pUsrData)
  86. {
  87. return Cli_MBWrite(Client, Start, Size, pUsrData);
  88. }
  89. //---------------------------------------------------------------------------
  90. int TS7Client::EBRead(int Start, int Size, void* pUsrData)
  91. {
  92. return Cli_EBRead(Client, Start, Size, pUsrData);
  93. }
  94. //---------------------------------------------------------------------------
  95. int TS7Client::EBWrite(int Start, int Size, void* pUsrData)
  96. {
  97. return Cli_EBWrite(Client, Start, Size, pUsrData);
  98. }
  99. //---------------------------------------------------------------------------
  100. int TS7Client::ABRead(int Start, int Size, void* pUsrData)
  101. {
  102. return Cli_ABRead(Client, Start, Size, pUsrData);
  103. }
  104. //---------------------------------------------------------------------------
  105. int TS7Client::ABWrite(int Start, int Size, void* pUsrData)
  106. {
  107. return Cli_ABWrite(Client, Start, Size, pUsrData);
  108. }
  109. //---------------------------------------------------------------------------
  110. int TS7Client::TMRead(int Start, int Amount, void* pUsrData)
  111. {
  112. return Cli_TMRead(Client, Start, Amount, pUsrData);
  113. }
  114. //---------------------------------------------------------------------------
  115. int TS7Client::TMWrite(int Start, int Amount, void* pUsrData)
  116. {
  117. return Cli_TMWrite(Client, Start, Amount, pUsrData);
  118. }
  119. //---------------------------------------------------------------------------
  120. int TS7Client::CTRead(int Start, int Amount, void* pUsrData)
  121. {
  122. return Cli_CTRead(Client, Start, Amount, pUsrData);
  123. }
  124. //---------------------------------------------------------------------------
  125. int TS7Client::CTWrite(int Start, int Amount, void* pUsrData)
  126. {
  127. return Cli_CTWrite(Client, Start, Amount, pUsrData);
  128. }
  129. //---------------------------------------------------------------------------
  130. int TS7Client::ListBlocks(PS7BlocksList pUsrData)
  131. {
  132. return Cli_ListBlocks(Client, pUsrData);
  133. }
  134. //---------------------------------------------------------------------------
  135. int TS7Client::GetAgBlockInfo(int BlockType, int BlockNum, PS7BlockInfo pUsrData)
  136. {
  137. return Cli_GetAgBlockInfo(Client, BlockType, BlockNum, pUsrData);
  138. }
  139. //---------------------------------------------------------------------------
  140. int TS7Client::GetPgBlockInfo(void* pBlock, PS7BlockInfo pUsrData, int Size)
  141. {
  142. return Cli_GetPgBlockInfo(Client, pBlock, pUsrData, Size);
  143. }
  144. //---------------------------------------------------------------------------
  145. int TS7Client::ListBlocksOfType(int BlockType, TS7BlocksOfType* pUsrData, int* ItemsCount)
  146. {
  147. return Cli_ListBlocksOfType(Client, BlockType, pUsrData, *ItemsCount);
  148. }
  149. //---------------------------------------------------------------------------
  150. int TS7Client::Upload(int BlockType, int BlockNum, void* pUsrData, int* Size)
  151. {
  152. return Cli_Upload(Client, BlockType, BlockNum, pUsrData, *Size);
  153. }
  154. //---------------------------------------------------------------------------
  155. int TS7Client::FullUpload(int BlockType, int BlockNum, void* pUsrData, int* Size)
  156. {
  157. return Cli_FullUpload(Client, BlockType, BlockNum, pUsrData, *Size);
  158. }
  159. //---------------------------------------------------------------------------
  160. int TS7Client::Download(int BlockNum, void* pUsrData, int Size)
  161. {
  162. return Cli_Download(Client, BlockNum, pUsrData, Size);
  163. }
  164. //---------------------------------------------------------------------------
  165. int TS7Client::Delete(int BlockType, int BlockNum)
  166. {
  167. return Cli_Delete(Client, BlockType, BlockNum);
  168. }
  169. //---------------------------------------------------------------------------
  170. int TS7Client::DBGet(int DBNumber, void* pUsrData, int* Size)
  171. {
  172. return Cli_DBGet(Client, DBNumber, pUsrData, *Size);
  173. }
  174. //---------------------------------------------------------------------------
  175. int TS7Client::DBFill(int DBNumber, int FillChar)
  176. {
  177. return Cli_DBFill(Client, DBNumber, FillChar);
  178. }
  179. //---------------------------------------------------------------------------
  180. int TS7Client::GetPlcDateTime(tm* DateTime)
  181. {
  182. return Cli_GetPlcDateTime(Client, *DateTime);
  183. }
  184. //---------------------------------------------------------------------------
  185. int TS7Client::SetPlcDateTime(tm* DateTime)
  186. {
  187. return Cli_SetPlcDateTime(Client, DateTime);
  188. }
  189. //---------------------------------------------------------------------------
  190. int TS7Client::SetPlcSystemDateTime()
  191. {
  192. return Cli_SetPlcSystemDateTime(Client);
  193. }
  194. //---------------------------------------------------------------------------
  195. int TS7Client::GetOrderCode(PS7OrderCode pUsrData)
  196. {
  197. return Cli_GetOrderCode(Client, pUsrData);
  198. }
  199. //---------------------------------------------------------------------------
  200. int TS7Client::GetCpuInfo(PS7CpuInfo pUsrData)
  201. {
  202. return Cli_GetCpuInfo(Client, pUsrData);
  203. }
  204. //---------------------------------------------------------------------------
  205. int TS7Client::GetCpInfo(PS7CpInfo pUsrData)
  206. {
  207. return Cli_GetCpInfo(Client, pUsrData);
  208. }
  209. //---------------------------------------------------------------------------
  210. int TS7Client::ReadSZL(int ID, int Index, PS7SZL pUsrData, int* Size)
  211. {
  212. return Cli_ReadSZL(Client, ID, Index, pUsrData, *Size);
  213. }
  214. //---------------------------------------------------------------------------
  215. int TS7Client::ReadSZLList(PS7SZLList pUsrData, int* ItemsCount)
  216. {
  217. return Cli_ReadSZLList(Client, pUsrData, *ItemsCount);
  218. }
  219. //---------------------------------------------------------------------------
  220. int TS7Client::PlcHotStart()
  221. {
  222. return Cli_PlcHotStart(Client);
  223. }
  224. //---------------------------------------------------------------------------
  225. int TS7Client::PlcColdStart()
  226. {
  227. return Cli_PlcColdStart(Client);
  228. }
  229. //---------------------------------------------------------------------------
  230. int TS7Client::PlcStop()
  231. {
  232. return Cli_PlcStop(Client);
  233. }
  234. //---------------------------------------------------------------------------
  235. int TS7Client::CopyRamToRom(int Timeout)
  236. {
  237. return Cli_CopyRamToRom(Client, Timeout);
  238. }
  239. //---------------------------------------------------------------------------
  240. int TS7Client::Compress(int Timeout)
  241. {
  242. return Cli_Compress(Client, Timeout);
  243. }
  244. //---------------------------------------------------------------------------
  245. int TS7Client::GetProtection(PS7Protection pUsrData)
  246. {
  247. return Cli_GetProtection(Client, pUsrData);
  248. }
  249. //---------------------------------------------------------------------------
  250. int TS7Client::SetSessionPassword(char* Password)
  251. {
  252. return Cli_SetSessionPassword(Client, Password);
  253. }
  254. //---------------------------------------------------------------------------
  255. int TS7Client::ClearSessionPassword()
  256. {
  257. return Cli_ClearSessionPassword(Client);
  258. }
  259. //---------------------------------------------------------------------------
  260. int TS7Client::ExecTime()
  261. {
  262. int Time;
  263. int Result = Cli_GetExecTime(Client, *&Time);
  264. if (Result == 0)
  265. return Time;
  266. else
  267. return Result;
  268. }
  269. //---------------------------------------------------------------------------
  270. int TS7Client::LastError()
  271. {
  272. int LastError;
  273. int Result = Cli_GetLastError(Client, *&LastError);
  274. if (Result == 0)
  275. return LastError;
  276. else
  277. return Result;
  278. }
  279. //---------------------------------------------------------------------------
  280. int TS7Client::PDULength()
  281. {
  282. int Requested, Negotiated;
  283. if (Cli_GetPduLength(Client, *&Requested, *&Negotiated) == 0)
  284. return Negotiated;
  285. else
  286. return 0;
  287. }
  288. //---------------------------------------------------------------------------
  289. int TS7Client::PDURequested()
  290. {
  291. int Requested, Negotiated;
  292. if (Cli_GetPduLength(Client, *&Requested, *&Negotiated) == 0)
  293. return Requested;
  294. else
  295. return 0;
  296. }
  297. //---------------------------------------------------------------------------
  298. int TS7Client::PlcStatus()
  299. {
  300. int Status;
  301. int Result = Cli_GetPlcStatus(Client, *&Status);
  302. if (Result == 0)
  303. return Status;
  304. else
  305. return Result;
  306. }
  307. //---------------------------------------------------------------------------
  308. bool TS7Client::Connected()
  309. {
  310. int ClientStatus;
  311. if (Cli_GetConnected(Client, *&ClientStatus) == 0)
  312. return ClientStatus != 0;
  313. else
  314. return false;
  315. }
  316. //---------------------------------------------------------------------------
  317. int TS7Client::SetAsCallback(pfn_CliCompletion pCompletion, void* usrPtr)
  318. {
  319. return Cli_SetAsCallback(Client, pCompletion, usrPtr);
  320. }
  321. //---------------------------------------------------------------------------
  322. bool TS7Client::CheckAsCompletion(int* opResult)
  323. {
  324. return Cli_CheckAsCompletion(Client, *opResult) == JobComplete;
  325. }
  326. //---------------------------------------------------------------------------
  327. int TS7Client::WaitAsCompletion(longword Timeout)
  328. {
  329. return Cli_WaitAsCompletion(Client, Timeout);
  330. }
  331. //---------------------------------------------------------------------------
  332. int TS7Client::AsReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData)
  333. {
  334. return Cli_AsReadArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  335. }
  336. //---------------------------------------------------------------------------
  337. int TS7Client::AsWriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void* pUsrData)
  338. {
  339. return Cli_AsWriteArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
  340. }
  341. //---------------------------------------------------------------------------
  342. int TS7Client::AsListBlocksOfType(int BlockType, PS7BlocksOfType pUsrData, int* ItemsCount)
  343. {
  344. return Cli_AsListBlocksOfType(Client, BlockType, pUsrData, *ItemsCount);
  345. }
  346. //---------------------------------------------------------------------------
  347. int TS7Client::AsReadSZL(int ID, int Index, PS7SZL pUsrData, int* Size)
  348. {
  349. return Cli_AsReadSZL(Client, ID, Index, pUsrData, *Size);
  350. }
  351. //---------------------------------------------------------------------------
  352. int TS7Client::AsReadSZLList(PS7SZLList pUsrData, int* ItemsCount)
  353. {
  354. return Cli_AsReadSZLList(Client, pUsrData, *ItemsCount);
  355. }
  356. //---------------------------------------------------------------------------
  357. int TS7Client::AsUpload(int BlockType, int BlockNum, void* pUsrData, int* Size)
  358. {
  359. return Cli_AsUpload(Client, BlockType, BlockNum, pUsrData, *Size);
  360. }
  361. //---------------------------------------------------------------------------
  362. int TS7Client::AsFullUpload(int BlockType, int BlockNum, void* pUsrData, int* Size)
  363. {
  364. return Cli_AsFullUpload(Client, BlockType, BlockNum, pUsrData, *Size);
  365. }
  366. //---------------------------------------------------------------------------
  367. int TS7Client::AsDownload(int BlockNum, void* pUsrData, int Size)
  368. {
  369. return Cli_AsDownload(Client, BlockNum, pUsrData, Size);
  370. }
  371. //---------------------------------------------------------------------------
  372. int TS7Client::AsCopyRamToRom(int Timeout)
  373. {
  374. return Cli_AsCopyRamToRom(Client, Timeout);
  375. }
  376. //---------------------------------------------------------------------------
  377. int TS7Client::AsCompress(int Timeout)
  378. {
  379. return Cli_AsCompress(Client, Timeout);
  380. }
  381. //---------------------------------------------------------------------------
  382. int TS7Client::AsDBRead(int DBNumber, int Start, int Size, void* pUsrData)
  383. {
  384. return Cli_AsDBRead(Client, DBNumber, Start, Size, pUsrData);
  385. }
  386. //---------------------------------------------------------------------------
  387. int TS7Client::AsDBWrite(int DBNumber, int Start, int Size, void* pUsrData)
  388. {
  389. return Cli_AsDBWrite(Client, DBNumber, Start, Size, pUsrData);
  390. }
  391. //---------------------------------------------------------------------------
  392. int TS7Client::AsMBRead(int Start, int Size, void* pUsrData)
  393. {
  394. return Cli_AsMBRead(Client, Start, Size, pUsrData);
  395. }
  396. //---------------------------------------------------------------------------
  397. int TS7Client::AsMBWrite(int Start, int Size, void* pUsrData)
  398. {
  399. return Cli_AsMBWrite(Client, Start, Size, pUsrData);
  400. }
  401. //---------------------------------------------------------------------------
  402. int TS7Client::AsEBRead(int Start, int Size, void* pUsrData)
  403. {
  404. return Cli_AsEBRead(Client, Start, Size, pUsrData);
  405. }
  406. //---------------------------------------------------------------------------
  407. int TS7Client::AsEBWrite(int Start, int Size, void* pUsrData)
  408. {
  409. return Cli_AsEBWrite(Client, Start, Size, pUsrData);
  410. }
  411. //---------------------------------------------------------------------------
  412. int TS7Client::AsABRead(int Start, int Size, void* pUsrData)
  413. {
  414. return Cli_AsABRead(Client, Start, Size, pUsrData);
  415. }
  416. //---------------------------------------------------------------------------
  417. int TS7Client::AsABWrite(int Start, int Size, void* pUsrData)
  418. {
  419. return Cli_AsABWrite(Client, Start, Size, pUsrData);
  420. }
  421. //---------------------------------------------------------------------------
  422. int TS7Client::AsTMRead(int Start, int Amount, void* pUsrData)
  423. {
  424. return Cli_AsTMRead(Client, Start, Amount, pUsrData);
  425. }
  426. //---------------------------------------------------------------------------
  427. int TS7Client::AsTMWrite(int Start, int Amount, void* pUsrData)
  428. {
  429. return Cli_AsTMWrite(Client, Start, Amount, pUsrData);
  430. }
  431. //---------------------------------------------------------------------------
  432. int TS7Client::AsCTRead(int Start, int Amount, void* pUsrData)
  433. {
  434. return Cli_AsCTRead(Client, Start, Amount, pUsrData);
  435. }
  436. //---------------------------------------------------------------------------
  437. int TS7Client::AsCTWrite(int Start, int Amount, void* pUsrData)
  438. {
  439. return Cli_AsCTWrite(Client, Start, Amount, pUsrData);
  440. }
  441. //---------------------------------------------------------------------------
  442. int TS7Client::AsDBGet(int DBNumber, void* pUsrData, int* Size)
  443. {
  444. return Cli_AsDBGet(Client, DBNumber, pUsrData, *Size);
  445. }
  446. //---------------------------------------------------------------------------
  447. int TS7Client::AsDBFill(int DBNumber, int FillChar)
  448. {
  449. return Cli_AsDBFill(Client, DBNumber, FillChar);
  450. }