ADS C++ DLL auslesen verschiedener Variablentypen ?

ScooB

Level-1
Beiträge
8
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo,
ich habe da ne Frage

ich bin mal die verschiedenen Beispiele von Beckhoff druchgegangen
http://infosys.beckhoff.com/index.p.../tcadsdll_api_delphi_sample01_08.htm&id=11753
Nur steh ich jetzt vor einem Problem
In den Beispielen zum auslesen einer Variable ist die Variable immer DWORD, jetzt möchte ich allerdings eine INT Variable auslesen was allerdings nicht klappt

Hat hier jemand vieleicht ein Beispiel für mich oder Infos wie man es lösen kann

Gruß
ScooB
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Also ich bekomm schon nen Wert zurück allerdings wenn der Wert z.B. 790 ist dann bekomm ich 3435922198 zurück

Code:
  long      nErr, nPort; 
  AmsAddr   Addr; 
  PAmsAddr  pAddr = &Addr; 
  ULONG     lHdlVar, nData; 
  char      szVar []={"MAIN.PLCVar2"}; 

  // Open communication port on the ADS router
  nPort = AdsPortOpen();
  nErr = AdsGetLocalAddress(pAddr);
  if (nErr) cerr << "Error: AdsGetLocalAddress: " << nErr << '\n';
  pAddr->port = AMSPORT_R0_PLC_RTS1;

  // Get the handle of the PLC-variable <szVar> 
  nErr = AdsSyncReadWriteReq(pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, sizeof(lHdlVar), &lHdlVar, sizeof(szVar), szVar);
  if (nErr) cerr << "Error: AdsSyncReadWriteReq: " << nErr << '\n';

  

    // Read the value of a PLC-variable, via handle 
    nErr = AdsSyncReadReq( pAddr, ADSIGRP_SYM_VALBYHND, lHdlVar, sizeof(nData), &nData ); 
    if (nErr) 
        cerr << "Error: AdsSyncReadReq: " << nErr << '\n'; 
    else 
        cout << "Value: " << nData << '\n'; 
    cout.flush();

    

  //Release the handle of the PLC-variable
  nErr = AdsSyncWriteReq(pAddr, ADSIGRP_SYM_RELEASEHND, 0, sizeof(lHdlVar), &lHdlVar); 
  if (nErr) cerr << "Error: AdsSyncWriteReq: " << nErr << '\n';

  // Close the communication port
  nErr = AdsPortClose(); 
  if (nErr) cerr << "Error: AdsPortClose: " << nErr << '\n';

das ist der Code den ich verwende

Gruß
 
Und der Typ ist IEC_INT? Das sind doch nur 2 Byte, Du liest wahrscheinlich 4 -> sizeof(nData)!? Da gibts aber bestimmt im RETURN_CODE eine ParaSizeError...
 
Hallo,
ich würde sagen du liest den Wert , du musst in nur am PC noch richtig auswerten....

die "CCCC" könnten vom Compiler stammen (Debug-Version ?) oder einfach irgendwelche nicht definierten Datenbytes (4 Byte, 2 Byte)

bg
bb

Code:
3435922198 ==> CCCC0316 bei Umwandlung dez --> hex
316        ==>      790 bei Umwandlung hex --> dez
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Danke für den Tipp is klar hab hab da was verwechstelt.
Ich hab es immer mit int versucht, aber int in C++ ist ja 4 Byte groß.

Habs jetzt Danke nochmal

Gruß
 
Zurück
Oben