LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 08-30-2005, 04:23 PM   #1
PFudd
LQ Newbie
 
Registered: Mar 2004
Posts: 17

Rep: Reputation: 2
How do I beep PC speaker without a console?


Hi...

I have a linux firewall that sits in a closet in a dark forgotten basement. It doesn't have a graphics card, so I've made the console be the serial port.

In a previous project on a different computer, I was able to make the console beep a couple of times at a different frequency when it had successfully booted. Unfortunately, that required a normal vga console to make it work.

If I do "/bin/echo -e \\a > /dev/console", it shows up as data on the serial port.

I've got the pcspkr module loaded, and it shows up in /proc/bus/input/devices, but now what? What device do I have to open and what ioctl do I have to run, or alternatively, what program do I download and run?

Thanks!
 
Old 08-30-2005, 06:52 PM   #2
PFudd
LQ Newbie
 
Registered: Mar 2004
Posts: 17

Original Poster
Rep: Reputation: 2
Lightbulb Solution!

After much searching and sending email to the maintainer (Vojtech Pavlik), a solution was found!

Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/kd.h>
#include <stdio.h>

#define ERROR (-1)

main() {
  int fd=open("/dev/tty0",O_RDWR|O_NDELAY);

  if (fd<0) {
    perror("/dev/tty0");
    exit(2);
  }

  /* 125 = 125 milliseconds, or 1/8th of a second;
      0x637 is the number of clock cycles in the standard kernel beep */ 
  if (ioctl(fd,KDMKTONE,(125<<16)+0x637) == ERROR) {
    perror("/dev/tty0: ioctl");
    exit(2);
  }

  close(fd);
}
Initially this was tried with /dev/tty and /dev/console, and it didn't work with either of them. Only /dev/tty0 worked, and even that would not have worked if CONFIG_VT was disabled in the kernel configuration.

Many thanks to Vojtech!
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make pc speaker beep in slackware vrillusions Linux - Hardware 5 03-02-2010 10:15 PM
obsd: constant pc speaker beep with gigabyte board Fonk *BSD 0 09-26-2005 03:07 AM
Incredibly annoying pc speaker beep on error in MySql in Windows XP nazdrowie Programming 2 07-15-2005 01:26 AM
FC3 no console beep Soabirw Linux - Software 2 06-21-2005 04:22 PM
Disable the console beep? csvke Linux - General 6 03-01-2004 04:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 04:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration