Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fieldio:cfnet:cfheaderprogramming:code_1 [2026/02/20 15:34] – created - external edit 127.0.0.1fieldio:cfnet:cfheaderprogramming:code_1 [2026/02/26 04:54] (current) admin
Line 1: Line 1:
 <code csharp> <code csharp>
-// Detect all connected CFHEADER modules. +// Get the CFHEADER module at address 0 
-foreach(var cfheader in Cfheader.Instances){ +var cfheader0 = Cfheader.Instances[0]; 
-    try    { +  
-        cfheader.Open(); +// Open USB communcation with the CFHEADER module 
-        Console.WriteLine($"CFHEADER at address {cfheader.Addresswas found connected to this host."); +cfheader0.Open(); 
-    } +  
-    catch    { +// Get all possible IO module instances 
-        Console.WriteLine($"CFHEADER at address {cfheader.Address} was not found connected to this host.");+var allIOModules = ((IEnumerable<IIOModule>)cfheader0.AnalogInputModules
 +    .Concat(cfheader0.AnalogOutputModules) 
 +    .Concat(cfheader0.DigitalInputModules) 
 +    .Concat(cfheader0.DigitalOutputModules); 
 +  
 +// Reset the IO module's I²C status so I²C communication will be attempted again on the next call to `Sync`. 
 +foreach(var ioModule in allIOModules) 
 +{ 
 +    ioModule.AcknowledgeI2cFailure(); 
 +} 
 +  
 +// Test i2c communication for each IO module 
 +cfheader0.Sync(); 
 +  
 +// Identify each IO module whose I²C communication succeeded. 
 +foreach(var ioModule in allIOModules) 
 +{ 
 +    if (ioModule.I2cStatus == I2cResult.Success) 
 +    { 
 +        Console.WriteLine($"Found {ioModule.GetType().Name} at address {ioModule.Address}");
     }     }
 } }
 + 
 +// Close USB communication with the CFHEADER module
 +cfheader0.Close();
 </code> </code>
 +