Hi every one,

I am trying to integrate the the bluetooth functionality with the QT applciation. I was just wondering what would be the problem with the sprintf statement(tested out both) but does not work...

the function is called from the main function which specifies the struct and initialises its comPort ... Then the data are passed to the connectRobot function and hence this error...

A error of segmentation is shown up if i debug the program at line 9.... crashing the whole program when I run it...

any suggestions on the mistake i would have made...


Thanking you...

Rajesh Medampudi


Qt Code:
  1. int connectRobot(struct robot *rbt, int comPort)
  2. {
  3.  
  4.  
  5.  
  6. char portname[20];
  7. sprintf(portname,"COM%d",comPort);
  8. //sprintf(portname,"\\\\.\\COM%d",comPort);
  9. hSerialPort[rbt->serialConnection] = CreateFileA(portname,
  10. GENERIC_READ | GENERIC_WRITE,
  11. 0,
  12. 0,
  13. OPEN_EXISTING,
  14. FILE_ATTRIBUTE_NORMAL,
  15. 0);
  16. if (hSerialPort[rbt->serialConnection] == INVALID_HANDLE_VALUE) return -1;
  17.  
  18.  
  19.  
  20. dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
  21. if (!GetCommState(hSerialPort[rbt->serialConnection], &dcbSerialParams)) return -2;
  22.  
  23. dcbSerialParams.BaudRate = 115200;
  24. dcbSerialParams.ByteSize = 8;
  25. dcbSerialParams.StopBits = ONESTOPBIT;
  26. dcbSerialParams.Parity = NOPARITY;
  27.  
  28. comt.ReadIntervalTimeout = 500;
  29. SetCommTimeouts( hSerialPort[rbt->serialConnection], &comt);
  30. if (!SetCommState(hSerialPort[rbt->serialConnection], &dcbSerialParams)) return -3;
  31.  
  32. rbt->port=comPort;
  33. rbt->connected=1;
  34.  
  35.  
  36.  
  37. return 0;
  38. }
To copy to clipboard, switch view to plain text mode