One, read system call
Once you have a file descriptor associated with an open file description, you can read bytes from the file using the read () system call as long as the file is opened with the o_rdonly or O_RDWR flag
Function Prototypes:
ssize_t Read (int fd, void *buf, size_t count);
Parameters:
FD: File descriptor for the file you want to read
BUF: Pointer to memory block, from bytes read in file to this memory block
Count: Number of bytes copied from this file to BUF
return value:
Returns 1 if an error occurs, returns 0, or returns the number of bytes copied from the file to the specified buffer
Second, write system call
Write data to a file using the Write () system call
Function Prototypes:
ssize_t Write (int fd, const void *buf, size_t count);
Function arguments:
FD: File descriptor for the file to be written
BUF: Pointer to memory block, read data from this memory block to write to file
Count: Number of bytes to write to file
Return value: Returns-1 If an error occurs, and returns the number of bytes written to the file if the write succeeds
Three, IOCTL function
IOCTL is used to send control and configuration commands to devices, some commands also need to read and write some data, but these data cannot be read and written by Read/write, called Out-of-band data. That is, the data read and written by Read/write is In-band data, the main body of I/O operations, and the IOCTL command transmits control information, where the data is auxiliary data. For example, in the serial port to send and receive data through the read/write operation, while the serial port baud rate, check bit, stop bit through the IOCTL set, A/D conversion results through read reading, and A/D conversion accuracy and working frequency through IOCTL settings.
#include <sys/ioctl.h>
int ioctl (int d, int request, ...);
D is a file descriptor for a device. The request is a IOCTL command, and the variable parameter depends on the request, usually a pointer to a variable or structure body. If the error returns-1, if successful returns the other value, the return value also depends on the request.