Home/Support/Support Forum/Transmitting via serial port on linux using cpp
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Transmitting via serial port on linux using cpp

0 votes
*This post is not getting displayed properly, but i do not know the problem here. Any ideas?

Hi all,
I am having trouble transmitting data. I have a cpp programm that should transmit and receive using this xbee board: http://ftp1.digi.com/support/documentation/xbibudev_referenceguide.pdf
Receiving data works perfectly fine, but sending is a problem.



The Code:
//open USB port for read/write and check success ctx->fd = open(devFileName, O_RDWR | O_NOCTTY); //opens the usb port for reading if (ctx->fd < 0) { cerr << "Could not open the USB Port. Try adding User to group dialout!" << endl; return 0; } //is the opened port a terminal? if(!isatty(ctx->fd)) { close(ctx->fd); errno = ENOTTY; return 0; } //setup termios tcgetattr(ctx->fd, &(ctx->oldtio)); cfmakeraw(&newtio); cfsetispeed(&newtio, baudrate); cfsetospeed(&newtio, baudrate); tcsetattr(ctx->fd, TCSANOW, &newtio); tcflush(ctx->fd, TCIFLUSH); lseek(ctx->fd, 0, SEEK_END); ctx->bufIO = fdopen(ctx->fd, "r+"); bool connection_status=0; unsigned char frame_id=0x00; unsigned char checksum=0xff; while(!connection_status){ checksum=0xFF; unsigned char buffer[] = { 0x7E, //start delimiter 0x00,0x07,//length of the data packet 0x01,//API identifier (refer to XBee module manual for further details) frame_id++, //frame id 0x00,0x0B,//destination address 0x00,//options 0x02,0x03,//data: 0,receiver address,mode 0x00}; //checksumm for(unsigned int i=0;i<sizeof(buffer);i++){ checksum-=buffer[i]; } buffer[10]=checksum; cout << "sending..." << endl; fwrite(buffer,sizeof(char),sizeof(buffer),ctx->bufIO); usleep(2000000); } [\CODE] But this does not work properly. I have an oscilloscope hooked up to the xbee to see data entering to be transmitted. But I do only get a signal of a few miliseconds, when the frame id is 0x0A. If i fix either the frame id or some other of the chars, for example the 0x02 to 0x0A then i get a signal of only one milisecond. I am a little desperate by now, have been working on this for 1 week now. Greetings Flo[CODE]
//open USB port for read/write and check success
ctx->fd = open(devFileName, O_RDWR | O_NOCTTY); //opens the usb port for reading
if (ctx->fd < 0) {
cerr << "Could not open the USB Port. Try adding User to group dialout!" << endl;
return 0;
}
//is the opened port a terminal?
if(!isatty(ctx->fd)) {
close(ctx->fd);
errno = ENOTTY;
return 0;
}

//setup termios
tcgetattr(ctx->fd, &(ctx->oldtio));

cfmakeraw(&newtio);
cfsetispeed(&newtio, baudrate);
cfsetospeed(&newtio, baudrate);

tcsetattr(ctx->fd, TCSANOW, &newtio);
tcflush(ctx->fd, TCIFLUSH);
lseek(ctx->fd, 0, SEEK_END);

ctx->bufIO = fdopen(ctx->fd, "r+");

bool connection_status=0;
unsigned char frame_id=0x00;
unsigned char checksum=0xff;
while(!connection_status){
checksum=0xFF;
unsigned char buffer[] = {
0x7E, //start delimiter
0x00,0x07,//length of the data packet
0x01,//API identifier (refer to XBee module manual for further details)
frame_id++, //frame id
0x00,0x0B,//destination address
0x00,//options
0x02,0x03,//data: 0,receiver address,mode
0x00}; //checksumm

for(unsigned int i=0;i<sizeof(buffer);i++){
checksum-=buffer;
}
buffer[10]=checksum;
cout << "sending..." << endl;
fwrite(buffer,sizeof(char),sizeof(buffer),ctx->bufIO);
usleep(2000000);
}
[\CODE]

But this does not work properly. I have an oscilloscope hooked up to the xbee to see data entering to be transmitted. But I do only get a signal of a few miliseconds, when the frame id is 0x0A. If i fix either the frame id or some other of the chars, for example the 0x02 to 0x0A then i get a signal of only one milisecond.

I am a little desperate by now, have been working on this for 1 week now.
Greetings
Flo
asked Aug 7 in USB Serial by roessing New to the Community (1 point)

Please log in or register to answer this question.

1 Answer

0 votes
In the checksum loop there is an missing is just saw. But it is present in the original code. I dont know why the forum messed up my beutifull post so hard :(
answered Aug 8 by roessing New to the Community (1 point)
...