Click here to Skip to main content
15,887,952 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
When i runthis code igot an error for mqueue.h how can i run this program
C++
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <mqueue.h>
#include <unistd.h>

#include "../../src/UUGear.h"

int main(int argc, char **argv)
{
    setupUUGear();

    setShowLogs(1);

    UUGearDevice dev = attachUUGearDevice ("UUGear-Arduino-7853-2668");

    if (dev.fd != -1)
    {
        int pin = 3;    // analog input pin 3

        int i, value;
        float voltage;
        for (i = 0; i < 100; i ++) {
            value = analogRead(&dev, pin);

            voltage = (float)(value * 5) / 1024;

            printf("%.2fV\n", voltage);

            usleep(200000);
        }

        detachUUGearDevice (&dev);
    }
    else
    {
        printf("Can not open UUGear device.\n");
    }

    cleanupUUGear();

    return 0;
}
Posted
Updated 9-Jul-15 4:01am
v3
Comments
Dominic Burford 9-Jul-15 7:31am    
What is the error message? What line of code is throwing the error? Have you stepped through the code to see what's going on?
chandanadhikari 9-Jul-15 7:43am    
the code is not able to find 'mqueue.h'. It can find the other header files like stdlib.h and stdio.h in the proper location and can hence use the code inside these header files, but it can not do the same for mqueue.h.
So, either mqueue.h is not present on the machine at all
OR
it is at a location on the machine about which the compiler does not know(in this case you need to tell the compiler where exactly to find the header file).

You can search for mqueue.h on the system, and mention its full directory path as you have done for UUGear.h. Check if it works !!
markkuk 9-Jul-15 7:46am    
What OS and compiler are you using? mqueue.h is a Unix/Linux header and it probably won't exist in Windows systems.
Stefan_Lang 9-Jul-15 11:22am    
Looking at the third line of functional code my guess is he's programming Arduino ;-)

[edit] I have to correct myself - I wondered about said line and googled to find out what it is good for. I stumbled upon this Raspberyy PI project: https://github.com/shawnu/UUGear

This appears to be the source of the code, but it doesn't say where to get mqueue.h . I suspect, as you say, the Raspberry PI is running some Linux distro.
Sergey Alexandrovich Kryukov 9-Jul-15 11:37am    
You cannot. :-)
—SA

Go back to where you got the code from, and look for the headers and library files it need to work: it looks like you have just grabbed a bit of code and expect it to work in isolation.

mqueue.h is a header file, probably for a required library.
 
Share this answer
 
Looks like you got that code from here: https://github.com/shawnu/UUGear[^]

If so, the code is supposed to run on a Raspberry PI sporting some Linux distro. If you're trying it on some other OS or platform it probably won't work.

If you are in fact trying to make this run on a Raspberry PI using Linux, and it still doesn't work, then maybe you're missing an include path. In that case search the file and add the file location to your include path.

Otherwise you can try and contact the author: he left a link to his homepage at the bottom of the site posted above.
 
Share this answer
 
Comments
veena nair 10-Jul-15 2:59am    
Ya it is. Can u please help me to find the device id and how to a add to python program. i dont know nothing about python. i opened the voltagemeasrement.py but i dont know how to add the device id to it now when i run that program it is showing that "UUgear device is not correctly initialized . here is the code

from time import sleep
from UUGear import *

UUGearDevice.setShowLogs(0)

device = UUGearDevice('UUGear-Arduino-7853-2668')

if device.isValid():
for i in range(100):
print "%0.2f" % (float(device.analogRead(3)) * 5 / 1024), "V"
sleep(0.2)

device.detach()
device.stopDaemon()
else:
print 'UUGear device is not correctly initialized.'
Stefan_Lang 10-Jul-15 3:44am    
Sorry, I don't know python myself. If you have questions regarding the python code, you can either try to contact the author, or post a separate question with the tag 'python'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900