0

Is it possible to write an API with Python so you can connect a physical ON and OFF switch via USB to a PC and when user presses the switch to ON or OFF, the python program detects it and send a signal to a web app and shows ON or OFF message on the website?

I am sorry if what I am asking its not clear enough!

BZ2021
  • 55
  • 5
  • what do you mean "a physical ON and OFF switch via USB"? Will the USB stick be a switch and not an external storage? – Foivoschr Nov 20 '20 at 06:43

2 Answers2

0

Yes, it is possible. Reading USB devices can be done with Python. In linux USB device inputs can be found in some files(e.g. /dev/ttyUSB0). By reading those files you can get the information that you need. Putting here link that will be helpful

Uzun Emre
  • 151
  • 5
0

Firstly, you can't write an API to interact with hardware in python. You would have to use the pre-existing windows API(or the API provided by the Operating system that you are using) in order to interact with hardware in such a high-level language. If you want to interact with hardware in python, and detect switch presses, releases etc, I would recommend you used a microcontroller such as a raspberry pi(for python) or an arduino(for C++). The respberry pi provides a very easy way to interact with hardware in python. If you still want to interact with a USB stick in python(but not acting as a switch) you can use the pyusb library.

Foivoschr
  • 455
  • 1
  • 4
  • 14