Wanted to connect to PLC through ethernet but its not getting connected giving error device not open
-
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 openprogram:
***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()));***
-
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 openprogram:
***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()));***
@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
-
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 openprogram:
***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()));***
-
part of program:
***QByteArray data_to_transmit = QByteArray::fromHex(networkmonitorCommand);
qDebug()<<networkmonitorCommand; clientnetworksocket->write(data_to_transmit); clientnetworksocket->flush();*** -
@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...