App Notes

Contents[Hide]
Download zip archive

Description

Data Collector Host ("Host") receives data over a serial link from a .NOW. It is intended to be used with the Data Collector Exfiltrator.

Compatibility

eMote.NOW 1.0, eMote version 4.3.1.12 and Visual Studio 2012.

Key Ideas

The main idea illustrated is that data must be reliably received. This is in two parts.

  • Serial communication itself must be reliable. Some of the Windows serial communication methods are unreliable (see www.sparxeng.com/blog/software/must-use-net-system-io-ports-serialport for a discussion). We use the reliable Stream.BeginRead and Stream.EndRead methods in SerialRead().
  • Serial read must not race. In the method SerialRead() you'll see use of WriteCompletedSemaphore. That keeps SerialRead() from continuing until the received data has been written to a file. Without it, the immediate execution of the next loop of BeginRead can cause WriteFile() to be called on a new buffer before the old one is finished, corrupting the data stored.

In addition, closing the serial port can cause the program to hang; this is a bug in Windows .NET. To avoid it, we close the port in a new thread and then wait until the thread is complete.

Setup

The Host program assumes that the PC is connected to a .NOW over a serial port in the range of COM1 - COM8.

Operation

Start the Host program. 

  • Respond to the prompts for COM port and file name. If you don't specify a path, the file will be stored in the program's Debug folder. An extension of .data is automatically added to the file name. You'll see the message to press Enter when ready to start receiving. Don't press it yet.
  • Set up the .NOW that's providing the data. Wait untio it's ready to start transmitting. For Data Collector Exfiltrator, this is when it displays "conn" on the LCD.
  • Press the Enter key on Host to start receiving.
  • If you're using the Exfiltrator. it will start sending automatically after a few seconds.  
  • On the Host, you will see messages printed periodically that give first and last values on each buffer's worth of data received.
  • Host will continue receiving until it receives a byte consisting of 0X0C0C. When that's received, Host will close the output file and print that it's finished.