kopia lustrzana https://github.com/Hamlib/Hamlib
added read_sleep
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@34 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.0.1
rodzic
d594c0415a
commit
81be478743
|
@ -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 */
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Ładowanie…
Reference in New Issue