▼Gainerメモ▼
デジタル出力


I/Oモジュールのデジタル出力を行うプログラムを作成する。
クリックすることにより値が変化する。



ブレッドボード


ソースコード

DOutForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DOutEx {
    public partial class DOutForm : Form{
        private Gainer  gio;
        private bool[] DOutValue=new bool[4];//デジタル出力値

        //コンストラクタ
        public DOutForm() {
            InitializeComponent();            
        }

        //ロード時の初期化
        private void DOutForm_Load(object sender, EventArgs e) {
            gio=new Gainer("localhost",2000,Gainer.MODE1,true);
            gio.onReady+=onReady;
        }

        //gspとの接続成功時に発生
        private void onReady() {
            cbDOut0.Enabled=true;
            cbDOut1.Enabled=true;
            cbDOut2.Enabled=true;
            cbDOut3.Enabled=true;
        }

        //dout0チェック変更のイベント処理
        private void cbDOut0_CheckedChanged(object sender, EventArgs e) {
            DOutValue[0]=cbDOut0.Checked;
            gio.digitalOutput(DOutValue);
        }

        //dout1チェック変更のイベント処理
        private void cbDOut1_CheckedChanged(object sender, EventArgs e) {
            DOutValue[1]=cbDOut1.Checked;
            gio.digitalOutput(DOutValue);
        }

        //dout2チェック変更のイベント処理
        private void cbDOut2_CheckedChanged(object sender, EventArgs e) {
            DOutValue[2]=cbDOut2.Checked;
            gio.digitalOutput(DOutValue);
        }

        //dout3チェック変更のイベント処理
        private void cbDOut3_CheckedChanged(object sender, EventArgs e) {
            DOutValue[3]=cbDOut3.Checked;
            gio.digitalOutput(DOutValue);
        }    
    }
}



−戻る−