Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can't write plc variable qt



  • char  szVar[] = {"MAIN.PLCVar"};
    AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar), &lHdlVar, sizeof(szVar), szVar);
        //AdsSyncReadReq( pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar, sizeof(nData), &nData );
        AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar, sizeof(nData), &nData);
        AdsSyncWriteReq(pAddr, ADSIGRP_SYM_RELEASEHND, 0, sizeof(lHdlVar), &lHdlVar);
    qDebug()<<nData;
    

    when i do that this works fine but i want to make a function that write plc variable in function then set value what i want.

    __declspec( dllexport )
    long __stdcall AdsSyncReadWriteReq( AmsAddr* pAddr,					// Ams address of ADS server
    							unsigned long indexGroup,			//	index group in ADS server interface
    							unsigned long indexOffset,			// index offset in ADS server interface
    							unsigned long cbReadLength,		// count of bytes to read
    							void* pReadData,						// pointer to the client buffer
    							unsigned long cbWriteLength, 		// count of bytes to write
    							void* pWriteData						// pointer to the client buffer
    							);
    

    this is function

    and when i want to do that this error is happening

    ads.cpp:35:5: error: no matching function for call to 'AdsSyncReadWriteReq'
    TcAdsAPI.h:67:16: note: candidate function not viable: no known conversion from 'char' to 'void *' for 7th argument; take the address of the argument with &
    
    void ADS::ChangeValue(char varName)
    {
        
        nData=80.1;
        AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar), &lHdlVar, sizeof(varName), varName);
        //AdsSyncReadReq( pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar, sizeof(nData), &nData );
        AdsSyncWriteReq(pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar, sizeof(nData), &nData);
        AdsSyncWriteReq(pAddr, ADSIGRP_SYM_RELEASEHND, 0, sizeof(lHdlVar), &lHdlVar);
        qDebug()<<nData;
    }
    

  • Lifetime Qt Champion

    And where's the relation to Qt? You call a simple C function but don't pass the correct type for the 7th argument. Fix it.



  • I know but may be you can help i tried and i cant


  • Lifetime Qt Champion

    @V0rtex What did you try to solve "no known conversion from 'char' to 'void *' for 7th argument"?



  • @jsulm yes i tried but i cant still. i didn't understand


  • Lifetime Qt Champion

    Hi,

    @V0rtex said in Can't write plc variable qt:

    @jsulm yes i tried but i cant still. i didn't understand

    The question was: can you please explain what you tried that did not work ?


Log in to reply