I'm way outside my depth here, but am attempting to utilize the IOCTL interface to hardware on a windows machine using python (via ctypes). I've done quite a bit of reading, and the call signature asks for a file handle which can be opened via the CreateFileA (link) function in the windows file API. This takes a path for the file to be opened and can be passed a "Device Name" which seems to be a "MS-DOS Device Name".
The examples given are using the \\.\PhysicalDrive0 name which I am familiar with from using tools like DISM (windows imaging), but never really knew what they were exactly. I'd like to use the IOCTL interface with some completely unrelated to disk hardware, specifically some NFC hardware but have absolutely no idea how to find out what sort of device filename I should use to target the device! This the reference I would use to talk to the NFC chip built into my target platform (Surface Go).
Am I way off the rails here? Is what I am trying to do the wrong approach/not possible?
Related
I want to establish a UART communication between an FPGA equipped with an FTD2232H chip and a PC, and for that, I am using the Python ftd2xx module. I do not know how to use the setBitMode function of this module to adjust the mode as UART.
I have written the following example code:
import ftd2xx as ftd
device = ftd.open(0)
device.setBaudRate(9600)
device.setBitMode(mask, enable)
device.write("01010101")
device.close()
How should the parameters mask and enable be chosen in order to have a UART communication?
The FT2232H defaults to a mode depending on if an EEPROM is present and the stored setup. If no EEPROM is present UART is the default. Else the setup stored in the EEPROM determins the mode. It can be UART or any other of the allowed modes. You can change the setup using FT_PROG.
If the FT2232H is in UART mode, there is no need to change anything via D2XX. Actually in that case the device can simply be opened as a com port if thethe Virtual Com Port (VCP) is loaded. The py_serial module is an easy solution to open the device in that case.
If you really want (or need) to use the ftd2xx module (note: the project page states "I don’t have time to maintain this project, so I am looking for a maintainer."), you can find the corresponding descripts in "D2XX Programmer's Guide" (Document Reference No.: FT_000071 ). However, you can only enter specific modes using the D2XX driver. If you entered one of them (e.g. to use an alternative protocol for a short time), you can issue a reset using mode = 0x0 to revert the device state to the EEPROM configurated mode. But this is a very specific use case which mostlikely does not apply here.
Since ftd2xx is simply a wrapper for the D2XX DLL from FTDI, you should consult the documentation for that.
I am building an application with python that needs to be able to connect to a scanner and process the data from the resulting pdf/jpeg/whatever. I have been trying to find a way to connect to the scanner to request a scan, but with no real progress.
I have looked around at all the options I could find, including this answer : I want to connect my program to image scanner
Most of the solutions I have found say that you need to use pyTwain, pySane, Libinsane, python-imagescanner, or the likes, which all seem to revolve around using TWAIN for Windows or SANE for Linux. I have a printer/scanner combo, but I can't find a TWAIN driver for it since it is not an 'enterprise' printer, but even then I don't know that this specific printer is what users would have, so I am looking for a more general solution.
The confusing part for me, is that I can still get the scanner to scan just fine by using Windows Fax and Scan, so I feel like there must be a way to get the scanner to receive a scan command from programs.
I don't really need much control over the scanner, just "scan the image and save the file here ___". So, is there any way to just tell Windows to send the "scan" command and save the output to a specific file that I can access? Maybe just using like a command through os.system()? (Basically, if windows can do it, can't I just use windows tools?)
A way to do this through linux would be helpful, too, but Windows 10 is the primary concern.
I cannot answer for Linux only for Windows.
The generic method to talk to a scanner is via Windows Image Acquisition.
In most cases the scanner needs some driver support and that's usually easily confirmed via MsPaint scanning (or if it is installed Fax scanning).
So first check the scanner in included in Windows Devices and either right click scan OR attempt a scan in Paint.
If you see messages like these the client is not enabled to use the scanner via WIA and you will need to install a suitable WIA driver.
Once that hurdle is surmounted then you can use a WIA-CMD-Scanner app to try to acquire the image to a file using https://github.com/nagimov/wia-cmd-scanner , it is a small 35 KB compiled VB exe.
So in my testing that scanner only returns a full platen scan 21.59 cm x 29.70 cm (it would not respect reducing the scan area with this tool.) NOTE also it only works with the first scanner, as found by Windows (You would need to modify the code for targeting a specific model).
The command that works for me (YMMV)
wia-cmd-scanner.exe /w 0 /h 0 /dpi 300 /color RGB /format PNG /output .\scan.png
Scanning to file .\scan.png (dpi = 300, color mode 'RGB', output format 'PNG')
Scan finished in 27 seconds
There is an example of setting date / using for loop in the readme https://github.com/nagimov/wia-cmd-scanner#scripting-and-automation
is snmp really required to manage devices ?
i'd like to script something with python to manage devices (mainly servers), such as disk usage, process list etc.
i'm learning how to do and many article speak about snmp protocole.
I can't use, for example, psutil, or subprocess or os modules, and send information via udp ?
Thanks a lot
The SNMP is a standard monitoring (and configuration) tool used widely in managing network devices (but not only). I don't understand your question fully - is it a problem that you cannot use SNMP because device does not support it (what does it support then?) To script anything you have to know what interface is exposed to you (if not a MIB files then what?). Did you read about NETCONF?
No, it's not required, but your question is sort of like asking if you're required to use http to serve web pages. Technically you don't need it, but if you don't use it you're giving up interoperability with a lot of existing client software.
I'm writing a program that converts OSC into MIDI, allowing OSC enabled applications (like touchOSC on my iPhone) to control MIDI enabled applications (Sibelius, Ableton Live and so on).
I'm using Python to create an OSC server and convert from OSC to MIDI. To get MIDI to the application in question, I'm outputting MIDI to the Apple IAC driver, which is then enabled as an input within the program in question.
Does anyone know of a means to programmatically configure Mac MIDI devices programmatically? In particular, I need to enable the IAC driver, which is disabled by default.
Using FileMon, I have observed that Audio Midi Setup.app modifies this file when enabling/disabling the IAC driver:
~/Preferences/ByHost/com.apple.MIDI.0017f2cxxxxx.plist
The number 0017f2cxxxxx is my system IOPlatformUUID. It's a simple XML property list, but I'm wary of writing to it directly. Even if I did, presumably I would need to cajole the midi server process into re-reading it somehow?
Finally, I'm becoming more and more aware that using the IAC driver at all is a pretty naff solution - for a start it only works on Mac! Ideally, I would write a loopback MIDI driver and all my problems would be solved...
Your hunch about writing directly to the plist is correct -- you probably shouldn't do it. I'm not 100% sure about this, but I have a feeling that the plist reflects the state of the MIDI device, but altering it will not open or close that MIDI device as you need.
To actually open the MIDI device, you could use something like pygame. I have used it for some audio-related projects, and the SDK is very straightforward and easy to work with. As python doesn't have great support for MIDI directly, this is probably your best bet (short of writing the python C module yourself, which would be rather painful).
As for IAC, it's a shame that other OS's don't come with virtual MIDI devices like this. IAC is very useful and good at what it does. So while relying on IAC for something like this would not be cross-platform, you could write an abstraction layer for manipulating the loopback device. For Windows users, you could recommend a free MIDI loopback device to be used with your software.
If you want to send OSC to MIDI then you're best off creating a Virtual Midi port in software rather trying to remotely configure an IAC. This virtual port will show up in Ableton etc so you can then have it control things programmatically.
You can do this using the rtmidi-python library (or older and slightly different pyrtmidi) - both based on the cross-platform rtmidi lib which provides for straightforward sending of MIDI Control and Notes:
import rtmidi_python as rtmidi
vmidi_out = rtmidi.MidiOut()
vmidi_out.open_virtual_port('My Virtual MIDI Output Port')
vmidi_out.send_message([0x90, 48, 100]) # Note on
vmidi_out.send_message([176, 7, 100]) # Control Change - Volume
PyGame itself uses PortMidi under the hood. If you don't need all PyGame library, maybe this can be useful for you.
As in title, what is banlist written in, or can be written in? I have a basic knowledge of Python but I don't see a way to get information from a running program.
To my knowledge, banlist uses winpcap, an open source library for packet capture and network analysis for the Win32 platforms and "understands" (at least partially) the network traffic between the game running on your computer and Battle.net servers. Regarding Battle.net protocol, there is unofficial documentation available, e.g. bnetdocs, and maybe at others places (there was even an open source implementation of a bnet server, bnetd). To reverse engineer the protocol, people used things like whireshark (or the command line version tcpdump). The principle is simple: do something (e.g. move a unit) and analyze the transmitted information.