PDA

View Full Version : serial port same local machine



adamatic
2nd February 2009, 08:36
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

Lesiok
2nd February 2009, 08:53
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 (http://www.aggsoft.com/rs232-pinout-cable/serial-port-loopback-db9-c.htm).

adamatic
2nd February 2009, 12:36
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.

Lesiok
2nd February 2009, 14:40
Of course You must open COM port in both programs in shared mode. Another solution is to use some application creating virtual ports (http://com0com.sourceforge.net/) makes connections betwen them. Than You can use in one program ie. COM5 and in second COM6.

wysota
2nd February 2009, 15:17
I'm sorry but what is the point of connecting two applications running on the same machine using the same serial port?

Lesiok
2nd February 2009, 16:26
For testing if You have only one computer ?

wysota
3rd February 2009, 00:29
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...

adamatic
3rd February 2009, 07:29
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.