added read_sleep

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@34 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.0.1
Frank Singleton, VK3FCS 2000-07-28 00:49:49 +00:00
rodzic d594c0415a
commit 81be478743
2 zmienionych plików z 46 dodań i 2 usunięć

Wyświetl plik

@ -5,7 +5,7 @@
* Provides useful routines for read/write serial data for communicating
* via serial interface .
*
* $Id: serial.c,v 1.1 2000-07-25 01:01:00 javabear Exp $
* $Id: serial.c,v 1.2 2000-07-28 00:49:49 javabear Exp $
*
*/
@ -164,3 +164,35 @@ int write_block(int fd, unsigned char *data) {
}
return 0;
}
/*
* Read "num" bytes from "fd" and put results into
* an array of unsigned char pointed to by "rxbuffer"
*
* Sleeps every second until number of bytes to read
* is the amount requested.
*
* It the reads "num" bytes into rxbuffer.
*
*/
int read_sleep(int fd, unsigned char *rxbuffer, int num ) {
int bytes = 0;
int n = 0;
while(1) {
ioctl(fd, FIONREAD, &bytes); /* get bytes in buffer */
printf("bytes = %i\n", bytes);
if (bytes == num)
break;
sleep(1); /* wait 1 second and try again */
}
/* this should not block now */
n = read(fd,rxbuffer,num); /* grab num bytes from rig */
return n; /* return bytes read */
}

Wyświetl plik

@ -5,7 +5,7 @@
* Provides useful routines for read/write serial data for communicating
* via serial interface .
*
* $Id: serial.h,v 1.1 2000-07-25 01:01:00 javabear Exp $
* $Id: serial.h,v 1.2 2000-07-28 00:48:40 javabear Exp $
*/
@ -13,3 +13,15 @@ int open_port(char *serial_port);
int write_block(int fd, unsigned char *data);
int close_port(int fd);
/*
* Read "num" bytes from "fd" and put results into
* an array of unsigned char pointed to by "rxbuffer"
*
* Sleeps every second until number of bytes to read
* is the amount requested.
*
*/
int read_sleep(int fd, unsigned char *rxbuffer, int num );