public void FindSlave() { LogOutput("開始搜尋控制器..."); ushort i, lMask = 0x1, p = 0; uint DeviceType = 0, IdentityObject = 0; btnstop.Enabled = false; btnNmove.Enabled = false; btnPmove.Enabled = false; gNodeNum = 0; txtSlaveNum.Text = "0"; cmbNodeID.Items.Clear(); for (i = 0; i < 1; i++) { NodeID[i] = 0; } if (SlaveTable[0] == 0) { MessageBox.Show("CardNo: " + gCardNo.ToString() + " No slave found!"); LogOutput("未發現控制器"); } else { for (i = 0; i < 32; i++) { if ((SlaveTable[0] & lMask) != 0) { NodeID[gNodeNum] = (ushort)(i + 1); gNodeNum++; rc = CPCI_DMC.CS_DMC_01_get_devicetype((short)gCardNo, (ushort)(i + 1), (ushort)0, ref DeviceType, ref IdentityObject); if (rc != 0) { MessageBox.Show("get_devicetype failed - code=" + rc); } else { switch (DeviceType) { case 0x4020192: //Servo A2 series cmbNodeID.Items.Add(i + 1); p++; break; case 0x6020192: //Servo M series cmbNodeID.Items.Add(i + 1); p++; break; case 0x8020192: //Servo A2R series cmbNodeID.Items.Add(i + 1); p++; break; case 0x9020192: //Servo S series cmbNodeID.Items.Add(i + 1); p++; break; } } } lMask <<= 1; } if (p == 0) { MessageBox.Show("No A2 Servo Device Found!"); } else { txtSlaveNum.Text = gNodeNum.ToString(); cmbNodeID.SelectedIndex = 0; LogOutput("控制卡連線完成"); } } }
private void btnFindSlave_Click(object sender, EventArgs e) { ushort i, lMask = 0x1, p = 0; uint DeviceType = 0, IdentityObject = 0; btnralm.Enabled = false; btnstop.Enabled = false; btnreset.Enabled = false; btnNmove.Enabled = false; btnPmove.Enabled = false; chksvon.Enabled = false; gNodeNum = 0; txtSlaveNum.Text = "0"; cmbNodeID.Items.Clear(); for (i = 0; i < 1; i++) { NodeID[i] = 0; } if (SlaveTable[0] == 0) { MessageBox.Show("CardNo: " + gCardNo.ToString() + " No slave found!"); } else { for (i = 0; i < 32; i++) { if ((SlaveTable[0] & lMask) != 0) { NodeID[gNodeNum] = (ushort)(i + 1); gNodeNum++; rc = CPCI_DMC.CS_DMC_01_get_devicetype((short)gCardNo, (ushort)(i + 1), (ushort)0, ref DeviceType, ref IdentityObject); if (rc != 0) { MessageBox.Show("get_devicetype failed - code=" + rc); } else { switch (DeviceType) { case 0x4020192: //Servo A2 series cmbNodeID.Items.Add(i + 1); p++; break; case 0x6020192: //Servo M series cmbNodeID.Items.Add(i + 1); p++; break; case 0x8020192: //Servo A2R series cmbNodeID.Items.Add(i + 1); p++; break; case 0x9020192: //Servo S series cmbNodeID.Items.Add(i + 1); p++; break; } } } lMask <<= 1; } if (p == 0) { MessageBox.Show("No A2 Servo Device Found!"); } else { txtSlaveNum.Text = gNodeNum.ToString(); cmbNodeID.SelectedIndex = 0; timer1.Enabled = true; btnralm.Enabled = true; btnstop.Enabled = true; btnreset.Enabled = true; btnNmove.Enabled = true; btnPmove.Enabled = true; chksvon.Checked = false; chksvon.Enabled = true; } } }
public int OpenCard() //打开控制卡并初始化 { ushort i, card_no = 0, cardnum = 0, DeviceInfo = 0; ushort lMask = 0x1; ushort gNodeNum = 0; uint DeviceType = 0, IdentityObject = 0; try { rc = CPCI_DMC.CS_DMC_01_open(ref existcard); if (existcard <= 0) { // throw new Exception("没有找到运动控制卡!" + e.Message); SendMsgToDisplayWarning("No DMC-NET card can be found!"); MessageBox.Show("No DMC-NET card can be found!"); return(-1); } else { for (i = 0; i < existcard; i++) { rc = CPCI_DMC.CS_DMC_01_get_CardNo_seq(i, ref card_no); gCardNoList[i] = card_no; } gCardNo = gCardNoList[0]; for (i = 0; i < existcard; i++) { rc = CPCI_DMC.CS_DMC_01_pci_initial(gCardNoList[i]); if (rc != 0) { // throw new Exception("运动控制卡无法进行初始化!" + e.Message); SendMsgToDisplayWarning("Can't boot PCI_DMC Master Card!"); return(-1); } else { rc = CPCI_DMC.CS_DMC_01_initial_bus(gCardNoList[i]); if (rc != 0) { SendMsgToDisplayWarning("The PCI_DMC Initial Failed!"); return(-1); } else { for (i = 0; i < 4; i++) { SlaveTable[i] = 0; } rc = CPCI_DMC.CS_DMC_01_start_ring(gCardNo, 0); //Start communication rc = CPCI_DMC.CS_DMC_01_get_device_table(gCardNo, ref DeviceInfo); //Get Slave Node ID rc = CPCI_DMC.CS_DMC_01_get_node_table(gCardNo, ref SlaveTable[0]); if (SlaveTable[0] == 0) { SendMsgToDisplayWarning("The node table is empty!"); } else { for (i = 0; i < 32; i++) { NodeID[i] = 0; if ((SlaveTable[0] & lMask) != 0) { NodeID[gNodeNum] = (ushort)(i + 1); rc = CPCI_DMC.CS_DMC_01_get_devicetype(gCardNo, NodeID[i], 0, ref DeviceType, ref IdentityObject); gNodeNum++; } lMask <<= 1; } } } } } if (existcard != 0) { gCardNo = gCardNoList[0]; } } } catch (Exception e) { // throw (new Exception("运动控制卡打开失败或者初始化失败!")); SendMsgToDisplayWarning("PCI_DMC Master Card failed OR PCI_DMC Initial Failed!"); return(-1); } return(gCardNo); }