Results 1 to 8 of 8

Thread: serial port same local machine

  1. #1
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default serial port same local machine

    Hello.

    I am using the qextserialPort and I have some doubts about how programmer the send and the receive data.

    I followed some thread in the forum but I couldnt find how programmer to receive and send data by the same port in the same local machine.

    I think that the port have to be configured and opened only once is this correct? And if I configure the port in a program and then i want to wait data from another program to read it, can i do it with a simple while datas availables?

    I did this but when a run both programs in the same PC is not working. I write the code because maybe you can understand me better seeing it.

    This is the read function in the program that what to read datas, and the port it was configured and open it before this code:

    QString ManejadorRS232::read()
    {

    char buff[1024];
    int numBytes;
    QString mensaje ;

    numBytes = port->bytesAvailable();

    while(numBytes<=0)
    numBytes = port->bytesAvailable();
    if(numBytes > 0)
    {
    if(numBytes > 1024) numBytes = 1024;

    int i = port->read(buff, numBytes);
    buff[i] = '\0';
    mensaje = buff;


    }
    return mensaje;
    }


    This is the code to write in the other programm which is not configured and opened the port becuase is the same port( the COM1):

    void ManejadorRS232::write(QString mensaje)
    {
    int i = port->write(mensaje.toAscii(),
    mensaje.length());

    }


    Could someone help me?.

    Thank you

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial port same local machine

    COM ports don't have any automagic. If You want write some data to COM port and read this same data from this same port You must use loopback connector on this port ie. like this.

  3. The following user says thank you to Lesiok for this useful post:

    adamatic (2nd February 2009)

  4. #3
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: serial port same local machine

    Yes, of course I did the loopback but i dont know if i have to configure and open the COM1 port in both programmes. I have tried both things but if it is opened in one program and then i configure the same port in another program to send datas to the other is telling that the port is close althoug i didnt close it.

    I dont know well which is the process.

  5. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial port same local machine

    Of course You must open COM port in both programs in shared mode. Another solution is to use some application creating virtual ports makes connections betwen them. Than You can use in one program ie. COM5 and in second COM6.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: serial port same local machine

    I'm sorry but what is the point of connecting two applications running on the same machine using the same serial port?

  7. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: serial port same local machine

    For testing if You have only one computer ?

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: serial port same local machine

    Doesn't the test itself influence the tested application? I think this is exactly what is happening here I think it's better to simply emulate the port (or even the whole connection, if you're testing the application logic only) or use a second port or take an old computer and test against it. Especially that you won't be able to test many things using such a loopback connection anyway...

  9. The following user says thank you to wysota for this useful post:

    adamatic (3rd February 2009)

  10. #8
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: serial port same local machine

    Hello.

    First thank you for your answers.

    Yes, I wanted to use the same port to test an applicatio,n sending and receiving datas using qextserialport. i was trying this mode because I though that could be the better and easier solution, but I think the programs are blocking the port. So I am going to try to use the virtual ports

    Regards.

Similar Threads

  1. serial port programming
    By sujatashooter in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2008, 15:51
  2. accessing serial port without CONFIG += console
    By bnilsson in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2008, 21:47
  3. forcing local port number from TcpSocket?
    By nbkhwjm in forum Newbie
    Replies: 6
    Last Post: 8th January 2008, 18:28
  4. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.