Mobi8python

From vret
Revision as of 14:19, 24 June 2009 by Wouter (talk | contribs)
Jump to: navigation, search
 
import win32com.client


#-------------connecting procedure----------------
print 'mobi8 demo interface'
print 'W.Pasman 24june 2009'

mobi8=win32com.client.Dispatch("PortiSerial.SerialSource")

print "connecting with mobi8..."

mobi8.ComPort="4"
SerialNumber = mobi8.FrontendSerialNumber
if SerialNumber==-1:
  raise Exception("can not open connection with mobi8."+
    " Try to reconnect the mobi8 device via bluetooth")

NrOfChannels=mobi8.GetFrontendNrOfChannels()
HighestSampleRate=mobi8.SampleRate
print "mobi8 connected with "+str(NrOfChannels)+" channels, max samplerate="+str(HighestSampleRate)


#--------------sample data capture of 1000 samples, including printing ----------------
ReceivedSamples=0
DesiredSampleRate=HighestSampleRate/8
mobi8.SampleRate=DesiredSampleRate
error=mobi8.StartAcq(DesiredSampleRate)


f=open('out.txt','w') # dump to file
while ReceivedSamples < 1000:
  Periods,samples=mobi8.GetSampleRecordAsVariant()
  if (Periods>0):
    ReceivedSamples = ReceivedSamples+Periods
    #print samples[0]
    for sample in samples[0]: # print channel 0 only. printing all is too much
      print >>f, sample

#-----------------disconnect --------------------
error=mobi8.StopAcq()
error=mobi8.ReleaseSerialPort()

print "ended"