int main() { char comm_port[100]; int tcp_port, comm_num; COMMTIMEOUTS cto = { MAXDWORD, 0, 0, 0, 0 }; //NON BLOQUANT HANDLE fd, fork_id; SOCKET sd, sd_client; struct ThreadData tData; tcp_port = TCP_PORT; comm_num = 1; printf("Win32 TCP2Xbee"); #ifdef _DEBUG_ printf(" - Active DEBUG Activated"); #endif printf("\n"); printf("COM Port Number [1]:"); if(scanf_s("%d", &comm_num)==0) comm_num = 1; printf("TCP Port [%i]:", tcp_port); if(scanf_s("%d", &tcp_port)==0) tcp_port = TCP_PORT; sprintf_s(comm_port, 100, "COM%d", comm_num); printf("Trying to Open %s\n", comm_port); openXBee(comm_port, &fd); sd=openNetwork(tcp_port); /* Switch to API Mode on the XBee device */ setAPI(&fd); COMMERR((!SetCommTimeouts(fd,&cto)?-1:0), "SetCommTimeouts"); /* Fork */ while(1) { ERR(sd_client = accept(sd, NULL, 0), "accept"); fprintf(stderr, "Client Connected\n"); tData.sock = sd_client; tData.fd = &fd; fork_id = CreateThread( NULL, 0,xbeeListen, &tData, 0, NULL); //Crée un thread pour s'occuper des datas du Xbee networkListen(sd_client, &fd); CloseHandle(fork_id); printf("xBeeListen Finished\n"); closesocket(sd_client); fprintf(stderr, "Client Disconnected\n"); } //close(sd); closesocket(sd); CloseHandle(fd); system("pause"); return 0; }
int main(int argc, char **argv) { char port[100], buf[1024], buf2[2048]; int fd, size, i; if(argc > 1) strcpy(port, argv[1]); else strcpy(port, "/dev/ttyS0"); ERR(fd = open(port, O_RDWR | O_NOCTTY), "open"); setbaud(fd); setAPI(fd); sendAPI(fd); return 0; }
Namespace::~Namespace() { WBATOM(MMgc::GC::GetGC(this), this, &m_prefix, 0); setUri(NULL, NS_Public); setAPI(0); }