Data acquisition without sd card!

**Moku model: Moku:lab
Operating system: Ubuntu
Software version: 601

Bug or support request description: Dear all, I would like to know, if there is any opportunity to log or stream data without downloading the .li file neither in the local computer nor in the moku SD card. I use python API for data streaming or logging.
best
Saman

Hello @Saman,
Streaming is available without an SD card. To use streaming you will need to first install mokucli which is available for download here. To get the data from the Moku, you can use get_stream_data() in a loop which will constantly pull in the streamed data. To log and download you will need an SD card. Hope this helps!

Hi Saman, I’ve had success using stream_to_file and specifying the destination as a temp csv on my local machine, then immediately reading and then deleting the temp file. It’s a little hacky but it gets around having to manually open and convert a .li file. I found repeatedly calling get_stream_data() to occasionally drop data if latency is poor. Maybe I’m doing something wrong there.

Hello @JackAttack720 and @Saman ,
Yes, streaming to file is another good choice! For this, you can choose to stream to a csv to avoid having to convert any .li files. You typically only have to convert the .li file if you are logging, not streaming. Calling get_stream_data() in a loop shouldn’t cause any data loss as the data is first stored in a buffer before it is streamed to your local machine. Here is a simple script where you can essentially collect all of the streamed data, add it to a list, and plot it and/or process it.

i=Datalogger('192.168.##.###', force_connect=True)

i.start_streaming(10,1e6)

time_data=[]
volt_data=[]

while True:
    data=i.get_stream_data()
    x=data['time']
    y=data['ch1']
    time_data.extend(x)
    volt_data.extend(y)

Once that is finished running, time_data will have all of the time data and the volt_data will have all the voltage data points.

1 Like

I sorted out why I was having data loss - essentially I was looking at the number of samples returned and it wasn’t matching rate*duration, and this was coming from how I was trying to manage the exceptions of the loop. If your while loop doesn’t have a termination condition it will just run until i.get_stream_data() fails with a StreamingException, which doesn’t allow for continued program execution. If you query the status each iteration of the loop you also run into problems. For example, if I use the following code with duration = 10, rate= 1000:

extended_data = {'time':[],'ch1':[]}
i.start_streaming(duration=duration,rate=rate)
status = 'RUNNING'
while status == 'RUNNING':
    data = i.get_stream_data()
    extended_data['time'].extend(data['time'])
    extended_data['ch1'].extend(data['ch1'])
    status = i.get_stream_status()['status']

I get only 5041 samples back, meaning a significant number of samples were being dropped.
I suspect that i.get_stream_status() has too much latency at high sampling rates and so there’d be a chance a chunk would be missed if the duration was too high
After a bit of fiddling I found that the following doesn’t drop samples and solve the issue of raising an exception. This has proven much less annoying to use than saving a temporary CSV, reading it out and then deleting the temporary file.

extended_data = {'time':[],'ch1':[]}
i.start_streaming(duration=duration,rate=rate)
while True:
   try:
        data = i.get_stream_data()
    except moku.exceptions.StreamException:
        break
    extended_data['time'].extend(data['time'])
    extended_data['ch1'].extend(data['ch1'])