Exemplo n.º 1
0
int main()
{
    HANDLE fd; 
    DCB OldConf;
    char cad[16]="Enviando Texto\n";
    int n;
    
    fd=Open_Port("COM1");               // Abre el puerto serie
                                        // fd=Open_Port("/dev/ttyS0"); 
    
    OldConf=Get_Configure_Port(fd);     // guardo la configuracion del puerto 
    
    Configure_Port(fd,B115200,"8N1");   // Configuro el puerto serie 
    
    IO_Blocking(fd,TRUE);               // Bloqueante por defecto, pero tambien
                                        // se puede usar
                                        // IO_Blocking(fd,TRUE); 
    
    n=Write_Port(fd,cad,16);            // Escribo en el puerto serie
    
    Create_Thread_Port(&fd);            // Creo un hilo y le paso el manejador 

    while(TRUE);
    
    Set_Configure_Port(fd,OldConf);     // Restituyo la antigua configuracion 
                                        // del puerto 

    Close_Port(fd);                     // Cierro el puerto serie 
    
    printf("\nPresione ENTER para terminar\n");
    getchar();
    
    return 0;
}
Exemplo n.º 2
0
int main()
{
    HANDLE fd; 
    DCB OldConf;
    char cad[16]="Enviando Texto";
    int n;
    
    fd=Open_Port("/dev/ttyUSB0");       // Abre el puerto serie.
    
    OldConf=Get_Configure_Port(fd);     // Guardo la configuración del puerto.
    
    Configure_Port(fd,B115200,"8N1");   // Configuro el puerto serie.
    
    IO_Blocking(fd,FALSE);              // Seleccionamos lectura no bloqueante.
    
    n=Write_Port(fd,cad,16);            // Escribo en el puerto serie.
    
    while(Kbhit_Port(fd)<16);           // Espero a leer hasta que se tengan
                                        // 16 bytes en el buffer de entrada.

    n=Read_Port(fd,cad,16);             // Leo el puerto serie.
    printf("%s",cad);                   // Muestro loas datos.

    
    Set_Configure_Port(fd,OldConf);     // Restituyo la antigua configuración 
                                        // del puerto.

    Close_Port(fd);                     // Cierro el puerto serie.
    
    return 0;
}
Exemplo n.º 3
0
void
send_data_to(HANDLE fd, address dest, char* data, int size)
{
    char buff[16];

    printf("Sending data to %c%c%c%c: '%s'...\n", dest[0], dest[1], dest[2], dest[3], data);
    sprintf(buff, "ATDL%c%c%c%c", dest[0], dest[1], dest[2], dest[3]);
    write_AT_command(fd, (char*)buff); 
    Write_Port(fd,data,size);  // Write the serial port.    
}
void Serial_Comm::Send_Packet()
{
	while(port_status)
	{
		while(!send_queue.empty())
		{
			std::string packet(send_queue.pop());
			//std::cout << "Send_Packet: " << packet << std::endl;
			Write_Port(packet);
		}
	}
}
Exemplo n.º 5
0
int
write_AT_command(HANDLE fd, char* command)
{
    /* Clean the buffer. */
    int size;
    int res;
    char buff[1024];


    Sleep(SLEEP_UNIT*10); /* No too many commands in a short period of time! */ 

    res = Clean_Buffer(fd);
    if (res != TRUE) 
        force_exit(fd, "Clean buffer");

    printf("AT Command: %s\n", command);
    Write_Port(fd,"+++",3);  /* Enter to command mode. */
    
    if (check_OK_retrieved(fd))
    {
        Write_Port(fd,command,strlen(command)); /* Send command. */
        Write_Port(fd,"\r",1);                  /* Enter command. */
        if (check_OK_retrieved(fd))
        {

            Write_Port(fd,"ATCN",4);          /* Exit command mode. */
            //Sleep(500);
            Write_Port(fd,"\r" , 1);
            if (check_OK_retrieved(fd))
            {
                printf("Command sent OK.\n");            

                return TRUE;       
            }
            
        }
    }    
    printf("ERROR: Cannot send %s command.\n", command);
    return FALSE;
}
Exemplo n.º 6
0
jint NS_SendData(JNIEnv *env, jobject object, jlong handler, jbyteArray data, jint size)
{
#ifdef DEBUG
	unsigned long cost = GTimeGet();
#endif
	LPSERIAL engine = (LPSERIAL)handler;
	env->GetByteArrayRegion(data, 0, size, (signed char*)engine->pWriteBuffer);
	Write_Port(engine->mHandle, engine->pWriteBuffer, size);
#ifdef DEBUG
	engine->pWriteBuffer[size] = '\0';
	LOGI("(%s,%d) cost = %ld",  engine->pWriteBuffer, size, GTimeGet() - cost);
#endif
	return 0;
}
Exemplo n.º 7
0
/* Select_Ok
 *==========================================================================
 * Called when OK button is pressed or close_window occurs
 */
void
Select_Ok( void )
{
    int port;
    int temp_port;
    
    store = ( BUFFER *)(*xcpb->Get_Buffer)();
    temp_port = Get_Active_Port();
    for( port = 0; port < Num_Ports; port++ )
    {
       Write_Port( port, store );
       store++;
    }
    Modem.cur_port = Set_Active_Port( temp_port );
    push_data();
}
Exemplo n.º 8
0
/* pop_data()
 *==========================================================================
 * Restore cancel buffer to current data
 */
void
pop_data( void )
{

   int port;
   
   store = ( BUFFER *)(*xcpb->Get_Buffer)();
   
   for ( port = 0; port < Num_Ports; port++ )
   {
         Modem.modem[ port ] = Old_Modem.modem[ port ];
         Write_Port( port, store );
         store++;
   }
   Modem.cur_port = Set_Active_Port( Old_Modem.cur_port );
}
Exemplo n.º 9
0
int main()
{
    HANDLE fd; 
    DCB OldConf;
    char cad[16]="Enviando Texto";
    int n;
    
    fd=Open_Port("COM1");               // Abre el puerto serie
                                        // fd=Open_Port("/dev/ttyS0"); 
    
    OldConf=Get_Configure_Port(fd);     // guardo la configuracion del puerto 
    
    Configure_Port(fd,B115200,"8N1");   // Configuro el puerto serie 
    
                                        // Bloqueante por defecto, pero tambien
                                        // se puede usar
                                        // IO_Blocking(fd,TRUE); 
    
    n=Write_Port(fd,cad,16);            // Escribo en el puerto serie
    
    while(Kbhit_Port(fd)<16);           // Espero a leer hasta que se tengan
                                        // 16 bytes en el buffer de entrada 

    n=Read_Port(fd,cad,16);             // Leo el puerto serie 
    printf(cad);                        // Muestro los datos
    
    Set_Configure_Port(fd,OldConf);     // Restituyo la antigua configuracion 
                                        // del puerto 

    Close_Port(fd);                     // Cierro el puerto serie 
    
    printf("\nPresione ENTER para terminar\n");
    getchar();
    
    return 0;
}
Exemplo n.º 10
0
*cdecl cpx_init( XCPB *Xcpb )
{
    OBJECT *tree;
    int    port;
    int    temp_port;
    
    xcpb = Xcpb;
    if( xcpb->booting )
    {
        /* Read in defaults and set the options */

        store = ( BUFFER *)(*xcpb->Get_Buffer)();
        Modem = save_vars;
        
        Set_Machine_Code();
	Set_Number_Of_Ports();        
	
        for( port = 0; port < Num_Ports; port++ )
        {
	   Write_Port( port, store );
	   store++;
        }
        Modem.cur_port = Set_Active_Port( Modem.cur_port );
        return( ( CPXINFO *)TRUE );  
    }
    else
    {
      appl_init();
      AES_Version = _GemParBlk.global[0];
      
      if( !xcpb->SkipRshFix )
           (*xcpb->rsh_fix)( NUM_OBS, NUM_FRSTR, NUM_FRIMG, NUM_TREE,
           		    rs_object, rs_tedinfo, rs_strings, rs_iconblk,
           		    rs_bitblk, rs_frstr, rs_frimg, rs_trindex,
           		    rs_imdope );


      Supexec( Get_OS );
      tree = ( OBJECT *)rs_trindex[ RS232 ];
      Disable( PORT );
      Set_Machine_Code();
      (( IsTT() || IsSTE() ) ? ( Enable( PORT ) ) : ( Disable( PORT ) ) );
      Set_Number_Of_Ports();
      store = ( BUFFER *)(*xcpb->Get_Buffer)();
      
      Modem = save_vars;	/* Get the Defaults and fill up all 4 ports with info */
      
      /* Get the ACTUAL system values for as many ports as possible.*/
      temp_port = Get_Active_Port();
      for( port = 0; port < Num_Ports; port++ )
      {
	Read_Port( port, store );
	store++;      
      }
      Modem.cur_port = Set_Active_Port( temp_port );
      push_data();
 
      open_vwork();
      close_vwork();
      gl_ncolors = work_out[13];

      if( !xcpb->SkipRshFix )
      {
        if(( AES_Version >= 0x0330 )
         && ( gl_ncolors > LWHITE ))
        {
          tree  = (OBJECT *)rs_trindex[RS232];
	  MakeActivator( RS232, SAVE );
	  MakeActivator( RS232, RS232OK );
	  MakeActivator( RS232, RS232CAN );
        }
      }   
      
      
      
      cpxinfo.cpx_call   = cpx_call;
      cpxinfo.cpx_draw   = NULL;
      cpxinfo.cpx_wmove  = NULL;
      cpxinfo.cpx_timer  = NULL;
      cpxinfo.cpx_key    = NULL;
      cpxinfo.cpx_button = NULL;
      cpxinfo.cpx_m1 	 = NULL;
      cpxinfo.cpx_m2	 = NULL;
      cpxinfo.cpx_hook   = NULL;
      cpxinfo.cpx_close  = NULL;             
      return( &cpxinfo );
    }
}