File tree 17 files changed +269
-0
lines changed
17 files changed +269
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <fcntl.h>
4
+ #include <errno.h>
5
+ #include <unistd.h>
6
+ #include <sys/types.h>
7
+ #include <sys/stat.h>
8
+ #include <string.h>
9
+ #include <stdint.h>
10
+ #include <termios.h>
11
+ //#include <android/log.h>
12
+ //#include <sys/ioctl.h>
13
+
14
+ int main (void ){
15
+ int fd ;
16
+ char * adc = "/dev/adc" ;
17
+ char buffer [512 ];
18
+ int len = 0 , r = 0 ;
19
+
20
+ memset (buffer ,0 ,sizeof (buffer ));
21
+ printf ("adc ready!\n" );
22
+
23
+ if ((fd = open (adc , O_RDWR |O_NOCTTY |O_NDELAY ))< 0 )
24
+ printf ("open adc err!\n" );
25
+ else {
26
+ printf ("open adc success!\n" );
27
+
28
+ len = read (fd ,buffer ,10 );
29
+
30
+ if (len == 0 )
31
+ printf ("return null\n" );
32
+ else {
33
+ r = atoi (buffer );
34
+ r = (int )(r * 10000 /4095 ); //Datas transition to Res
35
+ printf ("res value is %d\n" ,r );
36
+ }
37
+ }
38
+ }
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <string.h>
3
+
4
+ //argument count变元计数
5
+ //argument value变元值
6
+ int main (int argc ,char * argv [])
7
+ {
8
+ int i ,j ;
9
+ i = atoi (argv [1 ]);
10
+ j = atoi (argv [2 ]);
11
+
12
+ printf ("the Program name is %s\n" ,argv [0 ]);
13
+
14
+ printf ("The command line has %d argument:\n" ,argc - 1 );
15
+
16
+ printf ("%d,%d\n" ,i ,j );
17
+
18
+ return 0 ;
19
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <fcntl.h>
6
+ #include <unistd.h>
7
+ #include <string.h>
8
+
9
+ #define BUZZER_C 2
10
+ int main (int argc ,char * argv []){
11
+ char * buzzer_ctl = "/dev/buzzer_ctl" ;
12
+ int fd ,ret ,buzzer_c ;
13
+
14
+ buzzer_c = BUZZER_C ;
15
+
16
+ if (atoi (argv [1 ]) >= buzzer_c ){
17
+ printf ("argv[1] is 0 or 1\n" );
18
+ exit (1 );
19
+ }
20
+
21
+ if ((fd = open (buzzer_ctl ,O_RDWR |O_NOCTTY |O_NDELAY ))< 0 ){
22
+ printf ("open %s failed\n" ,buzzer_ctl );
23
+ exit (1 );
24
+ }
25
+
26
+ ret = ioctl (fd ,atoi (argv [1 ]),atoi (argv [2 ]));
27
+ close (fd );
28
+
29
+ return 0 ;
30
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ main ()
4
+ {
5
+ printf ("hello wenye\n" );
6
+
7
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <fcntl.h>
6
+
7
+ #define LED_NUM 2
8
+ #define LED_C 2
9
+ //cmd为0,则灭,为1,则亮;
10
+ //io为0则是靠近蜂鸣器的小灯,为1则靠近独立按键的小灯
11
+ int main (int argc ,char * argv [])
12
+ {
13
+ int fd ,led_num ,led_c ;
14
+ char * leds = "/dev/leds" ;
15
+
16
+ led_num = LED_NUM ;
17
+ led_c = LED_C ;
18
+
19
+ printf ("argv1 is cmd;argv2 is io \n" );
20
+ //对传入的参数进行判断,超出范围直接退出
21
+ if (atoi (argv [1 ]) >= led_c ) {
22
+ printf ("argv1 is 0 or 1)" );
23
+ exit (1 );
24
+ }
25
+ if (atoi (argv [2 ]) >= led_num ) {
26
+ printf ("argv2 is 0 or 1)" );
27
+ exit (1 );
28
+ }
29
+ //使用ioctl函数将参数传入内核
30
+ if ((fd = open (leds , O_RDWR |O_NOCTTY |O_NDELAY ))< 0 )
31
+ printf ("open %s failed\n" ,leds );
32
+ else {
33
+ ioctl (fd ,atoi (argv [1 ]),atoi (argv [2 ]));
34
+ printf ("ioctl %s success\n" ,leds );
35
+ }
36
+ close (fd );
37
+
38
+ return (1 );
39
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <fcntl.h>
6
+
7
+ main (){
8
+ int fd ;
9
+ char * leds = "/dev/leds" ;
10
+ char * test1 = "/bin/test1" ;
11
+ char * test2 = "/bin/test2" ;
12
+
13
+ if ((fd = open (leds ,O_RDWR |O_NOCTTY |O_NDELAY ))< 0 ){
14
+ printf ("open %s failed!\n" ,leds );
15
+ }
16
+ printf ("\n%s fd is %d\n" ,leds ,fd );
17
+
18
+ if ((fd = open (test1 ,O_RDWR ,0777 ))< 0 ){
19
+ printf ("open %s failed!\n" ,test1 );
20
+ }
21
+ printf ("%s fd is %d\n" ,test1 ,fd );
22
+
23
+ if ((fd = open (test2 ,O_RDWR |O_CREAT ,0777 ))< 0 ){
24
+ printf ("open %s failed!\n" ,test2 );
25
+ }
26
+ printf ("%s fd is %d\n" ,test2 ,fd );
27
+ }
Original file line number Diff line number Diff line change
1
+ //标准输入输出头文件
2
+ #include <stdio.h>
3
+
4
+ //文件操作函数头文件
5
+ #include <sys/types.h>
6
+ #include <sys/stat.h>
7
+ #include <fcntl.h>
8
+ #include <unistd.h>
9
+ #include <string.h>
10
+
11
+ #define MAX_SIZE 1000
12
+
13
+ main (){
14
+ int fd ;
15
+ ssize_t length_w ,length_r = MAX_SIZE ,ret ;
16
+ char * testwrite = "/bin/testwrite" ;
17
+ char buffer_write [] = "Hello Write Function!" ;
18
+ char buffer_read [MAX_SIZE ];
19
+
20
+ if ((fd = open (testwrite ,O_RDWR |O_CREAT ,0777 ))< 0 ){
21
+ printf ("open %s failed!\n" ,testwrite );
22
+ }
23
+ length_w = write (fd ,buffer_write ,strlen (buffer_write ));
24
+ if (length_w == -1 ){
25
+ perror ("write" );
26
+ }
27
+ else {
28
+ printf ("Write Function OK!\n" );
29
+ }
30
+ close (fd );
31
+
32
+ if ((fd = open (testwrite ,O_RDWR |O_CREAT ,0777 ))< 0 ){
33
+ printf ("open %s failed!\n" ,testwrite );
34
+ }
35
+ if (ret = read (fd ,buffer_read ,length_r )){
36
+ perror ("read" );
37
+ }
38
+ printf ("Files Content is %s \n" ,buffer_read );
39
+ close (fd );
40
+ }
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <fcntl.h>
6
+ #include <unistd.h>
7
+ #include <string.h>
8
+
9
+ void main (){
10
+ int fd ;
11
+ char * uart3 = "/dev/ttySAC3" ;
12
+
13
+ if ((fd = open (uart3 ,O_RDWR |O_CREAT ,0777 ))< 0 ){
14
+ printf ("open %s failed!\n" ,uart3 );
15
+ }
16
+ else {
17
+ printf ("open %s is success!\n" ,uart3 );
18
+ }
19
+
20
+ close (fd );
21
+ }
Original file line number Diff line number Diff line change
1
+ //标准输入输出头文件
2
+ #include <stdio.h>
3
+
4
+ //文件操作函数头文件
5
+ #include <sys/types.h>
6
+ #include <sys/stat.h>
7
+ #include <fcntl.h>
8
+ #include <unistd.h>
9
+ #include <string.h>
10
+
11
+ main ()
12
+ {
13
+ int fd ;
14
+ char * testwrite = "/bin/testwrite" ;
15
+ ssize_t length_w ;
16
+ char buffer_write [] = "Hello Write Function!" ;
17
+
18
+ if ((fd = open (testwrite , O_RDWR |O_CREAT ,0777 ))< 0 ){
19
+ printf ("open %s failed\n" ,testwrite );
20
+ }
21
+
22
+ //将buffer写入fd文件
23
+ length_w = write (fd ,buffer_write ,strlen (buffer_write ));
24
+ if (length_w == -1 )
25
+ {
26
+ perror ("write" );
27
+ }
28
+ else {
29
+ printf ("Write Function OK!\n" );
30
+ }
31
+ close (fd );
32
+ }
You can’t perform that action at this time.
0 commit comments