I want to be able to send time-stamps from Processing PDE to an EEG acquisition software called NetStation using the network library. NetStation has plug-ins and scripts available for Matlab, E-prime and Python, to send this time-stamp information, and I have been trying to use the matlab and python scripts to work out how to do this via processing – but I’ve had no luck so far, as I’m not familiar with these languages.
I’m pretty sure it is a formatting issue - whereby Netstation expects data to be send in specific C-type data formats.
//Here I need to send "Q" as a single byte character and "NTEL" as a C-style string message = struct.pack("=c4s", "Q", "NTEL") // beging session, send endianess self._socket.write(message) return self.GetServerResponse() self._socket.write('A'); // start recording message = struct.pack("=l", "T", ms_time); // time sync command - ms_time is long (32int) self._socket.write(message); self._socket.write('B'); //start recording data_string = 'D%s%s%s%s' % ( struct.pack('h', event_min_size), // short struct.pack('l', current_time), // long struct.pack('l', default_duration), //long struct.pack('4s', markercode), // 4 character string ) self._socket.write(data_string); // where the time-stamp information is sent self._socket.write('E'); //end recording
myClient.write('Q'+"NTEL"); myClient.write('A'); // this command works as expected, and pings back an OK response, which is a 'Z' ASCII or 90 in byte representation int local_time = System.currentTimeMillis();// get current time in milliseconds myClient.write('T' + local_time); // not sure if I should be sending with a '+', and whether processing int is the same as python long - I know the Netstation acquisition software is expecting 4 bytes myClient.write('B'); //start recording - this works min_size = 12; number of bytes that will follow this number. Must be send as a python short (16int, expecting 2 bytes). - not sure how to send this, as processing IDE doesnt have a short int int local_time = System.currentTimeMillis();// get current time in milliseconds int duration = 1; // duration is 1 millisecond myClient.write('D'+min_size + local_time + duration + "CODE"); myClient.write('E'); //end recording - this works
/// also I do not know how struct.pack works in python - and whether this function works to covert the data into bytes before sending over. According to the python website
“By default, the result of packing a given C struct includes pad bytes in order to maintain proper alignment for the C types involved; similarly, alignment is taken into account when unpacking. This behavior is chosen so that the bytes of a packed struct correspond exactly to the layout in memory of the corresponding C struct.”
Can I use Java ByteBuffer to do a similar thing? Or should I be converting to bytes and sending over in a different way?
Thanks for any help you can give!