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

Multiple sessions #24

Open
JoeyR opened this issue Dec 23, 2020 · 1 comment
Open

Multiple sessions #24

JoeyR opened this issue Dec 23, 2020 · 1 comment

Comments

@JoeyR
Copy link

JoeyR commented Dec 23, 2020

I have a handful of devices that I need to connect to for explicit messages. Is there currently a way to do this besides putting each device on it's own subnet? (#8)

@JoeyR
Copy link
Author

JoeyR commented Dec 23, 2020

I figured it out!

  1. Comment out the bind here: https://github.com/ros-drivers/odva_ethernetip/blob/indigo-devel/include/odva_ethernetip/socket/udp_socket.h#L63
  2. Then create new sockets for each session.

The question I have is: what are the implications of not binding the socket?

#include <iostream>

#include "odva_ethernetip/input_assembly.h"
#include "odva_ethernetip/io_scanner.h"
#include "odva_ethernetip/output_assembly.h"
#include "odva_ethernetip/session.h"
#include "odva_ethernetip/socket/tcp_socket.h"
#include "odva_ethernetip/socket/udp_socket.h"

int main(int args, char** argv) {
  using eip::socket::TCPSocket;
  using eip::socket::UDPSocket;

  boost::asio::io_service boost_io = {};

  boost::asio::io_service io_service;
  boost::shared_ptr<TCPSocket> socket = shared_ptr<TCPSocket>(new TCPSocket(io_service));
  boost::shared_ptr<UDPSocket> io_socket = shared_ptr<UDPSocket>(new UDPSocket(io_service, 2222));
  eip::Session s(socket, io_socket);

  boost::shared_ptr<TCPSocket> socket1 = shared_ptr<TCPSocket>(new TCPSocket(io_service));
  boost::shared_ptr<UDPSocket> io_socket1 = shared_ptr<UDPSocket>(new UDPSocket(io_service, 2222));
  eip::Session s1(socket1, io_socket1);

  try {
    s.open(argv[1]);
    s1.open(argv[2]);

    InputAssembly ia;
    s.getSingleAttributeSerializable(0x04, 107, 3, ia);

    std::cout << "Input Assembly: " << std::endl;
    std::cout << ia.sensor_and_control_port_inputs << std::endl;
    std::cout << ia.sensor_detect << std::endl;

    s1.getSingleAttributeSerializable(0x04, 107, 3, ia);

    std::cout << "Input Assembly: " << std::endl;
    std::cout << ia.sensor_and_control_port_inputs << std::endl;
    std::cout << ia.sensor_detect << std::endl;

  } catch (const std::exception& e) {
    std::cerr << "Error: " << e.what() << std::endl;
  }

  s.close();
  s1.close();

  return 0;
}

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