예제 #1
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;
}
예제 #2
0
파일: zbee.c 프로젝트: mauriciojost/zig-bee
int
read_all(HANDLE fd, char* data)
{
    
    int a;
    if((a = Kbhit_Port(fd))!=0){      // Is there something to read from serial port?
        Read_Port(fd,data,a);          // Then read it and show it.
        data[a] = 0;
        //printf("Data received: '%s'\n",data);
    }
    return a;
    
}
예제 #3
0
파일: zbee.c 프로젝트: mauriciojost/zig-bee
int
Read_Port_Blocking(HANDLE fd, char* buff)
{    
    int size_to_read = 0; 
    int time_out=0;
    do
    {
        time_out++;
        Sleep(SLEEP_UNIT);
        size_to_read = Kbhit_Port(fd); /* How many bytes are available to read? */
    }
    while(size_to_read == 0 && time_out < TIMEOUT);

    Read_Port(fd, buff, size_to_read);
    //printf("Read port blocking time_out %d size_to_read %d\n", time_out, size_to_read);

    return size_to_read;
}
예제 #4
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;
}