from pymoku import Moku, MokuException
from pymoku.instruments import *
import time, logging, traceback

logging.basicConfig(format='%(asctime)s:%(name)s:%(levelname)s::%(message)s')
logging.getLogger('pymoku').setLevel(logging.DEBUG)

# Use Moku.get_by_serial() or get_by_name() if you don't know the IP
m = Moku('192.168.1.106')#.get_by_name('example')

i = m.discover_instrument()

if i is None or i.type != 'oscilloscope':
	print "No or wrong instrument deployed"
	i = Oscilloscope()
	m.attach_instrument(i)
else:
	print "Attached to existing Oscilloscope"

i.set_defaults()
i.set_samplerate(1000) #10ksps
i.set_xmode(OSC_ROLL)
i.commit()

# TODO: Symbolic constants, simplify this logic in the underlying driver.
if i.datalogger_status() in  [1, 2, 6]:
	i.datalogger_stop()

i.datalogger_start(start=0, duration=10, filetype='net')

try:
	while True:
		ch, idx, d = i.datalogger_get_samples(timeout=5)

		print "Received samples %d to %d from channel %d" % (idx, idx + len(d), ch)
except MokuException as e:
	print e
except Exception as e:
	print traceback.format_exc()
finally:
	i.datalogger_stop()
	m.close()

@@ -310,26 +310,8 @@
 Moku
-('192.168.1.106')#
 .get
@@ -537,16 +537,22 @@
 scope%22%0A%0A
+try:%0A%09
 i.set_de
@@ -560,16 +560,17 @@
 aults()%0A
+%09
 i.set_sa
@@ -592,16 +592,17 @@
 #10ksps%0A
+%09
 i.set_xm
@@ -615,16 +615,17 @@
 C_ROLL)%0A
+%09
 i.commit
@@ -632,82 +632,9 @@
 ()%0A%0A
-# TODO: Symbolic constants, simplify this logic in the underlying driver.%0A
+%09
 if i
@@ -649,32 +649,17 @@
 ger_
-stat
+b
 us
+y
 ()
- in  %5B1, 2, 6%5D
 :%0A
+%09
 %09i.d
@@ -676,16 +676,17 @@
 stop()%0A%0A
+%09
 i.datalo
@@ -735,21 +735,16 @@
 'net')%0A%0A
-try:%0A
 %09while T
@@ -901,24 +901,103 @@
 ption as e:%0A
+%09# This will be raised if we try and get samples but the session has finished.%0A
 %09print e%0Aexc

Use new API to improve streaming datalogger example