A small demo application showing the use of threads to 
facilitate Modbus communication.


1. Introduction

The multithreaded demo application "MBusScanner" reads and writes 400 
register values to and from an Modbus slave using the "Fieldtalk" 
library.  The Modbus communication is realized over TCP.  The 
following sections describe the application and how to use the 
MBusScannerThread unit.  


2. The application "MBusScanner"

MBusScanner is a simple application that demonstrates the usage of the 
MBusScannerThread.  It connects to the defined IP address and reads 
and writes 400 registers from slave ID 1, start address 1.  The 
reading operation is executed on the INPUT registers (3:0000), the 
writing is executed on the HOLDING registers (4:0000).  


3. Using the "MBusScannerThread"

For using the MBusScannerThread, the application must instantiate the 
MBusScannerThread. The thread starts automatically.


4. The "MBusScannerThread"

The procedures ReadBigArray() and WriteBigArray() perform the reading 
an writing operations of the complete array.  The global arrays are 
divided into subarrays of size 100, which are read/written by the 
procedures ReadArraySegment and WriteArraySegment.  Before calling the 
Fieldtalk library methods "writeMultipleRegisters" or 
"readMultipleRegisters", a local copy of the arrays is created.  
During the copy operation, the threads are synchronized using a 
critical section.  The application uses the critical section while 
accessing the global arrays.

