T
T
TheBigBear2021-12-10 13:38:35
Electronics
TheBigBear, 2021-12-10 13:38:35

How to make it as easy as possible to launch a program on a computer by pressing a mechanical button?

Hello!
It is necessary to implement the following task
When you press a button (or using an alarm relay), you need to run a batch file for execution on a Windows computer. What is the easiest (cheapest) way to do this? Or in which direction to dig?
Now I did this: I found an ancient IP camera in DI with an input to which I attached a button. When DI is closed, the camera sends an email. There is a rule on the computer that if a letter arrives from a certain mailbox - run a batch file.
But there are disadvantages:
Long timeout.
Failure when there is no internet or mail server failure
And yes, technically the button and the computer are next to each other

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
lonelymyp, 2021-12-10
@TheBigBear

there are pedals https://aliexpress.ru/item/4000030684962.html you can pick out from there if the design does not fit
pretends to be a keyboard and you can assign a combination in a standard way like Ctrl + alt + button to start your program.
it seems like big red buttons used to be sold, but I didn’t find it right off the bat. There are also mini-keyboards for 4 buttons
))

H
hint000, 2021-12-10
@hint000

https://www.google.com/search?q=big+button+usb&tbm=isch
You can also take a keyboard with additional buttons, solder wires to contacts, for example, buttons e-mail, attach a large button and assign the desired program in Windows settings instead of an email client. And no programming. :)
CiCYi.jpg

A
Armenian Radio, 2021-12-10
@gbg

Compport or USB-UART converter, connect via CTS relay to ground.
When the relay is triggered, the state of the CTS will change. It can be considered as the following C++ code

DWORD dwModemStatus; 
BOOL fCTS = 0; 

if (!SetCommMask(hSerialIn, EV_CTS)) 
{ 
    DWORD err = GetLastError(); 
    printf("\nHandle creation error code: %x\n", err); 
} 

DWORD dwCommEvent; 

while(1) 
{ 
    if (!WaitCommEvent(hSerialIn, &dwCommEvent, NULL)) // An error occurred waiting for the event. 
        printf(""); 
    else 
    { 
        if (!GetCommModemStatus(hSerialIn, &dwModemStatus)) // Error in GetCommModemStatus; 
            return; 
        fCTS = MS_CTS_ON & dwModemStatus; 

        if(fCTS) 
            printf("%x ", fCTS); 
    }  
}

Copied from here

A
Alexey Kharchenko, 2021-12-11
@AVX

Organizationally, this is solved as follows - the PC must have a driver that controls a device, or in this case, looks at the state of the device and does what it is given by the algorithm. But it is quite possible to get by with any application program for low speeds, and listen to any low-speed port - COM, LPT. For example, as suggested, listen to the state of some signal on the COM port, and do the necessary actions. In addition to the button, you need to make an interface device between the button itself and the PC in a good way. For example, the PC will watch the COM port or LPT, and the device will switch the trigger inside by pressing the button, and return its state either by timeout (for example, 0.3 ... 0.5 s, but at least 10 seconds), or by a signal from a PC (the driver or program on the PC saw that the signal status had changed, did what was needed,

spoiler
В древние времена (в начале 2000х) делал на коленках через LPT порт и программку на QBASIC небольшую управление через датчик освещённости (да обычный фоторезистор), свет в комнате включился - выполняет одни действия, выключился - другие. Ничего сложного особо. На выход тоже делал через LPT управление громкостью звука на через самодельный цифровой регулятор громкости, подключенный к LPT опять же.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question