bool CStrainDevice::RequestDataB(long &ad) { if (m_hCom == INVALID_HANDLE_VALUE) { return false; } BYTE cmd = 'M'; WriteComm(&cmd, 1); ::Sleep(20); BYTE bytesRead[5]; ZeroMemory(bytesRead, 2); DWORD nCount = ReadComm(bytesRead, 5); bool ok = (nCount == 5); if (ok) { BYTE *ptr = (BYTE*)&ad; ptr[0] = bytesRead[3]; ptr[1] = bytesRead[2]; ptr[2] = bytesRead[1]; ptr[3] = bytesRead[0]; } return ok; }
//写位数据 bool SerialComm::WriteCommRelay(UINT16 address, bool value) { if (IsOpen()) { byte byComm[8]; byComm[0] = 1; byComm[1] = 5; byComm[2] = HIBYTE(address); byComm[3] = LOBYTE(address); if (value) { byComm[4] = 0xff; } else { byComm[4] = 0x0; } byComm[5] = 0x0; TblCRC(byComm, 6); SendComm(byComm, 8); Sleep(10); if (ReadComm(myReceiveDate) && (myReceiveDate[1] == 5)) { return true; } } return false; }
//读位数据 bool SerialComm::ReadCommRelay(UINT16 address, UINT16 number, bool* back) { if (IsOpen()) { if (number > 800) { number = 800; } byte byComm[8]; byComm[0] = 0x1; byComm[1] = 0x1; byComm[2] = HIBYTE(address); byComm[3] = LOBYTE(address); byComm[4] = HIBYTE(number); byComm[5] = LOBYTE(number); TblCRC(byComm, 6); SendComm(byComm, 8); Sleep(10); if (ReadComm(myReceiveDate) && (myReceiveDate[1] == 1)) { ByteToBool(myReceiveDate + 3, number, back); return true; } } return false; }
int gsmSendMessage(SM_PARAM* pSrc) { int nPduLength; // PDU串长度 unsigned char nSmscLength; // SMSC串长度 int nLength; // 串口收到的数据长度 char cmd[16]; // 命令串 char pdu[512]; // PDU串 char ans[128]; // 应答串 nPduLength = gsmEncodePdu(pSrc, pdu); // 根据PDU参数,编码PDU串 strcat(pdu, "\x01a"); // 以Ctrl-Z结束 TRACE("%s", pdu); //zhao gsmString2Bytes(pdu, &nSmscLength, 2); // 取PDU串中的SMSC信息长度 nSmscLength++; // 加上长度字节本身 // 命令中的长度,不包括SMSC信息长度,以数据字节计 sprintf(cmd, "AT+CMGS=%d\r", nPduLength / 2 - nSmscLength); // 生成命令 TRACE("%s", cmd); TRACE("%s\n", pdu); WriteComm(cmd, strlen(cmd)); // 先输出命令串 nLength = ReadComm(ans, 128); // 读应答数据 // 根据能否找到"\r\n> "决定成功与否 if(nLength == 4 && strncmp(ans, "\r\n> ", 4) == 0) { return WriteComm(pdu, strlen(pdu)); // 得到肯定回答,继续输出PDU串 } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { stack_t st1 = {}; cpu stk1 = {}; Stack_ctor(&stk1, &st1); char* argvName = (char*)calloc(wcslen(argv[0]), sizeof(argvName)); size_t len = wcstombs(argvName, argv[0], wcslen(argv[0])); //for (int i = 0; i < argc; i++) //std::cout << argv[i] << std::endl; // wprintf(L"%s \n", argv[i]); //const char* argv1 = "commands.asm"; int CountOfCom = 0; const int* commandBuff = ReadComm(argv[argc - 1], &CountOfCom); int ResultOfDo = doCommand(&stk1, commandBuff, argv[argc - 1], CountOfCom); //if (ResultOfDo == 0) printf("Wrong Command. \n" // "WHAT ARE YOU DOING? READ HELP ONE'S MORE TIME!"); Stack_dtor(&st1); Stack_dtor(&stk1); return 0; }
int far pascal zReadComm( int pp1, void far* pp2, int pp3 ) { int r; SaveRegs(); /* ** Log IN Parameters (No Create/Destroy Checking Yet!) */ LogIn( (LPSTR)"APICALL:ReadComm int++int+", pp1, (short)0, pp3 ); /* ** Call the API! */ RestoreRegs(); GrovelDS(); r = ReadComm(pp1,pp2,pp3); UnGrovelDS(); SaveRegs(); /* ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!) */ LogOut( (LPSTR)"APIRET:ReadComm int++FineString++", r, (short)0, (LPSTR) pp2, (int) abs( r ), (short) 0 ); RestoreRegs(); return( r ); }
//写双字数据 bool SerialComm::WriteCommDword(UINT16 address, DWORD value) { if (IsOpen()) { byte byComm[13]; byComm[0] = 1; byComm[1] = 16; byComm[2] = HIBYTE(address); byComm[3] = LOBYTE(address); byComm[4] = 0; byComm[5] = 2; byComm[6] = 4; byComm[7] = HIBYTE(LOWORD(value)); byComm[8] = LOBYTE(LOWORD(value)); byComm[9] = HIBYTE(HIWORD(value)); byComm[10] = LOBYTE(HIWORD(value)); TblCRC(byComm, 11); SendComm(byComm, 13); Sleep(10); if (ReadComm(myReceiveDate) && (myReceiveDate[1] == 16)) { return true; } } return false; }
//读双字数据 bool SerialComm::ReadCommDword(UINT16 address, UINT16 number, DWORD* back) { if (IsOpen()) { if (number > 25) { number = 25; } byte byComm[8]; byComm[0] = 0x1; byComm[1] = 0x3; byComm[2] = HIBYTE(address); byComm[3] = LOBYTE(address); byComm[4] = HIBYTE(number * 2); byComm[5] = LOBYTE(number * 2); int time = number * 5; if (time < 10) { time = 10; } TblCRC(byComm, 6); SendComm(byComm, 8); Sleep(time); if (ReadComm(myReceiveDate) && (myReceiveDate[1] == 3)) { ByteToDword(myReceiveDate + 3, number, back); return true; } } return false; }
// 初始化GSM状态 BOOL gsmInit() { char ans[128]; // 应答串 // 测试GSM-MODEM的存在性 WriteComm("AT\r", 3); ReadComm(ans, 128); if (strstr(ans, "OK") == NULL) return FALSE; // ECHO OFF WriteComm("ATE0\r", 5); ReadComm(ans, 128); // PDU模式 WriteComm("AT+CMGF=0\r", 10); ReadComm(ans, 128); return TRUE; }
// 初始化GSM状态 BOOL gsmInit(const char* pPort) { char ans[128]; // 应答串 ZeroMemory(ans,128); // 测试GSM-MODEM的存在性 WriteComm(pPort,"AT\r\n", 4); ReadComm(pPort,ans, 128); if (strstr(ans, "OK") == NULL) return FALSE; // ECHO OFF WriteComm(pPort,"ATE0\r", 5); ReadComm(pPort,ans, 128); // PDU模式 WriteComm(pPort,"AT+CMGF=0\r", 10); ReadComm(pPort,ans, 128); return TRUE; }
//------------------------------------------------------------------- // Read an array of bytes to the COM port, verify that it was // sent out. Assume that baud rate has been set and the buffers have // been flushed. // // portnum - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // inlen - the length of the data that was read // outbuf - the input data // // Returns number of characters read // int ReadCOM(int portnum, int inlen, uchar *inbuf) { COMSTAT ComStat; short result; ulong m; ulong more; // declare and set the default timeout int timeout = 20 * inlen + 60; //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// #ifdef DODEBUG short i; #endif //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// m = (ulong)msGettick() + (ulong)timeout; do { GetCommError(ComID[portnum],&ComStat); if ((short)ComStat.cbInQue >= inlen) { result = ReadComm(ComID[portnum],inbuf,inlen); if (result == (int)inlen) { GetCommError(ComID[portnum],&ComStat); more = ComStat.cbInQue; //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// #ifdef DODEBUG printf("R["); for (i = 0; i < inlen; i++) printf("%02X ",inbuf[i]); printf("]"); #endif //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// return result; } else return FALSE; } //else // yield this process //Yield(); } while ((ulong)msGettick() <= m); return FALSE; }
//------------------------------------------------------------------- // Description: // flush the rx and tx buffers // // portnum - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // void FlushCOM(int portnum) { char ch[] = {"X"}; COMSTAT stat; for (;;) { GetCommError(ComID[portnum],&stat); if (stat.cbInQue) ReadComm(ComID[portnum],ch,1); else break; } FlushComm(ComID[portnum],0); FlushComm(ComID[portnum],1); }
int gsmGetResponse(SM_BUFF* pBuff) { int nLength; // 串口收到的数据长度 int nState; // 从串口读数据,追加到缓冲区尾部 nLength = ReadComm(&pBuff->data[pBuff->len], 128); pBuff->len += nLength; // 确定GSM MODEM的应答状态 nState = GSM_WAIT; if ((nLength > 0) && (pBuff->len >= 4)) { if (strncmp(&pBuff->data[pBuff->len - 4], "OK\r\n", 4) == 0) nState = GSM_OK; else if (strstr(pBuff->data, "+CMS ERROR") != NULL) nState = GSM_ERR; } return nState; }
bool CStrainDevice::RequestAddr(BYTE addr /* = 0 */) { if (m_hCom == INVALID_HANDLE_VALUE) { return false; } BYTE cmd[2]; cmd[0] = 'K'; cmd[1] = 0; WriteComm(cmd, 2); ::Sleep(100); BYTE to_read[2]; ZeroMemory(to_read, 2); ReadComm(to_read, 2); return memcmp(cmd, to_read, 2) == 0; }
//写字数据 bool SerialComm::WriteCommWord(UINT16 address, WORD value) { if (IsOpen()) { byte byComm[8]; byComm[0] = 1; byComm[1] = 6; byComm[2] = HIBYTE(address); byComm[3] = LOBYTE(address); byComm[4] = HIBYTE(value); byComm[5] = LOBYTE(value); TblCRC(byComm, 6); SendComm(byComm, 8); Sleep(10); if (ReadComm(myReceiveDate) && (myReceiveDate[1] == 6)) { return true; } } return false; }
void XTTY::OnCommNotify(WPARAM wParam, LPARAM lParam) { char buf[128]; int rtn; RECT rc; BOOL fScroll = FALSE; if (!m_fConnect) return; if (lParam & CN_EVENT) { // 通信デバイスイベント発生 } if (lParam & CN_RECEIVE) { // 受信イベント発生 rtn = ReadComm(m_idComDev, buf, sizeof(buf)); if (rtn <= 0) { CommErrorMessage(); return; } WriteLog(buf, rtn); } }
void main (int argc, char *argv[]) { cout << "Squirrel 1.16/release, Adaptive answer Service for USR Voice modems" << endl; cout << "Copyright (c)2000 Eugeniy Gryaznov, Compiled on 02.05.00 at 21:09" << endl; if(argc<2) { cout << " Use <squirrel.exe> <action> [<action param>] [switches]" << endl; cout << " action: PLAY,REC,MAILER,MAIN" << endl; cout << " PLAY f.gsm Play file to speaker(modem)" << endl; cout << " REC f.gsm Record from microphone(modem) to file" << endl; cout << " MAILER Mailer compatible mode" << endl; cout << " MAIN Run in master mode" << endl; cout << " CONV f.gsm Convert GSM ->WAV" << endl; cout << " switches: [/L] [/D] [/P]" << endl; cout << " /L switch Playing/Recording device" << endl; cout << " /D switch Show debug info" << endl; cout << " /P switch close/real_close port" << endl; cout << " /B switch 8/16 bit wave output" << endl; cout << " Ex: squirrel play allo.gsm /L /D" << endl; cout << " squirrel main" << endl; ErrorExit(0,"Help screen"); } // Get default CTL name char ctl[128]; char *ext = "CTL"; strcpy(ctl,argv[0]); strcpy(ctl+strlen(ctl)-3,ext); SetDefault(); // Check ARGV int Task = 0, swch = 0; // 1 - PLAY, 2 - REC, 3 - MAILER, 4 - MAIN char TParam[128],fname[128],*outw; int postdo = 0; // Get task type if (strcmp(strupr(argv[1]),"PLAY")==0) { strcpy(TParam,argv[2]);Task=1; } else if (strcmp(strupr(argv[1]),"REC")==0) { strcpy(TParam,argv[2]);Task=2; } else if (strcmp(strupr(argv[1]),"MAILER")==0) { strcpy(TParam,argv[2]);Task=3; } else if (strcmp(strupr(argv[1]),"MAIN")==0) { strcpy(TParam,argv[2]);Task=4; } else if (strcmp(strupr(argv[1]),"CONV")==0) { strcpy(TParam,argv[2]);Task=5; } else ErrorExit(1,"Unknown action"); if ((Task==1||Task==2||Task==5)&&argc==2) ErrorExit(1,"not enough params"); // Process switches for (int argnum=2;argnum<argc;argnum++){ if ((Task!=1&&Task!=2&&Task!=5)||argnum!=2){ if (strcmp(strupr(argv[argnum]),"/D")==0) swch|=1; else if (strcmp(strupr(argv[argnum]),"/L")==0) swch|=2; else if (strcmp(strupr(argv[argnum]),"/P")==0) swch|=4; else if (strcmp(strupr(argv[argnum]),"/B")==0) swch|=8; else ErrorExit(1,"Unknown switch"); } } cout << "TASK: "; switch(Task){ case 1: cout << "playing file (device <- " << TParam << ")" << endl;break; case 2: cout << "recording file (device -> " << TParam << ")" << endl;break; case 3: cout << "mailer mode" << endl;break; case 4: cout << "master mode" << endl;break; } if (Task<5){ // Read config + FIX switches ReadConfig(ctl); if (swch&1) cfg.debuginfo=(cfg.debuginfo+1)%2; if (swch&2) cfg.pln=(cfg.pln+1)%2; if (swch&4) cfg.realcl=(cfg.realcl+1)%2; if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2; // Open COMPort OpenComm(cfg.baud,cfg.ioport,cfg.irq); if(prtst!=-1) ErrorExit(3,"Communication port not found"); // Init screen StartupScr(); // Init modem SendModemStr(&cfg.init,"Initializing modem"); SendModemStr(&cfg.voice,"Voice mode"); } // Start Log if (Task==3||Task==4){ struct time _t; struct date _d; gettime(&_t);getdate(&_d); write_log("\n -- executed on "); write_log_num(_d.da_day);write_log("."); write_log_num(_d.da_mon);write_log("."); write_log_num(_d.da_year);write_log(" at "); write_log_num(_t.ti_hour);write_log(":"); write_log_num(_t.ti_min);write_log(" --\n"); } // Main work switch(Task){ case 1: PlayFile(TParam); break; case 2: cfg.wavout=0; RecFile(TParam,0); break; case 3: if (!cfg.gsmframe) ErrorExit(78,"mailer mode require USE_GSM=1"); cfg.up=0;cfg.pln=0; if (cfg.useaon&1){ AON(); } else { if (cfg.hook){ SendModemStr(&cfg.offhook,"Offhook"); delay(cfg.wallo); } } PlayFile(cfg.sallo); if (cfg.loglev&2) write_log("detecting\n"); switch (Detect()){ case 1: // Modem CreateFlag(cfg.ata); SendModemStr(&cfg.data,"Data mode"); SendModemStr(&cfg.mailinit,"Initializing modem to connect"); write_log("Detected: MODEM\n"); ErrorExit(0,"modem detected"); break; case 2: // Voice write_log("Detected: VOICE\n"); PlayFile(cfg.swait); for (int curring=0;curring<cfg.RTL;curring++){ if (!kbhit()){ if (strlen(cfg.soundfl)) CreateFlag(cfg.soundfl); else sound(cfg.khz); SendModemStr(&cfg.beep,"Beep"); nosound(); } if (kbhit()) break; if (curring+1!=cfg.RTL) delay(cfg.delayring); } ch=0;while (kbhit()) ch=getch(); if (cfg.auto_detect&&ch!=27&&ch!=32){ // check if voice present cout << " ! auto : speach in line" << endl;FixLine(); if (cfg.loglev&2) write_log("detecting\n"); ch=0;cfg.limit=cfg.auto_detect; if ((ch=Detect())==2) ch=32; if (ch==3||ch==4) break; } if (ch!=27) if (ch==32){ cout << " ! autoanswer skipped" << endl;FixLine(); write_log("autoanswer skipped\n"); postdo=1; } else { PlayFile(cfg.sauto); SendModemStr(&cfg.abeep,"aBeep"); generate_name(fname); write_log("Recording: ");write_log(fname);write_log("\n"); RecFile(fname,cfg.rec_time); } break; case 3: write_log("Detected: BUSY\n");break; case 4: write_log("Detected: DIAL TONE\n");break; } SendModemStr(&cfg.onhook,"Onhook"); break; case 4: int wring; char rng[100];cfg.up=0;cfg.pln=0; while(kbhit()) getch(); if (cfg.gsmframe==0&&cfg.useaon!=0) ErrorExit(73,"AON require USE_GSM=1"); while(!kbhit()){ cout << " Waiting for RING ...";rng[0]=0; while(!kbhit()&&strstr(rng,"RING")==NULL){ while(ReadComm(ch)){ rng[strlen(rng)+1]=0; rng[strlen(rng)]=ch; if (strlen(rng)==95) rng[0]=0; } } if (!kbhit()){ cout << endl;FixLine(); cout << " ! RING ."; for(wring=0;wring<(cfg.ring-1);wring++){ if (!WaitFor("RING",7,cfg.debuginfo)) { cout << " <no more rings>" << endl;FixLine();wring=0;break;} else cout << "."; } } if (!kbhit()&&wring){ // Wait cfg.ring cout << endl;FixLine(); if (cfg.useaon&2){ AON(); } else { SendModemStr(&cfg.offhook,"Offhook"); delay(cfg.wallo); } cfg.up=0; PlayFile(cfg.sauto); SendModemStr(&cfg.abeep,"aBeep"); generate_name(fname); RecFile(fname,cfg.rec_time); SendModemStr(&cfg.onhook,"Onhook"); SendModemStr(&cfg.init,"Initializing modem"); SendModemStr(&cfg.voice,"Voice mode"); while(kbhit()) getch(); } } cout << endl;FixLine(); while(kbhit()) getch(); break; case 5: // Open files if (swch&8) cfg.wav8bit=(cfg.wav8bit+1)%2; fp=fopen(TParam,"rb"); if (fp==NULL) ErrorExit(93,"error: .gsm input"); outw=TParam; cout << "GSM->WAV converting: " << TParam << " -> "; while (strchr(outw,'\\')!=NULL) outw=strchr(outw,'\\'); while (strchr(outw,'/')!=NULL) outw=strchr(outw,'/'); if (strlen(outw)==0) ErrorExit(153,"out name error"); if (strchr(outw,'.')!=NULL) *strchr(outw,'.')=0; strcat(strlwr(TParam),".wav"); cout << TParam;if(cfg.wav8bit) cout << " (8bit)";cout << endl; if (!Start_GSM_WAV(TParam,cfg.wav8bit)){ cout << "output file error";exit(1);} while (fread(gsmb,1,33,fp)==33){ decode_block(gsmb,cfg.wav8bit); } // close file fclose(fp); Close_GSM_WAV(); ErrorExit(0,"OK"); } // Deinit SendModemStr(&cfg.data,"Data mode"); SendModemStr(&cfg.deinit,"Deinitializing modem"); if (postdo&&cfg.postspace){ cout << " ! Press any key to return to Mailer"; getch();sound(440);delay(5);nosound(); cout << endl;FixLine(); } // Close COMPort & Exit ErrorExit(0,"All ok"); }
BOOL TSerialConnection :: Receive ( void ) { char buffer [ SEND_BUFFER_SIZE_SERIAL / 4 ] ; char inbuf [ RECEIVE_BUFFER_SIZE_SERIAL ] ; int size, count ; int CommError ; DWORD TickCount ; COMSTAT ComStat ; register int i ; if ( DeviceId < 0 ) return ( FALSE ) ; TickCount = GetTickCount ( ) ; // Réception des caractères : CommError = GetCommError ( DeviceId, & ComStat ) ; if ( CommError & ( CE_BREAK | CE_RXOVER ) ) ClearCommBreak ( DeviceId ) ; size = ReadComm ( DeviceId, inbuf, RECEIVE_BUFFER_SIZE_SERIAL ) ; if ( size < 0 ) { size = - size ; GetCommError ( DeviceId, & ComStat ) ; ClearCommBreak ( DeviceId ) ; } for ( i = 0 ; i < size ; i ++ ) { if ( CharactersReceived + 1 >= ReceiveBufferSize ) { DestinationWindow -> HandleMessage ( WM_DATARECEIVED, CharactersReceived, 0L ) ; if ( CharactersReceived + 1 >= ReceiveBufferSize ) MessageBox ( NULL, "Arrghhh !!!", MB_OK | MB_ICONEXCLAMATION, "Trop de caractères reçus!" ) ; } ReceiveBuffer [ ( Origin + CharactersReceived ) % ReceiveBufferSize ] = inbuf [i] ; CharactersReceived = ( CharactersReceived + 1 ) % ReceiveBufferSize ; } // On vérifie s'il y a eu un timeout if ( TimeOutValue && ! size ) { if ( TickCount - TimeOutTick > TimeOutValue ) { ReceiveBuffer [ ( Origin + CharactersReceived ) % ReceiveBufferSize ] = TIMEOUT_CHAR ; CharactersReceived = ( CharactersReceived + 1 ) % ReceiveBufferSize ; size = 1 ; TimeOutFlag = TRUE ; } } if ( size ) TimeOutTick = TickCount ; // Prévenir la fenêtre que des caractères ont été reçus if ( CharactersReceived ) DestinationWindow -> HandleMessage ( WM_DATARECEIVED, CharactersReceived, 0L ) ; // Si des caractères sont à envoyer, on en profite count = ( int ) ( ( ConnectionParameters -> Serial. RealSpeed / 12 ) / ( 1000 / TIMER_INTERVAL ) ) ; count = min ( count, SEND_BUFFER_SIZE_SERIAL / 4 ) ; size = HugeTable -> Copy ( buffer, count ) ; if ( size ) DestinationWindow -> SendMessage ( WM_SENDDATA, size, ( LPARAM ) ( ( char far * ) buffer ) ) ; return ( size ) ; }
/////////////////////////////////////////////////////////////////////////////// // Run /////////////////////////////////////////////////////////////////////////////// // DESCRIPTION: // This function runs the main thread loop // this implementation can be overloaded. // This function calls CSocketComm::OnDataReceived() (Virtual Function) // PARAMETERS: // NOTES: // You should not wait on the thread to end in this function or overloads /////////////////////////////////////////////////////////////////////////////// void CSocketComm::Run() { stMessageProxy stMsgProxy; DWORD dwBytes = 0L; DWORD dwTimeout = INFINITE; LPBYTE lpData = (LPBYTE)&stMsgProxy; DWORD dwSize = sizeof(stMsgProxy); bool bSmartAddressing = IsSmartAddressing(); if ( !bSmartAddressing ) { lpData = stMsgProxy.byData; dwSize = sizeof(stMsgProxy.byData); } // Should we run as server mode if (IsServer() && !bSmartAddressing) { if (!IsBroadcast()) { SOCKET sock = (SOCKET) m_hComm; sock = WaitForConnection( sock ); // Get new connection socket if (sock != INVALID_SOCKET) { ShutdownConnection( (SOCKET) m_hComm); m_hComm = (HANDLE) sock; OnEvent( EVT_CONSUCCESS, NULL ); // connect } else { // Do not send event if we are closing if (IsOpen()) OnEvent( EVT_CONFAILURE, NULL ); // wait fail return; } } } else { GetPeerName( stMsgProxy.address ); } while( IsOpen() ) { // Blocking mode: Wait for event dwBytes = ReadComm(lpData, dwSize, dwTimeout); // Error? - need to signal error if (dwBytes == (DWORD)-1L) { // Do not send event if we are closing if (IsOpen()) { if ( bSmartAddressing ) { RemoveFromList( stMsgProxy.address ); } OnEvent( EVT_CONDROP, &stMsgProxy.address ); // lost connection } // special case for UDP, alert about the event but do not stop if ( bSmartAddressing ) continue; else break; } // Chars received? if ( bSmartAddressing && dwBytes == sizeof(SOCKADDR_IN)) { OnEvent( EVT_ZEROLENGTH, NULL ); } else if (dwBytes > 0L) { OnDataReceived( lpData, dwBytes); } //Sleep(0); } }