LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Wake-on-ring and null-modem (https://www.linuxquestions.org/questions/programming-9/wake-on-ring-and-null-modem-308390/)

NovHak 03-31-2005 07:19 PM

Wake-on-ring and null-modem
 
Dear forum members and contributors,

A friend of mine is far away from home where he needs to boot his computer remotely. This computer is connected to a running one via a null-modem cable. Assuming his computer has the wake-on-ring feature enabled, and the pins no. 9 of each computer are connected via the null-modem cable, is it possible to set pin 9 of the running computer so that it wakes the other one?

Here's the program I wrote to achieve this:

Code:

#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>

char *procname;

int open_port (char *device)
{
        int fd;

        fd=open(device,O_RDWR|O_NOCTTY|O_NDELAY);
        if (fd == -1)
                perror(procname);
        else
                fcntl(fd,F_SETFL,0);

        return(fd);
}

void ring (int fd)
{
        int status;

        if (ioctl(fd,TIOCMGET,&status))
                perror(procname);

        status|=TIOCM_RNG;

        if (ioctl(fd,TIOCMSET,&status))
                perror(procname);
}

int main (int argc,char *argv[])
{
        int res;

        procname=argv[0];
        if (argc != 2)
        {
                fprintf(stderr,"%s: Wrong number of arguments!\n",argv[0]);
                exit(1);
        }
        res=open_port(argv[1]);
        if (res == -1)
        {
                exit(2);
        }
        ring(res);
        close(res);

        exit(0);
}

Am I good on this one?

Olivier

HazByn 06-29-2009 01:47 AM

Hi there,

How do i test WOR (wake on ring) could someone provide me the correct steps?.I have to machine A (Ubuntu) and B (Ubuntu) and connected via null modem cable.

NovHak 06-29-2009 08:43 AM

Try to compile and execute the code I posted in this thread. Maybe it will work... You have to put the device filename as its only argument.

Hope this helps !

theNbomr 06-29-2009 12:24 PM

The RI pin of a PC serial port is an input. As such, you cannot control it, only read its status. If the peer computer is properly configured, you should be able to wake it by asserting the RI input. You can do this by cabling the RI input of the sleeping computer to one of the pins that are controllable outputs of the controlling computer. Those pins include DTR and RTS. You would then programmatically assert the pin using the TIOCMSET ioctl() call.

Most commercially available cables that I have seen do not use the RI pin. You may have to get a cable made or make it yourself. If the application requires only the 'wake-up' function, then your cable should only require two conductors: RTS or DTR, and a signal ground.

--- rod.

NovHak 06-29-2009 06:50 PM

Thanks Rod, interesting answer ! Funny that it comes more than four years later :)

theNbomr 06-30-2009 08:00 AM

Hmmm. I see. I saw the new response by HazByn, and didn't bother to check the date of the original post. Bad on me for responding to a hijacked thread.
So, did you ever get your scheme implemented?

--- rod.

NovHak 06-30-2009 09:20 AM

IMHO it's a good thing that you replied, since you gave me the answer I was looking for. Eventually I don't remember we managed to have a working WOR and my program didn't work, which is normal according to your answer. Next time we will make a custom cable !


All times are GMT -5. The time now is 09:53 PM.