jkunz07 Posted March 10, 2012 Share Posted March 10, 2012 Hey I'm trying to get some information from processing into Houdini. I'd like to use the pipe in chop but I'm a little confused as to what it's looking for, the format of the information it's getting, etc. I've looked at some example code in the docs, but there all in C or C++ and I'm having some trouble knowing what to output in Processing. Any help on this would be greatly appreciated, Thanks! Quote Link to comment Share on other sites More sharing options...
edward Posted March 10, 2012 Share Posted March 10, 2012 The format is documented in the help card for the node: http://www.sidefx.com/docs/houdini12.0/nodes/chop/pipein Quote Link to comment Share on other sites More sharing options...
jkunz07 Posted March 10, 2012 Author Share Posted March 10, 2012 The format is documented in the help card for the node: http://www.sidefx.com/docs/houdini12.0/nodes/chop/pipein Thanks, I've tried to read through the docs and some examples but I'm still having some trouble understanding the fifo concept Can you create a fifo file in a java based ide, would you need a specific library? Does anyone know of any examples of doing this through Python? The Docs have C or C++ code (I'm not sure which and have little experience with this). I'd like to do something similar to this but unfortunately can't find the script used in the video to go from the python shell to a fifo file. I'm sorry I'm struggling with this, I've just been having a lot of difficulty understanding the pipe concept Quote Link to comment Share on other sites More sharing options...
edward Posted March 10, 2012 Share Posted March 10, 2012 The PipeIn CHOP has a mode to accept TCP/IP connections, and that is what you should be using. eg. (untested) esc = chr(170) nul = chr(0) def writeValues(conn, cmd): for ch in cmd: if ch == esc: conn.send(ch) conn.send(ch) def sendReset(conn): conn.send(struct.pack('cccc', esc, nul, esc, nul)) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('localhost', 5000)) s.listen(1) conn, addr = s.accept) sendReset() # now send commands as per documentation writeValues(struct.pack(...etc...)) Quote Link to comment Share on other sites More sharing options...
GallenWolf Posted August 11, 2013 Share Posted August 11, 2013 Hi edward! I'm trying to use the pipe in chop (OSX 10.6.8, 12.5.427) with sockets in python and I'm not really getting much of a response from houdini. This is what I've got so far.. import os, struct, socket, math, timeesc = chr(170)nul = chr(0)def writeByte(conn, myChar):if myChar == esc:conn.send(struct.pack('c', esc))conn.send(struct.pack('c',myChar))def writeValues(conn, myString):for c in myString:conn.send(struct.pack('c',c))def sendReset(conn):print "!Sending Reset Sequence"bytesSent = conn.send(struct.pack('cccccccc', esc, nul, esc, nul, esc, nul, esc, nul))print "!Sent Reset " + str(bytesSent)# Establish "server"s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)s.bind(('localhost', 5000))s.listen(1)conn, addr = s.accept()# Send reset commandfor o in range(100):sendReset(conn)writeByte(conn, '1')writeByte(conn, '1')writeValues(conn, str(math.sin(0)))# time.sleep(0.1)conn.close()[/CODE]I've also tried some of the code from the whodini blog, where they appear to send integers and floats through, however I tried that too and got terminal replies from houdini e.g.Unknown command type: 4294967297Unknown command type: 72057594054705152Also tried using a named pipe but got nowhere with that :-/Do you have any suggestions for getting python talking with the Pipe In CHOP? Thanks! Quote Link to comment Share on other sites More sharing options...
edward Posted August 11, 2013 Share Posted August 11, 2013 Since my posting there, the format has changed to use 64-bit values instead of 32-bit. So you have to make sure you're packing the values correctly according to http://www.sidefx.com/docs/houdini12.5/nodes/chop/pipein and adjust the code above accordingly. Also, you can't just do writeValues(conn, str(math.sin(0))), because now you're just sending ASCII data through for a binary stream. You must do something like writeValues(conn, struct.pack('d', math.sin(0)). Quote Link to comment Share on other sites More sharing options...
GallenWolf Posted August 12, 2013 Share Posted August 12, 2013 Hi edward! Thanks for the tips. I think I'm rather confused with the code presented on the helpcard, from what I see everything seems to be sent as a character with fputc(). But if I were to use struct.pack('d', math.sin(0) the result will be sent as a binary64? I'll go over the helpcard and check the packing again. Been trying to get char sent over as 64 bit but seems to only want to send 1 byte across :-/ Thanks again! Quote Link to comment Share on other sites More sharing options...
edward Posted August 13, 2013 Share Posted August 13, 2013 Please consult the python documentation for struct.pack() ... the "d" means to format it as a binary 64-bit float. In the C code, write_values() is called with a byte stream, which is what writeValues() (in my code, not yours) above mimics. Quote Link to comment Share on other sites More sharing options...
GallenWolf Posted August 13, 2013 Share Posted August 13, 2013 I'll read up on what's a byte stream, no idea what's that :-/ But thanks for the help, I'll keep exploring! Cheers! Quote Link to comment Share on other sites More sharing options...
grau Posted August 21, 2013 Share Posted August 21, 2013 (edited) Hi, I'm working on something similar right now. I want to stream data from python into a chop. The Problem is I can't get Houdini to establish a tcp connection with python either as client or server. The s.accept() never happens. I can trigger it with telnet and everything works as expected on the python side. The pipein doesn't seem to contact the socket and just outputs "no network connection". If I use a pipein and pipeout they connect, so it should not be a firewall problem. Is there anything special about the way the pipein establishes a tcp connection? If I could at least get to the "Unknown command type: ..." GallenWolf described, I think I could take it from there. This is what I've got so far: import timeimport socketfrom struct import packdef sendReset(conn): conn.send(pack('cccccccc', esc, nul, esc, nul, esc, nul, esc, nul))def send(conn, value): for ch in value: if ch == esc: conn.send(ch) conn.send(ch)def sendCurrentValues(conn, channelCount, samples): commandType = 1 #send command type conn.send(pack('>Q', commandType)) #send channelCount conn.send(pack('>Q', channelCount)) #packed as unsigned long long integer > 8bytes #send samples for s in samples: send(conn, pack('>d', s)) #packed as double float > 8bytesesc = chr(170)nul = chr(0)s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)s.bind(('', 5556))s.listen(1)conn, addr = s.accept()print 'connection established' #this is where i'm stucksendReset(conn)for o in range(10000): channelCount = 1 samples = [3.2] sendCurrentValues(conn, channelCount, samples) time.sleep(0.03)[/CODE]p.s.Does anyone know if the Network Chop uses the same format as the pipe op's? They don't seem to be able to talk to each other and the manual has no details about the implementation. Edited August 21, 2013 by grau 1 Quote Link to comment Share on other sites More sharing options...
grau Posted August 26, 2013 Share Posted August 26, 2013 Just for future reference, I tested my code on different machines and it works. I just had problems on my home workstation due to the firewall. Quote Link to comment Share on other sites More sharing options...
everitmatt Posted May 31, 2014 Share Posted May 31, 2014 (edited) I have been looking into the Pipe In chop a bit and found the above example really good and managed to get it working with Python over sockets. Right at the top there was a mention of using Processing to communicate with the Pipe In. After some wrangling I got it working, have a look at the code below if your interested. int channels = 6; double[] samples = {3.4,2.2,1.2,2.3,4.2,2.4}; char r = 170; int nul = 0; void setup() { size(600, 600); // Starts a myServer on port 5204 myServer = new Server(this, 5204); frameRate(5); sendReset(); } void draw() { val = (val + 1) % 255; background(val); sendSetup(cmdType); sendSetup(channels); sendSamples(samples); samples[0] = (double)mouseX/100; samples[1] = (double)mouseY/100; } void sendReset() { myServer.write(r); myServer.write(nul); myServer.write(r); myServer.write(nul); myServer.write(r); myServer.write(nul); myServer.write(r); myServer.write(nul); } void sendSetup(int d){ myServer.write(0); myServer.write(0); myServer.write(0); myServer.write(0); myServer.write(0); myServer.write(0); myServer.write(0); myServer.write(d); } void sendSamples(double[] sample){ for(int i = 0; i < sample.length; i++){ double s = sample[i]; long lng = Double.doubleToLongBits(s); for(int j = 0; j < 8; j++){ myServer.write((byte)((lng >> ((7 - j) * 8)) & 0xff)); } } } Edited May 31, 2014 by everitmatt 1 Quote Link to comment Share on other sites More sharing options...
fdevillalobos Posted October 2, 2015 Share Posted October 2, 2015 Hey Peon, Just for future reference, I tested my code on different machines and it works. I just had problems on my home workstation due to the firewall. I cannot get it to work, I don't know what's going on. I tried with my own code that works between my client and server (forget about sending data... just barely CONNECTING to Houdini), and my code works on it's own. But it doesn't for Houdini. I checked my Firewall options and it shouldn't be a problem. Trying to run your exact same code and it never outputs any message, error, or anything, it just stays there thinking. Any ideas or help you may give me?? For the Houdini side I'm just setting one Pipe In node inside a CHOP_network in /obj/, and it's set to Source: Network, ServerAddres: localhost, ServerPort:5556, and ACTIVE. Any help you may give me... thanks! Quote Link to comment Share on other sites More sharing options...
Mandrake0 Posted October 2, 2015 Share Posted October 2, 2015 made some test there is a code that works from this site: http://arthuryidi.com/notes/2015/01/28/Send-Animation-Data-to-Houdini/ I changed the Port to (only a test reason): 7000 The python_pipe.py works its the above code what i have done is to Ctrl-c the process and the it worked and i don't know why :-) The python_pipe_example2.py should work too it's from this threat. Just made some changes it generates a chan1 stream with a fix value and it's buggy. Sometimes you have to play with the PIPE IN Active and Reset Channel Button till you see the values in the Motion FX View. Good Luck.... :-) pipe_example.zip 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.