Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
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?


  Search this Thread
Old 01-27-2007, 06:38 AM   #1
LQ Newbie
Registered: Dec 2006
Posts: 17

Rep: Reputation: 0
Thumbs up Serial Mouse is attached or not attached at seiral port

I want to know which device is attached at the serial port.

Now, Suppose I attach a serial mouse at COM Port 1.

I want when I attach serial mouse I can detect that serial mouse is attached at serial port and

when I just remove serial mouse from the serial port I can detect that mouse is not attached at the serial port.

Now the procedure is that if I connect Mouse at the Serial Port it just send character 'M' after 14 ms for 2 - Button Serial Mouse and after another 63 ms it will send '3' for 3 - Button Serial Mouse.

To read the character send by the mouse I have to use the read function.

But this function I have to use only when mouse send some data to the serial port.

If no data is send from the mouse and then also if I try to read it then the program is just hang from that moment.

So with the help of select function and read funtion I can detect the serial mouse at the serial port.

My problem is that How data is send from the mouse that I do not know.

So If I know the exact way if data is coming from the mouse or not then my problem is over.

Let us view a simple program :

/************************************************** **************************/


#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>


int main()
int fd; /* Input Sources */
fd_set readfs; /* File Descriptor Set */
int loop=0; /* Loop While TRUE */
int res;
struct timeval Timeout;
char *device = "/dev/ttyS0"; /* COM1 */

/* Opens a Device, Sets The Port Correctly, and Returns a File
Descriptor */

fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); /* OPEN DEVICE AT PORT COM1 */
if (fd == -1)

/* Loop For Input */

while (!loop)
FD_SET(fd, &readfs); /* Set Testing For Source */

/* Set Timeout Value Within Input Loop */

Timeout.tv_sec = 0; /* Seconds */
Timeout.tv_usec = 250000; /* Microseconds */
res = select(fd+1, &readfs, NULL, NULL, &Timeout);
if (res > 0)
printf("\nNow you are ready");
loop = 1;
printf("\nTill You are not ready");
return 0;

/************************************************** ****************************/

So if data is available from the mouse then the message is that Now you are ready and if there is no data then Till You are not ready message is continously on the screen at the given time interval.

So what should I have to do to come out the loop when data is just received by the select fucntion or not to come out the loop when there is no mouse and then data is not received by the select function.

Please do the needful.

Any good suggestion will be appreciated.

Thanks in advance.
Old 01-28-2007, 08:21 PM   #2
Registered User
Registered: Dec 2006
Posts: 1,454
Blog Entries: 1

Rep: Reputation: 74
No offense intended, but it sounds like you're trying to re-invent the wheel. And IMHO, it probably just won't work.

First, the serial mouse does not send anything. It is read by the device driver.

Secondly, it is not a PnP device; it is only detected at system startup. IOW you can unplug and replug the serial mouse at will and BIOS nor the OS will recognize that.

Lastly, if you could write a program that persistantly monitored the serial port for device connection/disconnection, it would be painfully slow, as it would need to constantly be jumping back into the detection loop.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
pl2303 attached to ttyUSB0 but driver attached to device is "serial" sheeluh Linux - Software 4 03-12-2007 05:27 AM
How can I say mouse is attached or not attached at the serial port ? lovelylinux Linux - Hardware 1 02-07-2007 10:44 AM
Serial attached SCSI support? krish240574 Linux - Hardware 1 03-20-2005 11:29 PM
linux locks up when usb mouse attached to usb port during startup. BGuy891653 Linux - Hardware 0 02-08-2004 06:26 PM
Sending commands and viewing replies from a serial-attached appliance bgianardo Programming 3 01-19-2004 12:00 PM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 01:25 PM.

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