mirror of
https://github.com/Hizenberg469/Driver-tutorial.git
synced 2026-04-20 00:42:25 +03:00
35 lines
765 B
C
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;
|
|
} |