Hello,
I’m working with a friend on a project for my engineering school and we have some issues to communicate with ours xbees PRO s1.
With XCTU xbees work perfectly (full duplex OK)
But, for our project we have to developp a program in c++ to communicate between xbees. The problem is that we cannot receive any data with the software but we can send them with our program and receive thanks to XCTU.
The program uses the library SerialPort.h and Windows.h
Here the code to receive :
int SerialPort::readSerialPort(char *buffer, unsigned int buf_size)
{
DWORD bytesRead;
unsigned int toRead;
ClearCommError(_handler,&_errors, &_status);
if (_status.cbInQue > 0){
if (_status.cbInQue > buf_size){
toRead = buf_size;
}
else toRead = _status.cbInQue;
}
if (ReadFile(_handler, buffer, toRead, &bytesRead, NULL)) return bytesRead;
return 0;
}
and the main.cpp :
#include
#include
#include
#include
#include “SerialPort.h”
using namespace std;
char *c_string;
int main()
{
SerialPort Xbee_rx((char*)“\\.\COM4”);
if (Xbee_rx.isConnected()) cout << “Connection etablie avec succes du recepteur” << endl;
else cout << “ERROR, pas le bon port”;
while (1) {
cout << " Lecture effectuee : " << Xbee_rx.readSerialPort(c_string, MAX_DATA_LENGTH) << endl;
Sleep(1);
}
The xbee is well connected to the port but receive nothing, the program only returns 0.
Thank you in advance