차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판 | |||
| fieldio:cfnet:cfheadernewproject:index [2026/02/26 05:11] – admin | fieldio:cfnet:cfheadernewproject:index [2026/06/13 13:56] (현재) – admin | ||
|---|---|---|---|
| 줄 55: | 줄 55: | ||
| </ | </ | ||
| {{ : | {{ : | ||
| + | |||
| + | =====예제 프로그램 2===== | ||
| + | |||
| + | 아래 예는 여러 개의 CFHEADER모듈 사용 프로그램입니다. **[ CFHEADER[0, 1, 2] x CFDO[0, 0, 0] ]** | ||
| + | |||
| + | ++++[소스 보기]| | ||
| + | <code csharp> | ||
| + | using ComfileTech.Cfnet.Cfheader; | ||
| + | |||
| + | // Get the CFHEADER instances | ||
| + | var cfheader0 = Cfheader.Instances[0]; | ||
| + | var cfheader1 = Cfheader.Instances[1]; | ||
| + | var cfheader2 = Cfheader.Instances[2]; | ||
| + | |||
| + | // Open USB communication for each CFHEADER instance | ||
| + | cfheader0.Open(); | ||
| + | cfheader1.Open(); | ||
| + | cfheader2.Open(); | ||
| + | |||
| + | // Create a thread for each CFHEADER instance | ||
| + | var thread0 = new Thread(() => Demo(cfheader0)); | ||
| + | var thread1 = new Thread(() => Demo(cfheader1)); | ||
| + | var thread2 = new Thread(() => Demo(cfheader2)); | ||
| + | |||
| + | // Start each thread | ||
| + | thread0.Start(); | ||
| + | thread1.Start(); | ||
| + | thread2.Start(); | ||
| + | |||
| + | // Wait for each thread to finish | ||
| + | thread0.Join(); | ||
| + | thread1.Join(); | ||
| + | thread2.Join(); | ||
| + | |||
| + | void Demo(Cfheader cfheader) | ||
| + | { | ||
| + | // Get the digital output module | ||
| + | var cfdo_16n0 = cfheader.DigitalOutputModules[0]; | ||
| + | |||
| + | // Initialize all channels to 0 | ||
| + | cfdo_16n0.State = 0x00; | ||
| + | |||
| + | while (true) | ||
| + | { | ||
| + | foreach (var channel in cfdo_16n0.Channels) | ||
| + | { | ||
| + | // Toggle the channel on | ||
| + | channel.State = !channel.State; | ||
| + | channel.Module.Header.Sync(); | ||
| + | |||
| + | // Delay for 50ms | ||
| + | Thread.Sleep(50); | ||
| + | |||
| + | // Toggle the channel off | ||
| + | channel.State = !channel.State; | ||
| + | channel.Module.Header.Sync(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | ++++ | ||
| [[..: | [[..: | ||
