Click here to Skip to main content
15,911,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: CInternetfile - trying to use 'seek' always getting an assertion error Pin
David Crow29-Aug-08 11:02
David Crow29-Aug-08 11:02 
AnswerRe: CInternetfile - trying to use 'seek' always getting an assertion error Pin
simon alec smith29-Aug-08 11:07
simon alec smith29-Aug-08 11:07 
AnswerRe: CInternetfile - trying to use 'seek' always getting an assertion error Pin
simon alec smith29-Aug-08 11:19
simon alec smith29-Aug-08 11:19 
GeneralRe: CInternetfile - trying to use 'seek' always getting an assertion error Pin
Mark Salsbery29-Aug-08 11:28
Mark Salsbery29-Aug-08 11:28 
QuestionUnable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 6:34
AprNgp29-Aug-08 6:34 
QuestionRe: Unable to send AT commands to the COM3 port. plz help. Pin
Perspx29-Aug-08 6:50
Perspx29-Aug-08 6:50 
AnswerRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 6:52
AprNgp29-Aug-08 6:52 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 6:58
AprNgp29-Aug-08 6:58 
my code is as follows ...
  DCB dcb;
   HANDLE hCom;
   BOOL fSuccess;
   TCHAR *pcCommPort = TEXT("COM3");
   char DataBuffer[] = "AT+FCLASS=8";
    DWORD dwBytesToWrite = (DWORD)strlen(DataBuffer);
	char Data2[]="ATDW2289759";
	
    DWORD dwBytesWritten = 0;
	DWORD dwBytesRead = 0;
    char ReadBuffer[BUFFER_SIZE] = {0};
   hCom = CreateFile( pcCommPort,
                    GENERIC_READ | GENERIC_WRITE,
                    0,    // must be opened with exclusive-access
                    NULL, // default security attributes
                    OPEN_EXISTING, // must use OPEN_EXISTING
                    0,    // not overlapped I/O
                    NULL  // hTemplate must be NULL for comm devices
                    );

   if (hCom == INVALID_HANDLE_VALUE) 
   {
       // Handle the error.
       printf ("CreateFile failed with error %d.\n", GetLastError());
       return (1);
   }

   // Build on the current configuration, and skip setting the size
   // of the input and output buffers with SetupComm.

  // SecureZeroMemory(&dcb, sizeof(DCB));
   dcb.DCBlength = sizeof(DCB);
   fSuccess = GetCommState(hCom, &dcb);

   if (!fSuccess) 
   {
      // Handle the error.
      printf ("GetCommState failed with error %d.\n", GetLastError());
      return (2);
   }

  
	dcb.BaudRate = CBR_2400;     // set the baud rate
	dcb.ByteSize = 8;             // data size, xmit, and rcv
	dcb.Parity = NOPARITY;        // no parity bit
    dcb.StopBits = ONESTOPBIT;    // one stop bit

   fSuccess = SetCommState(hCom, &dcb);

   if (!fSuccess) 
   {
      // Handle the error.
      printf ("SetCommState failed with error %d.\n", GetLastError());
      return (3);
   }

   _tprintf (TEXT("Serial port %s successfully reconfigured.\n"),pcCommPort);
	
	//WriteFile(hCom,"AT+FCLASS=8",sizeof("AT+FCLASS=8"),&len,0);

   if( FALSE == WriteFile(hCom,           // open file handle
                               DataBuffer + dwBytesWritten,     // start of data to write
                               dwBytesToWrite - dwBytesWritten, // number of bytes to write
                               &dwBytesWritten, // number of bytes that were written
                               NULL))            // no overlapped structure		
                    printf("Could not write %s to file (error %d)\n",DataBuffer, GetLastError());
   else
	   _tprintf(TEXT("Wrote %d bytes successfully.\n"), dwBytesWritten);
      if( FALSE == ReadFile(hCom, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead, NULL) )
    {
        printf("Could not read from file (error %d)\n", GetLastError());
   }
   else
	   printf("%s",ReadBuffer);

dwBytesWritten = 0;
if( FALSE == WriteFile(hCom,           // open file handle
                               Data2 + dwBytesWritten,     // start of data to write
                               (DWORD)sizeof(Data2) - dwBytesWritten, // number of bytes to write
                               &dwBytesWritten, // number of bytes that were written
                               NULL))            // no overlapped structure		
 printf("Could not write %s to file (error %d)\n",Data2, GetLastError());
else
_tprintf(TEXT("Wrote %d bytes successfully.\n"), dwBytesWritten);
if( FALSE == ReadFile(hCom, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead, NULL) )
{
printf("Could not read from file (error %d)\n", GetLastError());
}
else
printf("%s",ReadBuffer);


after sending the string to the port, i m reading the port, and every time same string is read !

Apurv

GeneralRe: Unable to send AT commands to the COM3 port. plz help. [modified] Pin
SandipG 29-Aug-08 8:22
SandipG 29-Aug-08 8:22 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 8:36
AprNgp29-Aug-08 8:36 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
SandipG 29-Aug-08 8:39
SandipG 29-Aug-08 8:39 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 8:42
AprNgp29-Aug-08 8:42 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
SandipG 29-Aug-08 8:43
SandipG 29-Aug-08 8:43 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 8:48
AprNgp29-Aug-08 8:48 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
SandipG 29-Aug-08 9:12
SandipG 29-Aug-08 9:12 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 9:15
AprNgp29-Aug-08 9:15 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
SandipG 29-Aug-08 9:19
SandipG 29-Aug-08 9:19 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 9:25
AprNgp29-Aug-08 9:25 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 9:28
AprNgp29-Aug-08 9:28 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp31-Aug-08 8:54
AprNgp31-Aug-08 8:54 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
Vaclav_29-Aug-08 8:50
Vaclav_29-Aug-08 8:50 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 8:56
AprNgp29-Aug-08 8:56 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 9:06
AprNgp29-Aug-08 9:06 
QuestionCString as variable arguments Pin
Royce Fickling29-Aug-08 5:31
Royce Fickling29-Aug-08 5:31 
QuestionRe: CString as variable arguments Pin
David Crow29-Aug-08 7:42
David Crow29-Aug-08 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.