Files
Driver-tutorial/ioctl/ioctl_app.c
2025-02-24 17:45:02 +00:00

35 lines
765 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "ioctl_const.h"
int main(){
int fd;
int32_t value , number;
printf("\nOpening Driver\n");
fd = open("/dev/demo_ioctl_device", O_RDWR);
if( fd < 0 ){
printf("Cannot open device file...\n");
return 0;
}
printf("Enter the Value to send\n");
scanf("%d", &number);
printf("Writing Value to Driver\n");
ioctl(fd, WR_VALUE, (int32_t*) &number);
printf("Reading Value from Driver\n");
ioctl(fd, RD_VALUE, (int32_t*) &value);
printf("Value is %d\n", value);
printf("Closing Driver\n");
close(fd);
return 0;
}