Read/Write Audio Data to Modem in OS X or Linux - python

I'm working on a program in Python that, for now, is on my iMac with OS X, but if I had to, I could move it to a Linux box on a Soekris box. Also, if there's a way to do this with a command line program or a C library I can easily access from Python (still not sure how to do that, but I hear it can be done), I'm open to that. But if it's possible to do it in Python on OS X, that would be preferred.
I have a simple (as of now) Python program for working with my modems. It handles incoming calls with caller ID info and taking faxes on my fax line. I would love to be able to add voice mail - nothing complex, but just being able to play back an outgoing message and record an incoming one.
But I'm having trouble finding any information on how to read or write audio data with a modem device on either OS X or Linux.
Is there anything good on handling audio data with modems on OS X or Linux?

Related

Is there a way to read incoming Windows notifications with python?

I would like to write a python script that listens to all incoming windows notifications and returns their content, so far i found nothing that works with python and would like to know if it's even possible.

How to send/receive data from a usb port with python

I am designing an FPGA for a college project and we need to send data to an FPGA, so we wanted to use USB cords and a python program to manage sending/receiving/displaying information on the computer sending/receiving data from the FPGA.
I've never really written anything to send data to external devices other than when using putty and an atmel avr microcontroller for a previous class, so i'm not familiar with how USB works. If anyone knows how to do this in python, as well as any issues i need to be aware of that would be great. I'm using Python 3.7 and working on a windows 10 laptop.
Edit: some clarification on the project itself. We are using the FPGA as an encoder. The fpga will have modules that perform the encoding and other stuff, but the python program itself only needs to ask the user for an encoding method and get said data to be encoded, then append bits to the data that will allow the FPGA to identify the encoding method, then send the data out to a usb.

Remotely sending inputs to a running Python script

I'll try to be as clear as possible with what I'm trying to aim for.
I have a running Python script on my Raspberry Pi and I'd like multiple users to send inputs to the script remotely (through SSH or anything else that might work better).
So for example if I have this script running:
Name = input ("Please type in your name. \n")
type (Name)
print ("Hello there" , Name)
time.sleep(3) # Pause for 3 seconds.
I want users to send names to this script remotely from devices that are connected to the same network as the Raspberry Pi.
If possible, I also want to implement the following functionalities:
Sending the output (aka the printed text) back to the specific device the input came from.
A queuing system: If multiple users send names at the same time, the script will take the names in order, one by one.
I know it's a lot to ask for, but I'd really appreciate if someone could help me get started with this by pointing me in the right direction. I've searched around quite a bit for the past few days but I haven't really come across anything that fits my needs.
Edit: I'm running this on PYTHON 3
Your comment that you would like to communicate (via network) to the script directly, opens up a world of possibilities. You have to modify your Python script a little though, because it won't communicate via stdin/stdout any longer.
I'm still not entirely sure how you want things to work but it does sound to me that a solution based around RPC can possibly work for you. May I suggest you have a look at Pyro4? Basically what that does for you is enable you to do normal Python method calls, but over the network, to code running on another computer.
So you can set up a server on your Pi (that needs to run continuously) which accepts remote calls from other computers, and can then call into your python code on the pi. It can process calls in parallel or in sequence. You didn't say if you need any form of security, but some basic security features are provided (no built-in encryption or communication over TLS yet, sorry).
A simple example is here and lots more are on github so you can have a look to see if this fits your requirements?
Another solution that doesn't require third party libraries is perhaps to write a WSGI http server that calls your script, run this on the pi, and access it via HTTP from your other computers.

Python: get keyboard input from MagStripe reader

For my DIY access control system, I'm running Debian on a Raspberry Pi attached to a MagStripe card reader. When a card is swiped, the reader writes the data from the magnetic stripe over the USB port by acting like a keyboard. For example, plug it into your computer, open a text editor, and swipe a card and you'll see a string of data printed out like you typed it with your keyboard.
Simple connection diagram:
Client <--ssh--> Host + card reader
The only problem is that I'm running my Python script over ssh, which doesn't directly hear the keyboard input.
How can I get Python to listen to the keyboard events coming from the MagStripe reader? (do I need to use a keylogger? PyGame's keyboard bindings?)
Thanks for the help!
On Linux, USB keyboards can be accessed via /dev/input.
See: format of /dev/input/event*? - the answers to that question include two different Python modules for getting events, and links to more documentation.
To translate from key codes to ASCII, see How can I translate Linux keycodes from /dev/input/event* to ASCII in Perl?
You will probably need to be root, or change the permissions on /dev/input.
It may be worth dividing the program into a two pieces: one as a service that starts at boot time on the raspberry pi which will get its stdin from your keyboard device(the reader) by default, and another that provides remote access functionality over ssh. This way you can avoid having to deal with devices in /dev directly.

How can I detect when a flash drive is plugged in under Linux?

How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?
Bye
falstaff
All mayor Linux distros include udev, that allows you to write custom scripts on hardware events.
You can read uevents from kernel via a Netlink socket and look for events where "ACTION" is "add" (you can also watch if a partition from a device was mounted or unmounted, or if a device is being removed). That's as close to the source of events as one can get in user space. As far as I know, this is how udev detects inserted removable media.
But probably using D-Bus/HAL API via Python bingings will be much easier (no uevents data parsing, etc). Not sure why you are opposed to this. Since you are using Python, I suspect that resources are not really the issue.
If you are targetting an embedded device, then you can run mdev instead of udev.
Then you can write mdev rules that are quite simple and triggers a script.
Of course you are not directly monitoring from your script, mdev is doing it, but you can launch any command. You can probably do the same thing with udev, but it always looked quite complicated to me.
When an USB device is plugged in syslog writes messages concerning this to /var/log/messages. The "dmesg" command shows this log. You can check near the end of the log to see which channel the device was attached to, it is usually /dev/sd(letter)(number) depending on the partitions and number of serial disks plugged into the system.
/proc/partitions shows all the partitions known to the kernel.
I did this using zenity in a script and udev with rule on rhel6 with:
KERNEL=="sd[b-d]", DRIVERS=="usb", ACTION=="add", RUN+="/path/to/script"

Categories

Resources