i am writing a small c program in Kubuntu system to communicate with Xbee. The prog is very simple, just open the serial port device file(ex:ttyS0, which is connected to Xbee development board),write a AT command string(ex: ‘atnd\r’ to search all the nodes nearby), and read the answer after then. Everything goes well if i put all of them together(including sub methods: send_PacketFrame(), receive_PacketFrame(), other sub function. and the main() function) in a single file. But when i tried to put these sub methods in a shared library file whose name is ended by .so, and create a seperate file for main(), in some of the sub function, the Xbee never answer the request and wait till the timeout(like the following example). i tested the basic function(such like send_PacketFrame(), receive_PacketFrame(), they work), and i’ve tested also a method who tried to get the temperature value from a remote device in API mode, it works too for me. But some command like ‘atnd\r’, ‘at\r’, Xbee never reponse.
i was really confused. because there are so few steps, i don’t understand where the problem is. Is there anyone who can help me out of this, i struggle with it for a long time, that really makes me nervous. A lots of thanks.
i list some of my code in the following :
int get_xbee_nodes(char *str)
send_PacketFrame(AT,5);//send AT string, 5 is the length of str
nbytes=receive_Packet(ptrFrame,255);//read 255 bytes from serial port, ptrFrame pointer to the beginning of result string, nbytes indicates the result length
//because each time it returns just 8 bytes, i write a loop here to get an entire reponse
i also tried adding some time repos: sleep(1) between send and receive function, it didn’t work either.