Delta PLC TCP communication

Hello all,
New to this forum. I have been working in the Delta PLC(AS228T-A) model, i want to establish a communication between the PLC and the PC using TCP. There is an example plc ladder program of PLC acting as a client and the PC acting as a server. But i want the PLC acts as a server and the PC acts as a client, So i can receive datas from the PLC to the PC and use it for my work. To use the PLC as a server, the instruction manual mentioned the S3 operand has to be set as 0 or 2, and it has the example program, which i am not sure thats the correct one or not. Configured the parameter setting as it is mentioned and Tried that also. Still i am having this "connection refused" output from the cpp file using "asio" library to establish the communication with the help of this site(see the client program). I even tried the libmodbus library in the client program. I attached the image below for the reference.
I would be so glad if someone helps me to overcome this.
 

Attachments

I figured out with the help of some more deep dive research, on how to act the PLC act as a server(slave) and the PC act as a client(master). I attached below images on how the parameter settings should be, the ladder diagram, and the cpp client program.

parameter_configuration.png

The ladder logic program

tcp_plc_to_pc_data_read_write_ladder_logic_program.png

the cpp client program

Code:
#include <iostream>

#include <boost/asio.hpp>


using namespace boost::asio;

using ip::tcp;

using std::string;


int main() {

    try{

         boost::asio::io_service io_service;

         tcp::socket socket(io_service);

         socket.connect( tcp::endpoint( boost::asio::ip::address::from_string("10.10.0.2"), 2400 ));

         std::cout << "connected to the server." << std::endl;  


         const string msg = "Hi buddy!\n";

         boost::system::error_code error;

         boost::asio::write( socket, boost::asio::buffer(msg), error );

         if( !error ) {

            std::cout << "Client sent hello message!" << std::endl;

         }

         else {

            std::cout << "send failed: " << error.message() << std::endl;

         }


        boost::asio::streambuf receive_buffer;

        boost::asio::read(socket, receive_buffer, boost::asio::transfer_all(), error);

        if( error && error != boost::asio::error::eof ) {

            std::cout << "receive failed: " << error.message() << std::endl;

        }

        else {

            const char* data = boost::asio::buffer_cast<const char*>(receive_buffer.data());

            std::size_t received_size = receive_buffer.size();

            if (received_size >= 2) { // combines two bytes of data into a single 16-bit unsigned integer

                uint16_t received_word = static_cast<uint16_t>((data[0] << 8) | data[1]);

                std::cout << "Received Word: " << received_word << std::endl;

            } else {

                std::cout << "Cannot interpret as a word." << std::endl;

            }

        }

    }catch(std::exception& e){

        std::cerr << e.what() << std::endl;

    }


    return 0;

}
 
Top