bool MainWindow::EnableTransfer() // вызывается из конструктора MainWindow{ if( ! ipusing ) { qDebug( "Opening parallel port transfer... " ); h = CreateFileA( "\\\\.\\UserPort", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( h == INVALID_HANDLE_VALUE ) { qDebug ("Error: could not get parallel port access.\n"); return false; } } else { bool converted = false; unsigned int port = a->arguments().at(2).toUInt( &converted ); // QCoreApplication* a if( ! converted ) { qDebug ("Error: invalid port number.\n"); return false; } qDebug( "Opening TCP/IP transfer... (to use paraller port add LPT after program name) " ); if( ( socket = new QAbstractSocket( QAbstractSocket::TcpSocket, a ) ) == 0 ) { qDebug ("Error: could not create connection.\n"); return false; } socket->connectToHost( a->arguments().at(1), port ); if( ! socket->waitForConnected( PortTimeOut ) ) { qDebug ("Error: Connection timeout.\n"); return false; } } qDebug( "Running normal\n" ); return true;}
void MainWindow::outport( BYTE data ){ if( ipusing ) { if( ! socket->putChar( data ) ) { qDebug( "Error: Network write error.\n" ); a->exit( -1 ); } socket->flush(); } else // LPT { __asm ( "outb %%al, %%dx;" : // нет ничего : "d" (lpt_addr), "a" (data) // AX:данные, DX:адрес ); }}BYTE MainWindow::inport(){ if( ipusing ) { char data; if( ! socket->getChar( &data ) ) { qDebug( "Error: Network read error.\n" ); a->exit( -1 ); return -1; } return data; } // else LPT __asm ( "inb %%dx, %%al;" : // возврат в AX : "d" (lpt_addr+1) // DX:адрес AX:данные ); // return уже на месте}
//#define QTCPSOCKET_DEBUG/*!\class QTcpSocket\brief The QTcpSocket class provides a TCP socket.\reentrant\ingroup io\inmodule QtNetworkTCP (Transmission Control Protocol) is a reliable,stream-oriented, connection-oriented transport protocol. It isespecially well suited for continuous transmission of data.QTcpSocket is a convenience subclass of QAbstractSocket thatallows you to establish a TCP connection and transfer streams ofdata. See the QAbstractSocket documentation for details.\bold{Note:} TCP sockets cannot be opened in QIODevice::Unbuffered mode.\sa QTcpServer, QUdpSocket, QFtp, QNetworkAccessManager,{Fortune Server Example}, {Fortune Client Example},{Threaded Fortune Server Example}, {Blocking Fortune Client Example},{Loopback Example}, {Torrent Example}*/#include "qlist.h"#include "qtcpsocket_p.h"#include "qtcpsocket.h"#include "qhostaddress.h"QT_BEGIN_NAMESPACE/*!Creates a QTcpSocket object in state \c UnconnectedState.\a parent is passed on to the QObject constructor.\sa socketType()*/QTcpSocket::QTcpSocket(QObject *parent): QAbstractSocket(TcpSocket, *new QTcpSocketPrivate, parent){#if defined(QTCPSOCKET_DEBUG)qDebug("QTcpSocket::QTcpSocket()");#endifd_func()->isBuffered = true;}/*!Destroys the socket, closing the connection if necessary.\sa close()*/QTcpSocket::~QTcpSocket(){#if defined(QTCPSOCKET_DEBUG)qDebug("QTcpSocket::~QTcpSocket()");#endif}/*!\internal*/QTcpSocket::QTcpSocket(QTcpSocketPrivate &dd, QObject *parent): QAbstractSocket(TcpSocket, dd, parent){d_func()->isBuffered = true;}QT_END_NAMESPACE
if( ! socket->isValid() ) { qDebug ("Error: Socket is not valid.\n"); return false; } if( ! socket->isOpen() ) // MUST be opened before { if( ! socket->open( QIODevice::ReadWrite ) ) { qDebug ("Error: Socket is not open.\n"); return false; } }