Jump to content

pipe in / fifo file


jkunz07

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...))

Link to comment
Share on other sites

  • 1 year later...

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, time

esc = 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 command

for 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: 4294967297

Unknown command type: 72057594054705152

Also 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!

Link to comment
Share on other sites

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)).

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 time
import socket
from struct import pack

def 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 > 8bytes

esc = 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 stuck

sendReset(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 by grau
  • Like 1
Link to comment
Share on other sites

  • 9 months later...

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 by everitmatt
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

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!

Link to comment
Share on other sites

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

  • Thanks 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...