简体   繁体   中英

Observed difference in reading event file C and python on beaglebone black

I have used the following turorial:

http://hipstercircuits.com/capture-input-events-via-gpio-on-beaglebone-black/

This python code works by reading an event file, the file reading call is then a blocking call until an event has occurred.

After getting it to work, i created ac implementation mimicking the python code, and ran into a curiosity, when reading the file: "/dev/input/event1" in python, the following commands are used:

evt_file = open("/dev/input/event1", "rb")
while True:
    evt = evt_file.read(16) 
    evt_file.read(16) 
    #Do stuff

As said before, this piece of code is a blocking call untill an event has occured, this code then reads the content of 1 event, after doing a C implementation, i found that i needed the following piece of code for it to work:

unsigned char *buffer[8];
fp = fopen("/dev/input/event1", "r");
while(1)
{
    fread(&buffer, sizeof(*buffer), 8, fp);
    //Do stuff
}

As it can be seen in the python implementation i read 32 characters, in the C implementation i read 8, yet i have found that they both read the same amount of information from the file, since they both react excatly once per event i generate, anyone have an idea why?

unsigned char buffer[8];
fp = fopen("/dev/input/event1", "r");
while(1)
{
    fread(buffer, 1, sizeof(buffer), fp);
    //Do stuff
}

Also, check your return values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM