Sending single commands to a maya node - python

I'm planning on creating a maya node that pulls some input from a serial port or some other kind of real time input. Each time I wish to receive input I must have an open connection to a unix file like unix, so far so simple.
My question is this, how do I send the maya node a one time command like connect or disconnect. I only know how to set up a simple 'attribute effects' stye relationship between attributes which isn't quite right for this situation. The only solution i could think of would be to add a non animatable boolean attribute to the node and run the connect disconnect methods whenever that attribute was changed, does this seem like a sensible solution?

If your goal is to support an external controller, there are a lot of examples on the net that use the commandport as an interface to external controllers. The clockServer example that comes with the Maya SDK shows how it can be done; and as an example of how to conver that into There's also Dave Moore's hacked up Xbox 360 controller server based on the clock server here that might give you an idea how to tackle it.

Related

Writing and routing over ethernet without IP

I have a project in which I need to setup a network that is essentially a bunch of Raspberry Pis connected through a router over ethernet, and have them talk to each other without using IP.
My challenge here is two folds, first, how can I write raw binary data to ethernet to pass my own custom payloads and have a custom parser on each end picking up and deserialising that data?
Second, and this is secondary for this post, if anyone has any ideas as to how I could use a router without using IP (aka setting up my own simple addressing protocol) this would be very welcomed. So far what I've sketched out is to procure myself a router than can be flashed, then have custom software on there running a custom protocol. However I'm not sure if this is even doable with off the shelf routers. Pointers are welcome.
Ideally I'd like to do all of this in python.
For your first question: asyncio comes as a standard library with Python. It can handle most of your communication needs, essentially acting as your communication stream for your binary data. Example implementation here.
For your second question: you can't go wrong with using IPv4. You could potentially implement something new but you'd probably go down a rabbit hole in doing so.

Control hardware (a Raman spectrometer) using Python

I have an old Raman spectrometer (one of these - http://www.camo.com/downloads/partners/deltanu/Inspector_Raman_Datasheet.pdf) and I'd like to write code, ideally in Python, that can provide it with input parameters, operate it and receive data from it.
The spectrometer connects to a PC via a USB, although it is assigned to a virtual COM port. I currently control it using an .exe file provided by the company that used to sell it, that I believe was produced using LabVIEW.
Is it possible to write my own code to control this sort of hardware? How can I pass parameters and commands to hardware? What information would I need to know to do this?
Although I'm a fairly proficient Python coder, this is a brand new area for me, so any advice on where to start would be super appreciated. I'm open to coding in another language if that would be more appropriate. And let me know if I need to provide any more info.
Cheers, Liam
A google search for the device model name and "programming manual" is usually where I start with something like this. Those keywords hopefully turn up something from the manufacturer that tells you how to do exactly what you're trying to do, and a lot of them include code samples. Unfortunately, with the little information I have on your device, I couldn't find anything. That's going to make it much, much harder.
Everything beyond this point is a guess based on what I've seen before. Typically, if a LabVIEW program interacts with a device over a virtual COM port, the program sends an ASCII command to the device using the protocol defined in the manual, and then receives ASCII data in return. You can try sniffing that data with the NI I/O Trace tool (http://www.ni.com/download/ni-io-trace-14.0.1/4914/en/) while running the manufacturer's application, and then trying to make sense of the flood of data that you see on that port.
It could also be a Modbus device, which may help you figure out the structure of the communication.
In short, this'll be tough without a programming manual, but there is some hope. Good luck!

How to identify a device broadcasting data over a specific port using Python?

Summary
I have set up a udp packet listener in python, and I would like to be able to identify the device that is broadcasting the data it receives.
The Goal
I have a PHP web page that is reading the data from a database, which is being populated by the listener inserting the data when it receives it. My goal is to have a toggle switch that allows the user to select which device to hear data from. So currently, data is only being broadcast by either an MT4000 telemetry device, or using the terminal to manually send data across port 30000.
I don't want to identify it from a specific serial port, as described in: Identifying serial/usb device python
But rather wherever it is connected (any serial ports).
My Method
My idea at the moment is to somehow, send a message back to the same device from the listener, acting as both an acknowledger, and as a scan, to ask what the device is. Is that a feasible way?
Problems
Increases the amount of data being transmitted massively with more back and forth packets.
It may not work for every device connected, methods of extracting identity may be different for each device.
Once the python has identified the device, I will insert into the database, and when the user selects a device, a modified query will be sent, ie
("SELECT * FROM table WHERE device = MT4000");
I feel that this is not a clean method to use, and would be very open for different suggestions.
The solution
Unless it helps get across an answer, I'm not looking for specific code, but rather the theory of the task.
You may want to look into the way that nmap performs service detection. It is my understanding that it uses several different approaches and then takes the best match available. Those different approaches include:
What port the service is running on
What welcome banner the service provides for an initial connection
What OS the server runs (and thus what services could possibly run on that server)
You can read more about this in the service and application detection chapter.
Since you are also receiving data from these devices you can look at that data to determine what type it is. The file command on linux is a tool that performs a similar function, and that can determine the type based on:
File extension (obviously inapplicable here)
Magic numbers that appear at or near the start of the file
The composition of the data (mostly binary, or mostly ascii/unicode/etc, byte endiness and so on)
The underlying functionality of the file command is available as libmagic, a C library. It would be worth trying to use that directly, rather than duplicating it's functionality.
It's worth pointing out that a lot of these techniques provide statistical probabilities rather than certain answers. This may mean that you have to deal with a degree of uncertainty in your results, leading to misclassifications. To mitigate this you can collect data until you are sure enough that the device providing the data has been correctly identified.

making IM program - am novice - how to connect to individual computer, not on LAN- using Python 3.2?

I was wondering if you could help me with some programming. I'm trying to write a chat program but i'm stuck. I can use LAN easily enough, but I cant do it over WAN / the Internet as an external IP-address only refers to the Lan/router. how can you connect to one computer in particular?
I'm trying to write in Python, but ive ran into a problem. i'm using a very basic client-server system using the socket module for both (so far).
The problem i'm having is that, while connecting over LAN is easy enough, i need to connect over the internet to one computer. This is because the external IP is only referring to the router. I know i could use probably port-forwarding but i was wondering if there was a way to reach the individual computer without the user manipulating router settings.
There's something called NAT Traversal. But it's not standard at all and there are may ways to do it, depending on the router vendor and other things. So it's a very complex thing to implement in a generic manner.

Keyboard input using stdio.StandardIO in twisted python

I have a doubt in twisted python related to my multiclient chat server program.
that is, when we give input from keyboard using stdio.StandardIO, where it is stored when we run the reactor? Can anybody give me the answer, please..
twisted.internet.stdio.StandardIO doesn't "store" data anywhere. It is a transport which you associate with a protocol. The protocol you associate with it can do anything you want with the data delivered to it.
You can find two examples of using StandardIO in the Twisted documentation, https://twistedmatrix.com/documents/current/_downloads/stdin.py and https://twistedmatrix.com/documents/current/_downloads/stdiodemo.py.

Categories