Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Ads funktioiden avulla voi toteuttaa kättetelyn kättelyn c++ ohjelman ja Beckhoffin logikan logiikan välillä.

Yksinkertainen esimerkki

...

Code Block
titleprojektitiedostoon kirjaston polku
collapsetrue
LIBS += "c://twincat//AdsApi//tcadsdll//lib//TcAdsDll.lib"

...

Code Block
titleotsikkotiedosto
collapsetrue
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include "WinTypes.h"
#include "c:\twincat\AdsApi\tcadsdll\include\tcadsdef.h"
#include "c:\twincat\AdsApi\tcadsdll\include\tcadsapi.h"

namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
    Q_OBJECT
public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();
    long     nErr, nPort;
    AmsAddr  Addr;
    PAmsAddr pAddr;
    DWORD    dwData;
    ULONG hAnalogInputs;
    ULONG hAnalogOutputs;
    void WriteDataToLogic(qint32 *asetusarvot, quint8 kokoTavuina);
    void ReadDataFromLogic(qint32 *mitatutArvot, quint32 kokoTavuina);
private:
    Ui::Dialog *ui;
};
#endif // DIALOG_H
Code Block
titleluokan funktiot
collapsetrue
#include "dialog.h"
#include "ui_dialog.h"


Dialog::Dialog(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog)
{
    ui->setupUi(this);
    pAddr = &Addr;
    nPort = AdsPortOpen();
    nErr = AdsGetLocalAddress(pAddr);
    pAddr->port =851;
    //5.11.25.80.1.1 netid on logiikan identiteetti (jokaisella oma)
    pAddr->netId.b[0]=5;
    pAddr->netId.b[1]=11;
    pAddr->netId.b[2]=25;
    pAddr->netId.b[3]=80;
    pAddr->netId.b[4]=1;
    pAddr->netId.b[5]=1;
    nErr=AdsSyncReadWriteReq( pAddr, ADSIGRP_SYM_HNDBYNAME, 0x0, 
                              sizeof(ULONG), &hAnalogInputs,
                              sizeof("MAIN.communication.AnalogInputsToPc_"),
                              "MAIN.communication.AnalogInputsToPc_");
...

}


Dialog::~Dialog()
{
    delete ui;
}

void Dialog::WriteDataToLogic(qint32 *asetusarvot, quint8 kokoTavuina)
{
    nErr=AdsSyncWriteReq( pAddr, ADSIGRP_SYM_VALBYHND, hAnalogOutputs,kokoTavuina,asetusarvot);
    Q_ASSERT(nErr==0);
}

void Dialog::ReadDataFromLogic(qint32 *mitatutArvot, quint32 kokoTavuina)
{
    nErr=AdsSyncReadReq( pAddr, ADSIGRP_SYM_VALBYHND,hAnalogInputs, lengthOfVectorAsBytes,mitatutArvot);
    Q_ASSERT(nErr==0);
}

 

Esimerkkejä

ADS-DLL Sample01.zip

...