123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- /*=============================================================================|
- | PROJECT SNAP7 1.4.0 |
- |==============================================================================|
- | Copyright (C) 2013, 2014 Davide Nardella |
- | All rights reserved. |
- |==============================================================================|
- | SNAP7 is free software: you can redistribute it and/or modify |
- | it under the terms of the Lesser GNU General Public License as published by |
- | the Free Software Foundation, either version 3 of the License, or |
- | (at your option) any later version. |
- | |
- | It means that you can distribute your commercial software linked with |
- | SNAP7 without the requirement to distribute the source code of your |
- | application and without the requirement that your application be itself |
- | distributed under LGPL. |
- | |
- | SNAP7 is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | Lesser GNU General Public License for more details. |
- | |
- | You should have received a copy of the GNU General Public License and a |
- | copy of Lesser GNU General Public License along with Snap7. |
- | If not, see http://www.gnu.org/licenses/ |
- |==============================================================================|
- | |
- | C++ Snap 7 classes Implementation |
- | |
- |=============================================================================*/
- #include "snap7.h"
- //==============================================================================
- // CLIENT
- //==============================================================================
- TS7Client::TS7Client()
- {
- Client=Cli_Create();
- }
- //---------------------------------------------------------------------------
- TS7Client::~TS7Client()
- {
- Cli_Destroy(&Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::Connect()
- {
- return Cli_Connect(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ConnectTo(const char *RemAddress, int Rack, int Slot)
- {
- return Cli_ConnectTo(Client, RemAddress, Rack, Slot);
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetConnectionParams(const char *RemAddress, word LocalTSAP, word RemoteTSAP)
- {
- return Cli_SetConnectionParams(Client, RemAddress, LocalTSAP, RemoteTSAP);
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetConnectionType(word ConnectionType)
- {
- return Cli_SetConnectionType(Client, ConnectionType);
- }
- //---------------------------------------------------------------------------
- int TS7Client::Disconnect()
- {
- return Cli_Disconnect(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetParam(int ParamNumber, void *pValue)
- {
- return Cli_GetParam(Client, ParamNumber, pValue);
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetParam(int ParamNumber, void *pValue)
- {
- return Cli_SetParam(Client, ParamNumber, pValue);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
- {
- return Cli_ReadArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::WriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
- {
- return Cli_WriteArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ReadMultiVars(PS7DataItem Item, int ItemsCount)
- {
- return Cli_ReadMultiVars(Client, Item, ItemsCount);
- }
- //---------------------------------------------------------------------------
- int TS7Client::WriteMultiVars(PS7DataItem Item, int ItemsCount)
- {
- return Cli_WriteMultiVars(Client, Item, ItemsCount);
- }
- //---------------------------------------------------------------------------
- int TS7Client::DBRead(int DBNumber, int Start, int Size, void *pUsrData)
- {
- return Cli_DBRead(Client, DBNumber, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::DBWrite(int DBNumber, int Start, int Size, void *pUsrData)
- {
- return Cli_DBWrite(Client, DBNumber, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::MBRead(int Start, int Size, void *pUsrData)
- {
- return Cli_MBRead(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::MBWrite(int Start, int Size, void *pUsrData)
- {
- return Cli_MBWrite(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::EBRead(int Start, int Size, void *pUsrData)
- {
- return Cli_EBRead(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::EBWrite(int Start, int Size, void *pUsrData)
- {
- return Cli_EBWrite(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ABRead(int Start, int Size, void *pUsrData)
- {
- return Cli_ABRead(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ABWrite(int Start, int Size, void *pUsrData)
- {
- return Cli_ABWrite(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::TMRead(int Start, int Amount, void *pUsrData)
- {
- return Cli_TMRead(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::TMWrite(int Start, int Amount, void *pUsrData)
- {
- return Cli_TMWrite(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::CTRead(int Start, int Amount, void *pUsrData)
- {
- return Cli_CTRead(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::CTWrite(int Start, int Amount, void *pUsrData)
- {
- return Cli_CTWrite(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ListBlocks(PS7BlocksList pUsrData)
- {
- return Cli_ListBlocks(Client, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetAgBlockInfo(int BlockType, int BlockNum, PS7BlockInfo pUsrData)
- {
- return Cli_GetAgBlockInfo(Client, BlockType, BlockNum, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetPgBlockInfo(void *pBlock, PS7BlockInfo pUsrData, int Size)
- {
- return Cli_GetPgBlockInfo(Client, pBlock, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ListBlocksOfType(int BlockType, TS7BlocksOfType *pUsrData, int *ItemsCount)
- {
- return Cli_ListBlocksOfType(Client, BlockType, pUsrData, ItemsCount);
- }
- //---------------------------------------------------------------------------
- int TS7Client::Upload(int BlockType, int BlockNum, void *pUsrData, int *Size)
- {
- return Cli_Upload(Client, BlockType, BlockNum, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::FullUpload(int BlockType, int BlockNum, void *pUsrData, int *Size)
- {
- return Cli_FullUpload(Client, BlockType, BlockNum, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::Download(int BlockNum, void *pUsrData, int Size)
- {
- return Cli_Download(Client, BlockNum, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::Delete(int BlockType, int BlockNum)
- {
- return Cli_Delete(Client, BlockType, BlockNum);
- }
- //---------------------------------------------------------------------------
- int TS7Client::DBGet(int DBNumber, void *pUsrData, int *Size)
- {
- return Cli_DBGet(Client, DBNumber, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::DBFill(int DBNumber, int FillChar)
- {
- return Cli_DBFill(Client, DBNumber, FillChar);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetPlcDateTime(tm *DateTime)
- {
- return Cli_GetPlcDateTime(Client, DateTime);
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetPlcDateTime(tm *DateTime)
- {
- return Cli_SetPlcDateTime(Client, DateTime);
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetPlcSystemDateTime()
- {
- return Cli_SetPlcSystemDateTime(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetOrderCode(PS7OrderCode pUsrData)
- {
- return Cli_GetOrderCode(Client, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetCpuInfo(PS7CpuInfo pUsrData)
- {
- return Cli_GetCpuInfo(Client, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetCpInfo(PS7CpInfo pUsrData)
- {
- return Cli_GetCpInfo(Client, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ReadSZL(int ID, int Index, PS7SZL pUsrData, int *Size)
- {
- return Cli_ReadSZL(Client, ID, Index, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ReadSZLList(PS7SZLList pUsrData, int *ItemsCount)
- {
- return Cli_ReadSZLList(Client, pUsrData, ItemsCount);
- }
- //---------------------------------------------------------------------------
- int TS7Client::PlcHotStart()
- {
- return Cli_PlcHotStart(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::PlcColdStart()
- {
- return Cli_PlcColdStart(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::PlcStop()
- {
- return Cli_PlcStop(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::CopyRamToRom(int Timeout)
- {
- return Cli_CopyRamToRom(Client, Timeout);
- }
- //---------------------------------------------------------------------------
- int TS7Client::Compress(int Timeout)
- {
- return Cli_Compress(Client, Timeout);
- }
- //---------------------------------------------------------------------------
- int TS7Client::GetProtection(PS7Protection pUsrData)
- {
- return Cli_GetProtection(Client, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetSessionPassword(char *Password)
- {
- return Cli_SetSessionPassword(Client, Password);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ClearSessionPassword()
- {
- return Cli_ClearSessionPassword(Client);
- }
- //---------------------------------------------------------------------------
- int TS7Client::ExecTime()
- {
- int Time;
- int Result = Cli_GetExecTime(Client, &Time);
- if (Result==0)
- return Time;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Client::LastError()
- {
- int LastError;
- int Result =Cli_GetLastError(Client, &LastError);
- if (Result==0)
- return LastError;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Client::PDULength()
- {
- int Requested, Negotiated;
- if (Cli_GetPduLength(Client, &Requested, &Negotiated)==0)
- return Negotiated;
- else
- return 0;
- }
- //---------------------------------------------------------------------------
- int TS7Client::PDURequested()
- {
- int Requested, Negotiated;
- if (Cli_GetPduLength(Client, &Requested, &Negotiated)==0)
- return Requested;
- else
- return 0;
- }
- //---------------------------------------------------------------------------
- int TS7Client::PlcStatus()
- {
- int Status;
- int Result = Cli_GetPlcStatus(Client, &Status);
- if (Result==0)
- return Status;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- bool TS7Client::Connected()
- {
- int ClientStatus;
- if (Cli_GetConnected(Client ,&ClientStatus)==0)
- return ClientStatus!=0;
- else
- return false;
- }
- //---------------------------------------------------------------------------
- int TS7Client::SetAsCallback(pfn_CliCompletion pCompletion, void *usrPtr)
- {
- return Cli_SetAsCallback(Client, pCompletion, usrPtr);
- }
- //---------------------------------------------------------------------------
- bool TS7Client::CheckAsCompletion(int *opResult)
- {
- return Cli_CheckAsCompletion(Client ,opResult)==JobComplete;
- }
- //---------------------------------------------------------------------------
- int TS7Client::WaitAsCompletion(longword Timeout)
- {
- return Cli_WaitAsCompletion(Client, Timeout);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsReadArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
- {
- return Cli_AsReadArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsWriteArea(int Area, int DBNumber, int Start, int Amount, int WordLen, void *pUsrData)
- {
- return Cli_AsWriteArea(Client, Area, DBNumber, Start, Amount, WordLen, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsListBlocksOfType(int BlockType, PS7BlocksOfType pUsrData, int *ItemsCount)
- {
- return Cli_AsListBlocksOfType(Client, BlockType, pUsrData, ItemsCount);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsReadSZL(int ID, int Index, PS7SZL pUsrData, int *Size)
- {
- return Cli_AsReadSZL(Client, ID, Index, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsReadSZLList(PS7SZLList pUsrData, int *ItemsCount)
- {
- return Cli_AsReadSZLList(Client, pUsrData, ItemsCount);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsUpload(int BlockType, int BlockNum, void *pUsrData, int *Size)
- {
- return Cli_AsUpload(Client, BlockType, BlockNum, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsFullUpload(int BlockType, int BlockNum, void *pUsrData, int *Size)
- {
- return Cli_AsFullUpload(Client, BlockType, BlockNum, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsDownload(int BlockNum, void *pUsrData, int Size)
- {
- return Cli_AsDownload(Client, BlockNum, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsCopyRamToRom(int Timeout)
- {
- return Cli_AsCopyRamToRom(Client, Timeout);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsCompress(int Timeout)
- {
- return Cli_AsCompress(Client, Timeout);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsDBRead(int DBNumber, int Start, int Size, void *pUsrData)
- {
- return Cli_AsDBRead(Client, DBNumber, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsDBWrite(int DBNumber, int Start, int Size, void *pUsrData)
- {
- return Cli_AsDBWrite(Client, DBNumber, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsMBRead(int Start, int Size, void *pUsrData)
- {
- return Cli_AsMBRead(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsMBWrite(int Start, int Size, void *pUsrData)
- {
- return Cli_AsMBWrite(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsEBRead(int Start, int Size, void *pUsrData)
- {
- return Cli_AsEBRead(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsEBWrite(int Start, int Size, void *pUsrData)
- {
- return Cli_AsEBWrite(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsABRead(int Start, int Size, void *pUsrData)
- {
- return Cli_AsABRead(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsABWrite(int Start, int Size, void *pUsrData)
- {
- return Cli_AsABWrite(Client, Start, Size, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsTMRead(int Start, int Amount, void *pUsrData)
- {
- return Cli_AsTMRead(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsTMWrite(int Start, int Amount, void *pUsrData)
- {
- return Cli_AsTMWrite(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsCTRead(int Start, int Amount, void *pUsrData)
- {
- return Cli_AsCTRead(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsCTWrite(int Start, int Amount, void *pUsrData)
- {
- return Cli_AsCTWrite(Client, Start, Amount, pUsrData);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsDBGet(int DBNumber, void *pUsrData, int *Size)
- {
- return Cli_AsDBGet(Client, DBNumber, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Client::AsDBFill(int DBNumber, int FillChar)
- {
- return Cli_AsDBFill(Client, DBNumber, FillChar);
- }
- //==============================================================================
- // SERVER
- //==============================================================================
- TS7Server::TS7Server()
- {
- Server=Srv_Create();
- }
- //---------------------------------------------------------------------------
- TS7Server::~TS7Server()
- {
- Srv_Destroy(&Server);
- }
- //---------------------------------------------------------------------------
- int TS7Server::Start()
- {
- return Srv_Start(Server);
- }
- //---------------------------------------------------------------------------
- int TS7Server::StartTo(const char *Address)
- {
- return Srv_StartTo(Server, Address);
- }
- //---------------------------------------------------------------------------
- int TS7Server::Stop()
- {
- return Srv_Stop(Server);
- }
- //---------------------------------------------------------------------------
- int TS7Server::GetParam(int ParamNumber, void *pValue)
- {
- return Srv_GetParam(Server, ParamNumber, pValue);
- }
- //---------------------------------------------------------------------------
- int TS7Server::SetParam(int ParamNumber, void *pValue)
- {
- return Srv_SetParam(Server, ParamNumber, pValue);
- }
- //---------------------------------------------------------------------------
- int TS7Server::SetEventsCallback(pfn_SrvCallBack PCallBack, void *UsrPtr)
- {
- return Srv_SetEventsCallback(Server, PCallBack, UsrPtr);
- }
- //---------------------------------------------------------------------------
- int TS7Server::SetReadEventsCallback(pfn_SrvCallBack PCallBack, void *UsrPtr)
- {
- return Srv_SetReadEventsCallback(Server, PCallBack, UsrPtr);
- }
- //---------------------------------------------------------------------------
- int TS7Server::SetRWAreaCallback(pfn_RWAreaCallBack PCallBack, void *UsrPtr)
- {
- return Srv_SetRWAreaCallback(Server, PCallBack, UsrPtr);
- }
- //---------------------------------------------------------------------------
- bool TS7Server::PickEvent(TSrvEvent *pEvent)
- {
- int EvtReady;
- if (Srv_PickEvent(Server, pEvent, &EvtReady)==0)
- return EvtReady!=0;
- else
- return false;
- }
- //---------------------------------------------------------------------------
- void TS7Server::ClearEvents()
- {
- Srv_ClearEvents(Server);
- }
- //---------------------------------------------------------------------------
- longword TS7Server::GetEventsMask()
- {
- longword Mask;
- int Result = Srv_GetMask(Server, mkEvent, &Mask);
- if (Result==0)
- return Mask;
- else
- return 0;
- }
- //---------------------------------------------------------------------------
- longword TS7Server::GetLogMask()
- {
- longword Mask;
- int Result = Srv_GetMask(Server, mkLog, &Mask);
- if (Result==0)
- return Mask;
- else
- return 0;
- }
- //---------------------------------------------------------------------------
- void TS7Server::SetEventsMask(longword Mask)
- {
- Srv_SetMask(Server, mkEvent, Mask);
- }
- //---------------------------------------------------------------------------
- void TS7Server::SetLogMask(longword Mask)
- {
- Srv_SetMask(Server, mkLog, Mask);
- }
- //---------------------------------------------------------------------------
- int TS7Server::RegisterArea(int AreaCode, word Index, void *pUsrData, word Size)
- {
- return Srv_RegisterArea(Server, AreaCode, Index, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Server::UnregisterArea(int AreaCode, word Index)
- {
- return Srv_UnregisterArea(Server, AreaCode, Index);
- }
- //---------------------------------------------------------------------------
- int TS7Server::LockArea(int AreaCode, word Index)
- {
- return Srv_LockArea(Server, AreaCode, Index);
- }
- //---------------------------------------------------------------------------
- int TS7Server::UnlockArea(int AreaCode, word Index)
- {
- return Srv_UnlockArea(Server, AreaCode, Index);
- }
- //---------------------------------------------------------------------------
- int TS7Server::ServerStatus()
- {
- int ServerStatus, CpuStatus, ClientsCount;
- int Result =Srv_GetStatus(Server, &ServerStatus, &CpuStatus, &ClientsCount);
- if (Result==0)
- return ServerStatus;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Server::GetCpuStatus()
- {
- int ServerStatus, CpuStatus, ClientsCount;
- int Result =Srv_GetStatus(Server, &ServerStatus, &CpuStatus, &ClientsCount);
- if (Result==0)
- return CpuStatus;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Server::ClientsCount()
- {
- int ServerStatus, CpuStatus, ClientsCount;
- int Result =Srv_GetStatus(Server, &ServerStatus, &CpuStatus, &ClientsCount);
- if (Result==0)
- return ClientsCount;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Server::SetCpuStatus(int Status)
- {
- return Srv_SetCpuStatus(Server, Status);
- }
- //==============================================================================
- // PARTNER
- //==============================================================================
- TS7Partner::TS7Partner(bool Active)
- {
- Partner=Par_Create(int(Active));
- }
- //---------------------------------------------------------------------------
- TS7Partner::~TS7Partner()
- {
- Par_Destroy(&Partner);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::GetParam(int ParamNumber, void *pValue)
- {
- return Par_GetParam(Partner, ParamNumber, pValue);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::SetParam(int ParamNumber, void *pValue)
- {
- return Par_SetParam(Partner, ParamNumber, pValue);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::Start()
- {
- return Par_Start(Partner);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::StartTo(const char *LocalAddress, const char *RemoteAddress, int LocalTSAP, int RemoteTSAP)
- {
- return Par_StartTo(Partner, LocalAddress, RemoteAddress, LocalTSAP, RemoteTSAP);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::Stop()
- {
- return Par_Stop(Partner);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::BSend(longword R_ID, void *pUsrData, int Size)
- {
- return Par_BSend(Partner, R_ID, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::AsBSend(longword R_ID, void *pUsrData, int Size)
- {
- return Par_AsBSend(Partner, R_ID, pUsrData, Size);
- }
- //---------------------------------------------------------------------------
- bool TS7Partner::CheckAsBSendCompletion(int *opResult)
- {
- return Par_CheckAsBSendCompletion(Partner ,opResult)==JobComplete;
- }
- //---------------------------------------------------------------------------
- int TS7Partner::WaitAsBSendCompletion(longword Timeout)
- {
- return Par_WaitAsBSendCompletion(Partner, Timeout);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::SetSendCallback(pfn_ParSendCompletion pCompletion, void *usrPtr)
- {
- return Par_SetSendCallback(Partner, pCompletion, usrPtr);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::BRecv(longword *R_ID, void *pUsrData, int *Size, longword Timeout)
- {
- return Par_BRecv(Partner, R_ID, pUsrData, Size, Timeout);
- }
- //---------------------------------------------------------------------------
- bool TS7Partner::CheckAsBRecvCompletion(int *opResult, longword *R_ID, void *pUsrData, int *Size)
- {
- return Par_CheckAsBRecvCompletion(Partner, opResult, R_ID, pUsrData, Size) == JobComplete;
- }
- //---------------------------------------------------------------------------
- int TS7Partner::SetRecvCallback(pfn_ParRecvCallBack pCallback, void *usrPtr)
- {
- return Par_SetRecvCallback(Partner, pCallback, usrPtr);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::Status()
- {
- int ParStatus;
- int Result = Par_GetStatus(Partner, &ParStatus);
- if (Result==0)
- return ParStatus;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Partner::LastError()
- {
- int Error;
- int Result = Par_GetLastError(Partner, &Error);
- if (Result==0)
- return Error;
- else
- return Result;
- }
- //---------------------------------------------------------------------------
- int TS7Partner::GetTimes(longword *SendTime, longword *RecvTime)
- {
- return Par_GetTimes(Partner, SendTime, RecvTime);
- }
- //---------------------------------------------------------------------------
- int TS7Partner::GetStats(longword *BytesSent, longword *BytesRecv, longword *ErrSend, longword *ErrRecv)
- {
- return Par_GetStats(Partner, BytesSent, BytesRecv, ErrSend, ErrRecv);
- }
- //---------------------------------------------------------------------------
- bool TS7Partner::Linked()
- {
- return Status()==par_linked;
- }
- //==============================================================================
- // Text routines
- //==============================================================================
- TextString CliErrorText(int Error)
- {
- char text[TextLen];
- Cli_ErrorText(Error, text, TextLen);
- return TextString(text);
- }
- //---------------------------------------------------------------------------
- TextString SrvErrorText(int Error)
- {
- char text[TextLen];
- Srv_ErrorText(Error, text, TextLen);
- return TextString(text);
- }
- //---------------------------------------------------------------------------
- TextString ParErrorText(int Error)
- {
- char text[TextLen];
- Par_ErrorText(Error, text, TextLen);
- return TextString(text);
- }
- //---------------------------------------------------------------------------
- TextString SrvEventText(TSrvEvent *Event)
- {
- char text[TextLen];
- Srv_EventText(Event, text, TextLen);
- return TextString(text);
- }
|