Connect two devices using DDS on Lan - python

I came up with an idea to establish connection between my Raspberry Pi 4 and Windows host machine. I did it successfully by utilizing MQTT protocol, but got interested in Data Distribution Service concept (DDS). My Pi needs to send captured images (publish) to windows machine (subscriber) as byte array. How to do this easily for prototyping and testing purposes? I don't have a problem with doing this on same machine, but cannot wrap my head around connectivity between nodes on same LAN network, I know for sure that DDS supports TCP and UDP. Is there just an config file where I have to put IP addresses of second machine for both applications and that's it? I want to use RTI Connector for Python, can it work on its own for both devices that communicate? Sorry for lame question, but I just want to test DDS utility as fast as possible. Can anyone point me to some sources that would help solve my case? I've seen some articles, but none were clear to me.

Most of the answers that you're looking for can be found on community.rti.com.
But fundamentally, you should be able to run DDS between your Raspberry Pi and Windows box easily...and the helloworld should run with no configuration required (Connext DDS uses multicast for discovery by default)...as long as you have disabled the firewalls on your Linux (assuming you're running Linux on the Raspberry Pi) and on Windows (usually not needed if the network type is configured to be private).
If you want to use Python as the programming language you can either use the new Python API for RTI Connext DDS,
or as you mentioned, RTI Connector for Python (although this will be deprecated since RTI has released the Python API).
Examples are provided in the distributions of both the Python API for Connext as well as RTI Connector (with documentation).
You will need to understand a bit about DDS to modify the examples to use your own data type. Basically it means defining your data type in IDL and then using rtiddsgen to generate the XML definition of the datatype from IDL...or you can directly create your datatype definition in XML.
[I tried to add a bunch of links to the documentation, examples, etc., on github/rti.com/community.rti.com, but it got flagged as SPAM]

If your datatype is a fixed size array, then you should use the IDL fundamental datatype of octet[]. If it's variable sized, then you need to use sequence, either
struct MyImageType {
octet imageFrame[1048576];
};
or
struct MyImageType {
sequence<octet, 1048576> imageFrame;
};
using the above in an IDL file and then using rtiddsgen will be easier than typing the equivalent XML definition into a file.

Related

Programmatic access to Brother ADS-1000W

I've got a Brother ADS-1000W receipt scanner and using the ControlCenter4 software it works great. However I would like to be able automate the scanning process and I can't find any pointers/clues on where to get access to the ADS-1000W specific features. With the ControlCenter4 software, I can have the scanner deskew images. It also scans to an arbitrary length and width (matching the scanned receipt). I'm assuming this is being handled by the scanner, but it may be happening in the ControlCenter4 software. These features specifically don't seem to be accessible in the TWAIN interface. I tried using TWAINCommander 3 and it doesn't show the deskew and arbitrary size features in the TWAIN interface.
I've got both Linux and Windows machines available and I'm cool with a commandline solution or an SDK that I have to write software to implement. If it's an SDK, I prefer Python.
I know this is somewhat open-ended, but hoping someone can point in a direction for further research.
Just in case anyone else stumbles across this question: The ADS-1000W supports scanning to FTP. If PDF is selected, then the scanner supports the de-skew option, so I installed vsftpd on my linux box and used Python to process the files as their uploaded.

How do I connect/disconnect/configure a wireless network in python?

I'm looking to see if there is a way to connect or disconnect to a wireless network in python, preferably a way that would work for both public and secured networks if I supplied the password. If I can configure the options about wireless, that would be an added bonus (ex. see all networks in range, see information about networks in range (like encryption type)). I run a windows computer, so I see many answers to this question in Linux, or other operating systems, but none in windows. Thanks in advance.
You'll probably have to use one of the DLLs in windows for that. Using ctypes you can get access to the win32 API from Python.
It looks like the functions from wlanapi.dll, starting with WlanOpenHandle and WlanEnumInterfaces might do what you want.
Edit: For example code, see the accepted answer to this.

put interface down in windows with python?

A friend asked me for a program to switch his integrated wifi card off and on. I've googled it with no luck. Can someone tell me if there's any way to do that natively in python?
Does the solution have to be native? I would use a utility called 'devcon' which is created by Microsoft. You could use Python to call devcon and parse the output and disable the required device(s).
Here's an example:
http://en.kioskea.net/faq/1886-enable-disable-a-device-from-the-command-line
You can get the list of network devices with
devcon hwids =net
You can try to parse the one with WiFi in it and the lines that start with PCI.
Or you can do something like:
devcon disable hwids =net, unfortunately this disables the ethernet devices as well.
If you need to just disconnect from WiFi you can use netsh wlan disconnect
EDIT: Ok, finally found the perfect solution (IMHO).
You will need to install two packages pywin32 and wmi.
Using WMI (Windows Management Instrumentation) bindings for Python this becomes pretty easy.
import wmi
cur=wmi.WMI()
wireless_devices=cur.query("select * from Win32_NetworkAdapter WHERE NetConnectionID = 'Wireless Network Connection'")
for device in wireless_devices:
device.Disable()
If it returns a tuple with the first value of (0) it succeeded. Obviously, this must be run as an administrator (otherwise you will get 5 as the return value).
If there is a way to do it from the win32 API in C/C++ (I honestly don't know), then you can use the pywin32 bindings to do it from Python.

Is there a way to "compile" Python code onto an Arduino (Uno)?

I have a robotics type project with an Arduino Uno, and to make a long story short, I am experimenting with some AI algorithms. However, I need to implement some high level matrix algorithms that would be quite simple using NumPy/SciPy, but they are an utter nightmare in C or C++. Even with the libraries out there, this is just getting ridiculous.
Is there any way I can do this project in Python? I think I heard something about the Mega having this capability, but I have an Uno, and replacing it is not an option at this point (that would set the project back quite a bit.) Also, I heard somethings about using Python to communicate to the Arduino via USB, but I cannot have the USB cable in while the thing is running. I need to be able to upload the program and be done with it.
Are there any options out there, or have I just reached a dead end?
There was a talk about using Python with robotics at this years PyConAU called Ah! I see you have the machine that goes 'BING'! by Dr. Graeme Cross.
The only option he recommended for using Python on a microcontroller board was PyMite which I think also goes by the name of Python-On-A-Chip.
It has been ported to a range of boards - specifically he mentions the Arduino Mega which you said is not an option for you, but it is possible it is supported on other Arduino boards.
However, because it is a "batteries not included" version of Python it is more than likely that you will have a real problem getting numpy/scipy etc up and running.
As other posters have suggested, implementing in C might be the path of least resistence.
Update: again, not specifically for Arduino, but pyMCU looks to provide python on a chip. The author states he may look at developing an Arduino version of pyMCU if there is enough interest.
I've started work on a "Little Python" to C++ (called Pyxie - a play on Py CC- Pyc-C) compiler, with the specific aim of compiling a sane subset of python to C++ such that it can run on an arduino.
This is far from complete at time of writing (0.0.16), but it can currently compile a very small subset of python - enough for the arduino "blink" example to run. To support this, it has a compilation profile - which essentially means "compile using the arduino toolchain."
A program it can compile looks like this:
led = 13
pinMode(led, OUTPUT)
while True:
digitalWrite(led, HIGH)
delay(1000)
digitalWrite(led, LOW)
delay(1000)
This parses, performs analysis (like type inference, etc), compiles to C++, which is then compiled to a hex file, which you can load onto your device.
There's a long way to go before it's useful, but it is progressing and does have a roadmap/etc.
PyPI - http://pypi.python.org/pypi/pyxie
Homepage - http://www.sparkslabs.com/pyxie/index.html
In particular a key difference from Micropython (and PyMite) is that it's designed to compile to devices too small to run either implementation. (This also means it's very different from things like ShedSkin which while a Python to C++ compiler target larger execution environments)
It's going to be difficult to get any kind of Python script running directly on the Arduino uno.Reason is that it is an interpreted language, so you will need a interpreter on-board in addition to the plain text script. There is probably not going to be enough memory for all of thatin arduino uno.
What you can do best is to find a way to compile a Python script to native machine code (this is how C/C++ works). I have seen projects around to do something like that for other platforms, but (as far as I know) none which does it successfully for Arduino uno yet.
you can visit http://www.toptechboy.com/using-python-with-arduino-lessons/ for more.
wish this will help you.
thanks!
This is not a direct solution but in your circumstances If I were you, I would write the AI program on my computer and the rest of it in Arduino. after that I would write a flask server with my AI program. and then, port forward from my router to the local machine. finally, make requests from Arduino to the server.

scripting fruityloops or propellerheads reason from VB or Python?

I have both Fruityloops and Propellerheads Reason software synths on my Windows PC.
Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code?
Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) don't seem to work. I don't think Reason or FL Studio act like standard GM Midi synths.
Update 2 : If you're interested in this question, check out this too.
Both applications support MIDI. It's just that they don't see each other.
In order to send messages via MIDI between applications, you need to install a virtual midi port.
There are several freely available, but this one works: http://www.midiox.com/zip/MidiYokeSetup.msi
You'll get a virtual MIDI output port that you can write to as if it's a normal MIDI device. In Fruity Loops or Rebirth you choose that port as the input. That's all you need to do to connect the programs.
It'll work like this:
Your Application --> Virtual MIDI Port --> FruityLoops
Note: This answer doesn't exactly answer the question you asked but it might achieve the result you want :)
You can author a VST plugin in Java using jVSTWrapper (http://jvstwrapper.sourceforge.net/). If you really wanted to use Python you could use Jython to interface to java and do it that way. Alternatively you could just write the plugin in Java or another scripting language for the JVM like Groovy.
I think both FL Studio and Reason can be configured as the default MIDI playback device. To send MIDI messages to either from VB.NET, you'll need to PInvoke the midiOutOpen, midiOutShortMsg and midiOutClose API calls. Here's a link to code samples:
http://www.answers.com/topic/midioutopen
They're for VB6, but they should be easy to translate to VB.NET.
I know FL Studio can be "driven" from a plugin authored for FL (or a VSTx plugin), but I think these are always written in C or C++.
Edit: I just learned that Windows Vista dropped the MIDI Mapper (which would have made setting up FL or Reason as the default MIDI device simple). Amazing. Here is a link I found with an alternative solution:
http://akkordwechsel.de/15-windows-vista-und-der-midi-mapper/
I just tried it out (it's just a *.CPL file that you double-click to run) and it appears to work (although the GM Synth is the only option available on my laptop, so I'm not sure if it will pick up FL or Reason as choices).
What you need is a VST MIDI scripter / scripting plugin to create a logic of MIDI events that can be sent to any MIDI channel. You would need to set a MIDI channel in FL for the VST instrument/effect you need to tweak its values. Google for it there are some plugins around and please share them back here if you find anything useful :)
You could write a Rewire host. Though, you will have to get a license (the license is free, but your application must be proprietary, so no open source).
Alternatively, you could interface through MIDI messages.
Finally, you could implement a dummy audio device which would route the audio to/from wherever you want or process it in some way.
I imagine all of these would be reasonably difficult. MIDI is probably the easiest of the three (I have no idea how easy or hard the Rewire protocol is to use).
When it comes to Reason, you can do with it to much because of it's closed architecture - you can use VST plugins (or any other type like DirectX ones) - your only option is to use MIDI.
Regarding Fruity Loops, you could write a VST plugin that can take an input from a scripting language (VB, Python or whatever) but in order to write such thing you would have to use Delphi or C++.
Alternatively, you can check out MAX made by Cycling74 - it's something like a IDE for music ;-) - and I'm pretty sure you can use Python with it.
There's an opensource music workstation, called Frinika, and you can script that in Javascript. (Insert / delete notes , change midi effects like pitch wheel etc.) It can import / export regular midi files, so it will work with Fruity loops or whatever else you have.
// Insert New
song.newLane("MyMidiLane", type("Midi"));
lane = song.getLane("MyMidiLane");
part = lane.newPart( time("10.0:000"), time("4.0:000") );
part.insertNote(note("c#3"), time("11.2:000"), time("2:0"), 120 );
part.insertNote(note("f3"), time("11.3:000"), time("1:0"), 100 );
part.insertNote(note("g#3"), time("11.3:000"), time("1:0"), 100 );
part.insertNote(note("b3"), time("11.3:000"), time("0:64"), 100 );
part.removeNote(note("f3"), time("11.3:000"));
part = song.newLane("MyTextLane",
type("Text")).newPart(time("24.0:000"), time("10.0:000"));
part.text = "This is the test text to be inserted.";
part.lane.parts[0].remove(); // remove initially inserted text-part
Another example for reading/changing notes:
lane = song.getLane("MyMidiLane");
// a lane has a fixed instrument assigned
lane.parts[0].notes[0].duration=64
lane.parts[0].notes[1].duration=32
lane.parts[0].notes[1].startTick=120
// Parts are blocks of notes that you can drag around together in the Frinika GUI.
// They're like patterns in trackers.
for (i in lane.parts[0].notes){
println("i: "+i+", n: "+noteName(lane.parts[0].notes[i].note));
println("i: "+i+", dur: "+lane.parts[0].notes[i].duration);
println("i: "+i+", startT: "+lane.parts[0].notes[i].startTick);
}
http://frinika.appspot.com/
It has a Java Webstart launcher as well, so you don't even have to
install.
It used to bundle the Javadoc documentation as well, but for some
reason their latest downloads don't include that. It's a pity, because
that's where the Javascript bindings are documented. So, now you have
to browse the source or build the Javadoc yourself. (It has some built-in examples that are accessible from the scripting window, you should check them out first. My first example is from there.)
Here is the sourcefile where you'll find the Javascript docs:
frinika Javascript doc/source
But there are other options as well. You can check out mingus too, which is a Python library for music theory and midi file handling. It requires Fluidsynth, and the demo apps require GamePython too, so it's a bit more complicated to setup than Frinika.
P.S.:
Frinika has a particular bug: when dragging around neighbouring notes, some might not sound the right length. You can help that by transposing forth and back the consecutive notes (fairly fast in piano roll view), or dragging the part that contains the notes forth and back. Restarting Frinika will also help, but that's the slower way. So this bug won't affect saved files, neither midi export.

Categories

Resources