import ch.psi.bsread.Receiver as Receiver
import ch.psi.bsread.ReceiverConfig as ReceiverConfig
import ch.psi.bsread.configuration.Channel as ReceiverChannel


c1 = ReceiverChannel("Int32Scalar", 10)
config = ReceiverConfig("tcp://sf-lc6-64:9999")
#config.setReqbsuestedChannels([c1,])

receiver = Receiver(config)
receiver.connect()

message = None
# Its also possible to register callbacks for certain message parts.
# These callbacks are triggered within the receive() function 
# (within the same thread) it is guaranteed that the sequence is ordered
# main header, data header, values

# receiver.addDataHeaderHandler(header -> System.out.println(header));
# receiver.addMainHeaderHandler(header -> System.out.println(header) );
# receiver.addValueHandler(data -> System.out.println(data));
try:
    while(True):
        message = receiver.receive()
        #print (message.getMainHeader())
        #print (message.getDataHeader())
        #print (message.getValues())
        print "----------------"
        for channel in message.getValues().keys():
            print channel , " = " , message.getValues()[channel].getValue().array().tolist()
        break
finally:  
    receiver.close()