Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Wanted to connect to PLC through ethernet but its not getting connected giving error device not open

Wanted to connect to PLC through ethernet but its not getting connected giving error device not open

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 3 Posters 817 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mganesh
    wrote on last edited by
    #1

    Re: Qt gui C++ to read other controllers memory location through ethernet tcp/ip address
    Wanted to connect to PLC through ethernet in Qt but its not getting connected giving error device not open.
    but when connected through other means like using hercules the plc gets connected.

    giving error :
    QIODevice::write (QTcpSocket): device not open

    program:

    ***clientnetworksocket=new QTcpSocket(this);
    clientnetworksocket->connectToHost(QHostAddress("192.168.5.239"),5102,QIODevice::ReadWrite);
    if (clientnetworksocket->waitForConnected(2000))
    {
    ui->label_status->setText("Connected to Server");

     }
     else
     {
         ui->label_status->setText("Server Offline");
       clientnetworksocket->disconnectFromHost();
       clientnetworksocket->close();
     }
    
    
     connect(timer, SIGNAL(timeout()), this, SLOT(monitorLoop()));
     timer->start(500);
    
     connect(clientnetworksocket,SIGNAL(readyRead()),this, SLOT(serialDataReceived()));
    

    connect(clientnetworksocket,SIGNAL(disconnected()),this,SLOT(lineStatus()));***

    jsulmJ KroMignonK 2 Replies Last reply
    0
    • M mganesh

      Re: Qt gui C++ to read other controllers memory location through ethernet tcp/ip address
      Wanted to connect to PLC through ethernet in Qt but its not getting connected giving error device not open.
      but when connected through other means like using hercules the plc gets connected.

      giving error :
      QIODevice::write (QTcpSocket): device not open

      program:

      ***clientnetworksocket=new QTcpSocket(this);
      clientnetworksocket->connectToHost(QHostAddress("192.168.5.239"),5102,QIODevice::ReadWrite);
      if (clientnetworksocket->waitForConnected(2000))
      {
      ui->label_status->setText("Connected to Server");

       }
       else
       {
           ui->label_status->setText("Server Offline");
         clientnetworksocket->disconnectFromHost();
         clientnetworksocket->close();
       }
      
      
       connect(timer, SIGNAL(timeout()), this, SLOT(monitorLoop()));
       timer->start(500);
      
       connect(clientnetworksocket,SIGNAL(readyRead()),this, SLOT(serialDataReceived()));
      

      connect(clientnetworksocket,SIGNAL(disconnected()),this,SLOT(lineStatus()));***

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mganesh said in Wanted to connect to PLC through ethernet but its not getting connected giving error device not open:

      clientnetworksocket->disconnectFromHost();

      There is no need to disconnect if socket was not connected

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mganesh
        wrote on last edited by
        #3

        removed whats next then also giving same error.

        1 Reply Last reply
        0
        • M mganesh

          Re: Qt gui C++ to read other controllers memory location through ethernet tcp/ip address
          Wanted to connect to PLC through ethernet in Qt but its not getting connected giving error device not open.
          but when connected through other means like using hercules the plc gets connected.

          giving error :
          QIODevice::write (QTcpSocket): device not open

          program:

          ***clientnetworksocket=new QTcpSocket(this);
          clientnetworksocket->connectToHost(QHostAddress("192.168.5.239"),5102,QIODevice::ReadWrite);
          if (clientnetworksocket->waitForConnected(2000))
          {
          ui->label_status->setText("Connected to Server");

           }
           else
           {
               ui->label_status->setText("Server Offline");
             clientnetworksocket->disconnectFromHost();
             clientnetworksocket->close();
           }
          
          
           connect(timer, SIGNAL(timeout()), this, SLOT(monitorLoop()));
           timer->start(500);
          
           connect(clientnetworksocket,SIGNAL(readyRead()),this, SLOT(serialDataReceived()));
          

          connect(clientnetworksocket,SIGNAL(disconnected()),this,SLOT(lineStatus()));***

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @mganesh said in Wanted to connect to PLC through ethernet but its not getting connected giving error device not open:

          QIODevice::write (QTcpSocket): device not open

          Where do you got this error?
          On you code extract, there is not write.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mganesh
            wrote on last edited by
            #5

            part of program:

            ***QByteArray data_to_transmit = QByteArray::fromHex(networkmonitorCommand);

                qDebug()<<networkmonitorCommand;
            
                    clientnetworksocket->write(data_to_transmit);
                     clientnetworksocket->flush();***
            
            jsulmJ 1 Reply Last reply
            0
            • M mganesh

              part of program:

              ***QByteArray data_to_transmit = QByteArray::fromHex(networkmonitorCommand);

                  qDebug()<<networkmonitorCommand;
              
                      clientnetworksocket->write(data_to_transmit);
                       clientnetworksocket->flush();***
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @mganesh So, did the connection succeed?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mganesh
                wrote on last edited by
                #7

                no ..plz help to to connect to PLC

                jsulmJ 1 Reply Last reply
                0
                • M mganesh

                  no ..plz help to to connect to PLC

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @mganesh Is the IP correct? Is the port correct? Did you try to disable the firewall?
                  Also, you know that QTcpSocket provides functionality to get information about occurred errors? Why don't you use it?
                  So please check what https://doc.qt.io/qt-5/qabstractsocket.html#error and https://doc.qt.io/qt-5/qiodevice.html#errorString tell you after connection timeout...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved