LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   program with frame buffer (https://www.linuxquestions.org/questions/programming-9/program-with-frame-buffer-767289/)

lwhat 11-06-2009 06:53 AM

program with frame buffer
 
Ubuntu 9.10, I have /dev/fb0.
I try a tutorial c source code, and it works on the
embedded board, and works on the PC in my lab as well,
but on my own PC (Ubuntu 9.10) I met the following problem

fd=open("/dev/fb0",O_RDWR); is OK

ioctl(fd,FBIOGET_VSCREENINFO,&vinfo); always fails
My task is to draw a point or line,
and I know something about frame buffer.

JohnGraham 11-06-2009 08:47 AM

Quote:

Originally Posted by lwhat (Post 3746948)
fd=open("/dev/fb0",O_RDWR); is OK

ioctl(fd,FBIOGET_VSCREENINFO,&vinfo); always fails
My task is to draw a point or line,
and I know something about frame buffer.

I don't know much about using the framebuffer in this way, but it'd sure help if you could show the output of perror() when ioctl() fails - just do something like:

Code:

if (ioctl(fd, FBIOGET_VSCREENINFO, &info) < 0)
{
    perror("ioctl on framebuffer");
    exit(1);
}

John G

lwhat 11-06-2009 11:34 PM

Thanks, and here is the output of perror()


Error reading fixed information.
: Bad file descriptor

Then I added printf("fbfd=%d\n",fbfd);
it returned fbfd=-1;
so open() fails ,
I wondered why open() fails, as I said
I have /dev/fb0, so it lacks the right device driver?

$lsmod|grep fb
vga16fb 12456 0
vgastate 9628 1 vga16fb
fbcon 36640 72
tileblit 2460 1 fbcon
font 8124 1 fbcon
bitblit 5372 1 fbcon
vesafb 5696 1

sorry for my English, this is the first time I post on an English bbs

lwhat 11-07-2009 01:04 AM

I change to root, and it works.

$ ls -l /dev/fb0
crw-rw---- 1 root video 29, 0 2009-11-07 21:21 /dev/fb0

JohnGraham 11-08-2009 05:32 AM

Quote:

Originally Posted by lwhat (Post 3746948)
fd=open("/dev/fb0",O_RDWR); is OK

Quote:

Originally Posted by lwhat (Post 3747858)
Then I added printf("fbfd=%d\n",fbfd);
it returned fbfd=-1;
so open() fails

You always, always need to check the return value of any function you call - now that you can run the program as root you might get away with it, but put a check in for the return value of the open() command, or later on you might get led up another garden path.

On another note, you can still open the file if you add yourself to the group 'video' by placing your name on the 'video' line of /etc/group. For example, to add myself to 'video' on my system, the following line:

Code:

video:x:44:
should be changed to:

Code:

video:x:44:john
you can then make sure you're in that group by running the command 'groups', which will show you all the groups you're in.

This is a much, much safer option than running your program as root, lest you do any permanent damage to your system.

John G

lwhat 11-10-2009 01:27 AM

Thanks a lot.
Now I can draw a point, a line and a circle both on the arm board in my lab and on my own computer.
That afternoon I added myself to video group but still failed, so I turned to use sudo .
Today I ran the program without root and succeeded.
And by running the command 'groups', I see 'video'.
I add a new user ,lwhat, and add him to video group, and run 'groups', I cannot see video.
Then I log off and login ,and lwhat is in the group video and of course is able to run the frame buffer program.
I guess I should exit and login to allow the changes to happen.

richman1234 03-10-2010 08:18 AM

This is exactly what I want to do. Iwhat, can you provide some more information on how you drew a point, line and circle on the arm and PC?


All times are GMT -5. The time now is 09:59 AM.