//public IOdevice[] devices = { // new IOdevice(1, 1, "EL1004", 4), // new IOdevice(2, 2, "EL2004", 4), // new IOdevice(3, 3, "EL3008", 8), // new IOdevice(4, 4, "EL4002", 2), // }; public FormDevice() { InitializeComponent(); ethercat = EtherCAT.getEtherCAT(true); //临时的 ethercat.getAdapter(); ethercat.setAdapter(2); }
// EtherCAT通信スレッド処理 void threadFunc_EtherCAT() { while (true) { // サーボの角度指令値を出力バッファに設定 lock (m_lockobj) { EtherCAT.setOutputPDO(1, 0, (byte)servo1_val); EtherCAT.setOutputPDO(2, 0, (byte)servo2_val); } // EtherCATのPDO転送 EtherCAT.transferPDO(); // ボリュームの値を入力バッファから取得 int[] vol = new int[2]; for (int i = 0; i < 2; i++) { byte vol_h = EtherCAT.getInputPDO(1 + i, 0); byte vol_l = EtherCAT.getInputPDO(1 + i, 1); vol[i] = ((int)vol_h << 8) | (int)vol_l; } // UIに反映 this.BeginInvoke((Action)(() => { joystickBar1.Value = vol[0]; joystickBar2.Value = vol[1]; })); // 停止判定 if (!isConnected) { break; } // 20msecスリープ Thread.Sleep(10); }// while(true) // 通信終了処理 this.BeginInvoke((Action)(() => { // 切断処理 EtherCAT.requestState(EtherCAT.ALL_SLAVES, EtherCAT.STATE_INIT); EtherCAT.close(); // UIの表示切替え buttonConnect.Enabled = true; buttonDisconnect.Enabled = false; buttonUpdate.Enabled = true; comboNicName.Enabled = true; })); }
public void Start(int mode = NexMotion_Define.DEV_TYPE_SIMULATION) { ether_cat_net = new EtherCAT(); ether_cat_net.SetMode(mode); int ret = ether_cat_net.InitRobot(); if (ret != NexMotion_ErrCode.NMCERR_SUCCESS) { throw new System.SystemException("Unable to openup device(" + ret.ToString() + ")!!"); } ether_cat_net.InitIOForRobot(2, 0); }
// Connectボタン private void buttonConnect_Click(object sender, EventArgs e) { try { // 接続処理 int result = EtherCAT.open(@"\Device\NPF_" + ((NicInfo)comboNicName.SelectedItem).ID); if (result == EtherCAT.FAILED) { MessageBox.Show("ネットワークインターフェースが開けません", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } result = EtherCAT.config(); if (result == EtherCAT.NO_SLAVES_FOUND) { MessageBox.Show("スレーブデバイスが見つかりません", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (result == EtherCAT.NOT_ALL_OP_STATE) { MessageBox.Show("OPERATIONAL状態に移行できないデバイスがあります", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 設定の保存 Properties.Settings.Default.NicName = comboNicName.Text; Properties.Settings.Default.Save(); // 通信中フラグをセット isConnected = true; // UIの表示切替え buttonConnect.Enabled = false; buttonDisconnect.Enabled = true; buttonUpdate.Enabled = false; comboNicName.Enabled = false; // シリアル通信スレッドを起動 threadEtherCAT = new Thread(new ThreadStart(threadFunc_EtherCAT)); threadEtherCAT.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public FormNIC() { InitializeComponent(); ethercat = EtherCAT.getEtherCAT(true); }