We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey there, I am working on a project that sends data from Processing to Houdini( a procedural modelling program). Houdini needs to receive the data in 8 byte chunks of type int and double.
In my code below I am successfully sending the cmdType and channels ints by packing them out. However, the structure of a double cannot be simply packed out and the server.write() will on use int, char and byte.
Is there a way I can send a double or convert it to bytes/bits?
import processing.net.*;
Server myServer;
int val = 0;
int cmdType = 1;
int channels = 3;
double[] samples = {5.3,2.3,1.2};
void setup() {
size(200, 200);
// 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);
}
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++){
myServer.write(sample[i]);
}
}
Answers
If the
double
values got only 1 digit after the decimal point, you can multiply it by 10 before sending it out!Are you suggesting multiplying the double so that I can then send it as an int and then just adjust for that in Houdini? Good idea, but Houdini has to receive the samples data as doubles rather than ints.
For example, it receives the cmdType and channels like so:
int cmdType = 1 --- becomes '\x00\x00\x00\x00\x00\x00\x00\x01'
int channels = 3 --- becomes '\x00\x00\x00\x00\x00\x00\x00\x03'
But has to receive the sample as a double like so:
double sample = 5 --- becomes '@\x14\x00\x00\x00\x00\x00\x00'
Just took a look at class Serial's source for method write():
As you can see above, it's based on class OutputStream:
http://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html
And I'm afraid it can only send a single
byte
. Therefore, every other bytes beyond the lowest 1st are ignored!If you wanna send the whole
double
as a full sequence of 8 bytes, you're gonna need to convert it to abyte[8]
!Afterwards, you can call the other overloaded Serial's write() method:
Check it out my conversion solution below: :D
Hey GoTo, Thanks for the above reply, after reading that it can only send single Bytes I went about looking how I could split my double up into a byte[]. Found a good example and this is what I came up with. Working fine at the moment.
Hey just saw your edit to the discussion after I posted the above. Looks pretty similar to what I came up with. Thanks Heaps.
Perhaps we both searched @ StackOverflow.com. ;)
Anyways, I've tweaked your version to use my doubleToBytes() snippet: O:-)
Hey, can you tell me the your workflow of how to send processing data in Houdini or export maybe directly to fbx. thanks.