CFHEADER library 설치 및 프로젝트 만들기

개발PC 환경 설정을 마쳤다면, Visual Studio를 이용하여 프로그램(App)를 만드는 방법과 CFHEADER library(Nuget Packages) 설치 방법을 설명합니다.

위 설정을 마쳤다면 아래의 예제 코드로 동작을 확인할 수 있습니다. ( CFHEADER [ADDR. 0] + CFDO-16N [ADDR. 0] )

using ComfileTech.Cfnet.Cfheader;
 
var cfheader0 = Cfheader.Instances[0];
var digitalOutputModule0 = cfheader0.DigitalOutputModules[0];
 
cfheader0.Open();
 
while (true)
{
    // Blink each output in increasing order
    foreach (var channel in digitalOutputModule0.Channels)
    {
        channel.Blink();
    }
 
    // Blink each output in decreasing order
    foreach (var channel in digitalOutputModule0.Channels.Reverse())
    {
        channel.Blink();
    }
}
 
static class Extensions
{
    public static void Blink(this DigitalOutputModule.Channel channel)
    {
        // Toggle the channel's state
        channel.Toggle();
 
        // Delay for 50ms
        Thread.Sleep(50);
 
        // Toggle the channel's state again
        channel.Toggle();
    }
 
    public static void Toggle(this DigitalOutputModule.Channel channel)
    {
        // Toggle state
        channel.State = !channel.State;
 
        // Write the state to the module
        channel.Module.Header.Sync();
    }
}

CFHEADER