Exemplo n.º 1
0
void readByNameExample(std::ostream& out, long port, const AmsAddr& server)
{
    static const char handleName[] = "MAIN.byByte[4]";
    uint32_t bytesRead;

    out << __FUNCTION__ << "():\n";
    const uint32_t handle = getHandleByNameExample(out, port, server, handleName);
    const uint32_t bufferSize = getSymbolSize(out, port, server, handleName);
    const auto buffer = std::unique_ptr<uint8_t>(new uint8_t[bufferSize]);
    for (size_t i = 0; i < 8; ++i) {
        const long status = AdsSyncReadReqEx2(port,
                                              &server,
                                              ADSIGRP_SYM_VALBYHND,
                                              handle,
                                              bufferSize,
                                              buffer.get(),
                                              &bytesRead);
        if (status) {
            out << "ADS read failed with: " << std::dec << status << '\n';
            return;
        }
        out << "ADS read " << std::dec << bytesRead << " bytes:" << std::hex;
        for (size_t i = 0; i < bytesRead; ++i) {
            out << ' ' << (int)buffer.get()[i];
        }
        out << '\n';
    }
    releaseHandleExample(out, port, server, handle);
}
Exemplo n.º 2
0
Arquivo: AdsAPI.c Projeto: gass/libads
/**
 * @brief A frontend to AdsSyncReadReqEx2() with port = defaultPort and pnRead = NULL
 */
int32_t AdsSyncReadReq(PAmsAddr pAddr,
                    uint32_t nIndexGroup,
                    uint32_t nIndexOffset,
                    uint32_t nLength, void *pData)
{
	return AdsSyncReadReqEx2(defaultPort, pAddr,
							 nIndexGroup, nIndexOffset,
							 nLength, pData,
							 NULL);
}
Exemplo n.º 3
0
void readExample(std::ostream& out, long port, const AmsAddr& server)
{
    uint32_t bytesRead;
    uint32_t buffer;

    out << __FUNCTION__ << "():\n";
    for (size_t i = 0; i < 8; ++i) {
        const long status = AdsSyncReadReqEx2(port, &server, 0x4020, 0, sizeof(buffer), &buffer, &bytesRead);
        if (status) {
            out << "ADS read failed with: " << std::dec << status << '\n';
            return;
        }
        out << "ADS read " << std::dec << bytesRead << " bytes, value: 0x" << std::hex << buffer << '\n';
    }
}