GFG-3015      p.45 
 
/*---------------- initial Data ---------------*/     
  for(i = 0; i<100;i++) command_line[i]=0; 
  for(i = 0; i<100;i++) Receive_Data[i]=0; 
 
/*---------------- Create Comm_port -----------*/   
    hComm = InitCom(error_value);   
 
/*---------------- Send *IDN? -----------------*/   
 
  dwcommand_len =sprintf( command_line,"*IDN?\n"); // ‘\n’ is message   
// terminator 
  WriteFile(hComm,command_line,dwcommand_len,&dwWritten,NULL); 
 
  Sleep(1000); // delay 1 sec for instrument response 
   
  ReadFile(hComm,Receive_Data,100,&dwRead,NULL); 
 
  Receive_Data[strlen(Receive_Data)] = 0x00; 
  printf("\nReceive_Data = %s\n",Receive_Data); 
   
/*-------------- Send FRQuency = 1000Hz -----------*/ 
 
  dwcommand_len =sprintf( command_line,":FREQuency %3.0f\n",1000.0);   
// ‘\n’ is message terminator 
  WriteFile(hComm,command_line,dwcommand_len,&dwWritten,NULL); 
 
  CloseHandle(hComm); 
} 
 
 
/*---------------------------------------------*/ 
/*                        Initial RS-232                                                  */    
/*---------------------------------------------*/ 
HANDLE InitCom(int Error_Value) 
{ 
  HANDLE      hComm; 
  COMMTIMEOUTS  CommTimeOuts; 
 
  hComm = CreateFile("COM1", 
    GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,NULL, NULL );     
               
 
  if (hComm == INVALID_HANDLE_VALUE)   
  { 
    printf("%s",Error_Message[0]); 
    return FALSE; 
  }     
 
/*----------------- Timeout -------------------*/ 
  CommTimeOuts.ReadIntervalTimeout = 1; 
  CommTimeOuts.ReadTotalTimeoutMultiplier = 0; 
  CommTimeOuts.ReadTotalTimeoutConstant = 1000; 
  CommTimeOuts.WriteTotalTimeoutMultiplier = 0; 
  CommTimeOuts.WriteTotalTimeoutConstant = 5000; 
  if(!SetCommTimeouts(hComm, &CommTimeOuts )) 
  { 
    printf("%s",Error_Message[1]); 
    return FALSE; 
  }