77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
from ch.psi.bsread import ScheduledSender
|
|
from ch.psi.bsread import SenderConfig
|
|
from ch.psi.bsread import DataChannel
|
|
from ch.psi.bsread.impl import StandardPulseIdProvider
|
|
from ch.psi.bsread.impl import StandardTimeProvider
|
|
from ch.psi.bsread.message import Timestamp
|
|
from ch.psi.bsread.message import ChannelConfig
|
|
from ch.psi.bsread.converter import MatlabByteConverter
|
|
from java.util.concurrent import TimeUnit
|
|
from ch.psi.bsread.message import Type as ChanlelType
|
|
from ch.psi.bsread.compression import Compression
|
|
|
|
try:
|
|
sender.close()
|
|
except:
|
|
pass
|
|
try:
|
|
receiver.close()
|
|
except:
|
|
pass
|
|
|
|
#address "tcp://*:9999"
|
|
#try:
|
|
pid_provider = StandardPulseIdProvider()
|
|
time_provider = StandardTimeProvider();
|
|
converter = MatlabByteConverter()
|
|
sender = ScheduledSender(SenderConfig(SenderConfig.DEFAULT_ADDRESS,pid_provider,time_provider,converter))
|
|
|
|
class ScalarChannel(DataChannel):
|
|
def getValue(self, pulseId):
|
|
#print pulseId
|
|
return float(pulseId);
|
|
def getTime(self, pulseId):
|
|
return Timestamp(pulseId, 0L)
|
|
scalar_channel_config = ChannelConfig("Scalar", ChanlelType.Float64, 10, 0)
|
|
scalar_channel = ScalarChannel(scalar_channel_config)
|
|
sender.addSource(scalar_channel)
|
|
|
|
|
|
#Compression: bitshuffle_lz4 , none or lz4
|
|
compression = Compression.none
|
|
|
|
SIZE_ARRAY = 1200000 #54268
|
|
#SIZE_ARRAY = 120
|
|
|
|
|
|
class ArrayChannel(DataChannel):
|
|
def getValue(self, pulseId):
|
|
return Arr.indexesDouble(SIZE_ARRAY)
|
|
def getTime(self, pulseId):
|
|
return Timestamp(pulseId, 0L)
|
|
|
|
array_channel_config = ChannelConfig("Array", ChanlelType.Float64, [SIZE_ARRAY/1000, 1000], 10, 0, ChannelConfig.DEFAULT_ENCODING, compression)
|
|
array_channel = ArrayChannel(array_channel_config)
|
|
sender.addSource(array_channel)
|
|
|
|
|
|
sender.connect();
|
|
initialDelay = 20
|
|
period = 20
|
|
sender.sendAtFixedRate(initialDelay, period, TimeUnit.MILLISECONDS)
|
|
back=sender
|
|
|
|
#run ("test/test_receive_sender")
|
|
|
|
|
|
receiver = Stream("st1", "tcp://localhost:9999", SocketType.PULL)
|
|
#st1.parent.config.headerReservingAllocator = True
|
|
receiver.initialize()
|
|
receiver.start()
|
|
show_panel(receiver)
|
|
|
|
|
|
#finally:
|
|
# #receiver.close();
|
|
# sender.close();
|
|
# pass |