Serial daq timing & aligned logging


patrickokeeffe

Recommended Posts

I'm monitoring the continuous output from a Hamamatsu PMT via RS-232. The PMT controls triggering and sends data for 100-10ms readings giving a sampling rate very very close to but not precisely 1 Hz. Since the timestamps are marked upon arrival, the frequency is further distorted by tiny, varying delays in serial comm. All the other I/O for this setup is done through a Labjack however so its timing is DAQFactory-controlled and sampling is done on nice intervals.

This timing difference is enough that my aligned logging set doesn't align too well. The daily files typically end up a few records shy of 86400 and missing records are distributed throughout the day. It's also common to see two entries for a single second with different fractions of a second that should have been merged together or to have multiple PMT records aligned to the same second (then I lose a record). Before deployment, I tried different alignment threshold values and figured it was unavoidable so we've logged an 'all points' dataset too & used it to repair the aligned sets - this method is tedious and means I'm the only one doing it.

The easiest solution would be to change the timing of the PMT daq so its timestamps are identical to the other channels. It does have poll-response capabilities but using them requires a lower integration time (<1s) and that deflates my signal. To ensure all records are received before the next poll is sent would also require a fairly large listen window, probably a full quarter-second so poll-response is not really an option.

What else could be done to ensure 86400pnts/day and no record-squishing? Would it be crazy to have a sequence mirroring my PMT channel into a dummy channel & rounding the timestamps to whole sec. values? Or to have a Test device "Lag5s" with 1hz timing that 'samples' PMT_channel[now-5s]?

Any suggestions welcome & appreciated

Link to comment
Share on other sites

I guess I didn't really answer the question, sorry..

The PMT has its own separate protocol file so it's not based on sequence timing. I'm just listening to the serial line after sending the 'continuous output' command while the PMT does the integration and reports once/second. When the data actually shows up is not exactly 1Hz though and that seems to be the root of the "timing" issue I described.

Link to comment
Share on other sites

Depends on what you want. If you really need it at exactly 1 second, you need to decide what to do with either the extra (data coming in faster than 1 per second) or missing data point (data less than 1 per second) on the PMT. The best solution, however, is to probably let the PMT do the timing, and simply read the labjack as soon as the PMT responds. Just set the timeout of your serial port to something larger than 1 second (say 1500), then put the read() or readuntil() inside a loop without much of a delay, and read the LabJack as soon as the read returns. Something like this:

while(1)
   try
	  private string datain = device.mydevice.readuntil(13)
	  read(mylabjackChan)
	  ...
   catch()
   endcatch
   delay(0.1) // just in case
endwhile

What happens is that the readuntil() will pause until the PMT responds, which presumably is once a second, and then you use that as a trigger to read the labjack channels.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.