Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing IP from terminal #219

Open
amirtronix opened this issue Dec 1, 2023 · 0 comments
Open

Passing IP from terminal #219

amirtronix opened this issue Dec 1, 2023 · 0 comments

Comments

@amirtronix
Copy link

amirtronix commented Dec 1, 2023

Let's say we want to pass the PLC IP from terminal to C++ code. Consider this code:

#include <ros/ros.h>
#include <rospack#include <std_msgs/String.h>
#include <AdsLib/AdsLib.h>
#include "AdsLib/AdsNotificationOOI.h"
#include "AdsLib/AdsVariable.h"

#include <array>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <unistd.h>


class BeckhoffClass
{


public:

    cv_bridge::CvImagePtr cvImageSubscribePtr;

    int imgWidth, imgHeight;
    int imgPixels;
    int rosRate;

    std::string plcNetId, plcIp, localNetId;
    
    AdsDevice* route = nullptr;
    bool AdsConenction = false;

    BeckhoffClass()
        : private_nh("~"),
          it_(nh_)
    {
        // 
    }

    ~BeckhoffClass()
    {

    }

    void connectTwinCatAds()
    {
        try 
        {

            static const AmsNetId remoteNetId { 169, 254, 94, 16, 1, 1};
            static const char remoteIpV4[] = "10.2.2.157";
            AdsSetLocalAddress({10, 2, 2, 128, 1, 1});

            route = new AdsDevice(remoteIpV4, remoteNetId, AMSPORT_R0_PLC_TC3);
            AdsConenction = true;
            std::cout << "Asd connected! \n";
        }
        catch (const AdsException& ex) 
        {
            std::cout << "Error: " << ex.errorCode << "\n";
            std::cout << "AdsException message: " << ex.what() << "\n";
        } 
        catch (const std::runtime_error& ex) 
        {
            std::cout << ex.what() << '\n';
        }
    }

};


int main(int argc, char** argv)
{

    std::string plcIp = arv[1];

    BeckhoffClass beckhoff_class(plcIp);
    
    return 0;
}

How can I initialize ADS struct inside Beckhoff class constructor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant