// IO 정보 리턴. public DeviceNetIO GetLinkData(string strIoName, DNET_IO_TYPE type) { DeviceNetIO Rtn = null; for (int nAdapter = 0; nAdapter < DNet_Adapter.Count; nAdapter++) { for (int nModule = 0; nModule < DNet_Adapter[nAdapter].Module_List.Count; nModule++) { if (DNet_Adapter[nAdapter].Module_List[nModule].IO_Type != type) { continue; } for (int nIO = 0; nIO < DNet_Adapter[nAdapter].Module_List[nModule].IO_List.Count; nIO++) { DeviceNetIO _IO = DNet_Adapter[nAdapter].Module_List[nModule].IO_List[nIO]; if (_IO.IO_Name.Equals(strIoName) && _IO.IO_Type.Equals(type)) { Rtn = _IO; break; } } if (Rtn != null) { break; } } if (Rtn != null) { break; } } return(Rtn); }
public ushort ReadInput(DeviceNetIO IO) { ushort[] _Value = new ushort[1]; xHilscher.ReadInput(IO.Address, _Value, 0); IO.AnalogValue = (short)_Value[0]; return(_Value[0]); }
private void ListView_Output_DoubleClick(object sender, EventArgs e) { //테스트 //if (UseOutputControl == false) // return; ListView listView = ((ListView)sender); int nIndex = listView.SelectedItems[0].Index; if (nIndex < 0) { return; } string strIOName = listView.Items[nIndex].SubItems[0].Text; //테스트 //if (strIOName.StartsWith("SPARE_") == true) // return; //스페어다. DeviceNetIO _IO = m_DNet_IoList.GetLinkData(strIOName, DNET_IO_TYPE.D_OUTPUT); if (_IO != null) { bool bOn = !_IO.IsOn; // 현재값과 반대로 보낸다. string strMsg = string.Format("Do you Wan't Send Select IO?\r\n\r\n - IO Name : {0}\r\n - Value : {1}", _IO.IO_Name, (bOn) ? "ON" : "OFF"); if (!MessageBox.Show(strMsg, "Send IO", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2).Equals(DialogResult.Yes)) { return; } m_DNet.WriteBit(_IO, bOn); } }
private void RefreshView() { foreach (ListViewItem list in ListView_InputList.Items) { int nIO_Index = int.Parse(list.SubItems[0].Text) - 1; DeviceNetIO _IO = m_IoList_All.Input[nIO_Index]; string strOnOff = _IO.IsOn == true ? "ON" : "OFF"; if (strOnOff != list.SubItems[5].Text) { list.SubItems[5].Text = strOnOff; } } foreach (ListViewItem list in ListView_OutputList.Items) { int nIO_Index = int.Parse(list.SubItems[0].Text) - 1; DeviceNetIO _IO = m_IoList_All.Output[nIO_Index]; string strOnOff = _IO.IsOn == true ? "ON" : "OFF"; if (strOnOff != list.SubItems[5].Text) { list.SubItems[5].Text = strOnOff; } } }
public void RefreshAddress(ref ushort usInputMax, ref ushort usOutputMax) { //ushort nInputAddr = 0; ushort nInputAddr = 1; //ushort nInputAddr = 0; ushort nOutputAddr = 0; nSpare = 1; for (int nCntAdapter = 0; nCntAdapter < DNet_Adapter.Count; nCntAdapter++) { //nInputAddr += 2; //디지털 인풋은 아답터 정보때매 2Word를 차지한다. for (int nCntModule = 0; nCntModule < DNet_Adapter[nCntAdapter].Module_List.Count; nCntModule++) { //Todo if (DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_Type == DNET_IO_TYPE.D_INPUT || DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_Type == DNET_IO_TYPE.D_OUTPUT) { //Digital 신호 DNET_IO_TYPE _CurIO_Type = DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_Type; for (int nCntIO = 0; nCntIO < DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_List.Count; nCntIO++) { DeviceNetIO _CurIO = DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_List[nCntIO]; //_CurIO.SubAddr = (ushort)(1 << nCntIO); if (_CurIO.IO_Name == "" || _CurIO.IO_Name.IndexOf("SPARE_") >= 0) { _CurIO.IO_Name = string.Format("SPARE_{0:d04}", nSpare++); } } //nInputAddr += 2; //nOutputAddr += 2; } else { //Analog 신호 //아날로그 모듈은, 인풋이 9개, 아웃풋이 6개로,,, 각각 2워드를 차지한다. DNET_IO_TYPE _CurIO_Type = DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_Type; for (int nCntIO = 0; nCntIO < DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_List.Count; nCntIO++) { DeviceNetIO _CurIO = DNet_Adapter[nCntAdapter].Module_List[nCntModule].IO_List[nCntIO]; //_CurIO.Address = nInputAddr; //_CurIO.SubAddr = nOutputAddr; if (_CurIO.IO_Name == "" || _CurIO.IO_Name.IndexOf("SPARE_") >= 0) { _CurIO.IO_Name = string.Format("SPARE_{0:d04}", nSpare++); } //nInputAddr += 2; } //nOutputAddr += 12; //아날로그 아웃풋 영역은 6개니깐,, 고정으로 12워드를 차지한다. 단 첫번째 어드래스는,, 각 인풋영역의 셋팅값으로 활용된다. } } } usInputMax = nInputAddr; usOutputMax = nOutputAddr; }
public void ReadAll_and_Matching() { try { if (IsOpen() == false) { return; } ReadAllInput(); ReadAllOutput(); if (DNet_IO_List == null) { return; } for (int nAdapter = 0; nAdapter < DNet_IO_List.DNet_Adapter.Count; nAdapter++) { for (int nModule = 0; nModule < DNet_IO_List.DNet_Adapter[nAdapter].Module_List.Count; nModule++) { for (int nIo = 0; nIo < DNet_IO_List.DNet_Adapter[nAdapter].Module_List[nModule].IO_List.Count; nIo++) { DeviceNetIO _IO = DNet_IO_List.DNet_Adapter[nAdapter].Module_List[nModule].IO_List[nIo]; switch (_IO.IO_Type) { case DNET_IO_TYPE.D_INPUT: { ReadBit(_IO); } break; case DNET_IO_TYPE.D_OUTPUT: { ReadOutBit(_IO); } break; case DNET_IO_TYPE.A_INPUT: { ReadInput(_IO); } break; } } } } } catch (Exception ex) { LogTextOut(ex.Message); } }
private void Write_AnalogIO_ConfigSet() { for (int nAdapter = 0; nAdapter < DNet_IO_List.DNet_Adapter.Count; nAdapter++) { for (int nModule = 0; nModule < DNet_IO_List.DNet_Adapter[nAdapter].Module_List.Count; nModule++) { if (DNet_IO_List.DNet_Adapter[nAdapter].Module_List[nModule].IO_Type != DNET_IO_TYPE.A_INPUT) { continue; //아날로그 아이오만 하면 된다. } for (int nIo = 0; nIo < DNet_IO_List.DNet_Adapter[nAdapter].Module_List[nModule].IO_List.Count; nIo++) { DeviceNetIO _IO = DNet_IO_List.DNet_Adapter[nAdapter].Module_List[nModule].IO_List[nIo]; //WriteAnalog_Set(_IO.SubAddr); } } } }
private void Listview_To_IoList() { _PmacCtrl.IoList_All.Input.Clear(); ListView _ListView = ListView_InputList; for (int nRow = 0; nRow < _ListView.Items.Count; nRow++) { string strNum = _ListView.Items[nRow].SubItems[0].Text; string strAddr = _ListView.Items[nRow].SubItems[1].Text; strAddr = strAddr.Replace("M", ""); strAddr = strAddr.Replace("->", ""); strAddr = strAddr.Replace(" ", ""); ushort uAddr = ushort.Parse(strAddr); string strSubAddr = _ListView.Items[nRow].SubItems[2].Text; string strType = _ListView.Items[nRow].SubItems[3].Text; string strCable = _ListView.Items[nRow].SubItems[4].Text; string strIoName = _ListView.Items[nRow].SubItems[5].Text; DeviceNetIO _IO = new DeviceNetIO(strIoName, uAddr, 0, DNET_IO_TYPE.D_INPUT, strCable, strSubAddr); _PmacCtrl.IoList_All.Input.Add(_IO); } _PmacCtrl.IoList_All.Output.Clear(); _ListView = ListView_OutputList; for (int nRow = 0; nRow < _ListView.Items.Count; nRow++) { string strNum = _ListView.Items[nRow].SubItems[0].Text; string strAddr = _ListView.Items[nRow].SubItems[1].Text; strAddr = strAddr.Replace("M", ""); strAddr = strAddr.Replace("->", ""); strAddr = strAddr.Replace(" ", ""); ushort uAddr = ushort.Parse(strAddr); string strSubAddr = _ListView.Items[nRow].SubItems[2].Text; string strType = _ListView.Items[nRow].SubItems[3].Text; string strCable = _ListView.Items[nRow].SubItems[4].Text; string strIoName = _ListView.Items[nRow].SubItems[5].Text; DeviceNetIO _IO = new DeviceNetIO(strIoName, uAddr, 0, DNET_IO_TYPE.D_OUTPUT, strCable, strSubAddr); _PmacCtrl.IoList_All.Output.Add(_IO); } }
public int SetOutIOValUMAC(DeviceNetIO _IO, bool bVal, bool bMustSet = false) { string strCommand = "", strRet = ""; int nRtn = -1; int nIndex = _IO.Address - (int)m_nOutputStartAddr; if (!bMustSet) { // 현재 IO 상태가 지령값과 같으면 SendCommand 생략 if (m_bOpIOSta[nIndex] == bVal) { return(0); } } strCommand = string.Format("M{0}={1}", _IO.Address, bVal ? 1 : 0); nRtn = SendCommand(strCommand, ref strRet); if (nRtn > 0) { m_bOpIOSta[nIndex] = bVal; } return(nRtn); }
private void Btn_IO_List_Change_Click(object sender, EventArgs e) { if (ListView_IO_List.SelectedItems.Count <= 0) { return; } int nAdapter = ListBox_Adapter.SelectedIndex; int nModule = ListBox_Module.SelectedIndex; int nIo = ListView_IO_List.SelectedItems[0].Index; try { if (Check_IO_Name(txtBox_IoName.Text, nAdapter, nModule, nIo) == true) { MessageBox.Show("동일한 이름의 IO가 존재합니다. 이름을 변경하세요."); return; } if (MessageBox.Show("입력하신 값으로 변경 하시겠습니까?", "값 변경", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1).Equals(DialogResult.No)) { return; } DeviceNetIO _IO = m_IO_List_DataSet.DNet_Adapter[nAdapter].Module_List[nModule].IO_List[nIo]; _IO.Cable = txtBox_Cable.Text; _IO.IO_Name = txtBox_IoName.Text; //_IO.Address = Convert.ToUInt16(tbAddr.Text); Init_IoListView(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ListView_OutputList_DoubleClick(object sender, EventArgs e) { if (UseOutputControl == false) { return; } ListView listView = ((ListView)sender); int nIO_Index = listView.SelectedItems[0].Index; if (nIO_Index < 0) { return; } DeviceNetIO _IO = m_IoList_All.Output[nIO_Index]; if (_IO != null) { bool bOn = !_IO.IsOn; // 현재값과 반대로 보낸다. string strMsg = string.Format("Do you Wan't Send Select IO?\r\n\r\n - IO Name : {0}\r\n - Send Value : {1}", _IO.IO_Name, (bOn) ? "ON" : "OFF"); if (!MessageBox.Show(strMsg, "Send IO", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2).Equals(DialogResult.Yes)) { return; } m_PmacModule.GetPmac().SetOutIOValUMAC(_IO, bOn); if (SendIO_Log_Event != null) { string strLog = string.Format("IO Name : {0}, SendVal : {1}", _IO.IO_Name, bOn); SendIO_Log_Event(strLog, EventArgs.Empty); } } }
public int WriteBit(DeviceNetIO IO, bool bOn) { return(xHilscher.WriteBit(IO.Address, IO.SubAddr, bOn)); }
public bool ReadOutBit(DeviceNetIO IO) { IO.IsOn = xHilscher.ReadOutBit(IO.Address, IO.SubAddr); //IO.IsOn = true; return(IO.IsOn); }
private int Write(string strIOname, DNET_IO_TYPE type, bool bOn) { DeviceNetIO IO = cOM_DeviceNet_IO_List.GetLinkData(strIOname, type); return(cOM_DeviceNet.WriteBit(IO, bOn)); }
private bool Read(string strIOname, DNET_IO_TYPE type) { DeviceNetIO IO = cOM_DeviceNet_IO_List.GetLinkData(strIOname, type); return(cOM_DeviceNet.ReadBit(IO)); }
private void Refresh_IO_List(int nTabIndex, TabPage _Page) { if (nTabIndex < 0 || _Page == null) { return; } string strIO_Name = ""; string strIO_Type = ""; int nOutputTab = 0; foreach (Control ctrl in _Page.Controls) { if (ctrl.GetType().Name == "Win_ListView") { Win_ListView listView = ctrl as Win_ListView; if (listView != null) { foreach (ListViewItem list in listView.Items) { strIO_Name = list.SubItems[0].Text; strIO_Type = list.SubItems[5].Text; DeviceNetIO _IO = null; if (strIO_Type == DNET_IO_TYPE.D_INPUT.ToString()) { _IO = m_DNet_IoList.GetLinkData(strIO_Name, nTabIndex, DNET_IO_TYPE.D_INPUT); } else if (strIO_Type == DNET_IO_TYPE.D_OUTPUT.ToString()) { //if (nTabIndex == 1) nTabIndex = 2; //OUTPUT일 경우 TAB 2번이 없기 때문에 1번탭 이후1씩증가 if (nTabIndex >= 1) { nOutputTab = nTabIndex + 1; } _IO = m_DNet_IoList.GetLinkData(strIO_Name, nOutputTab, DNET_IO_TYPE.D_OUTPUT); } else if (strIO_Type == DNET_IO_TYPE.A_INPUT.ToString()) { _IO = m_DNet_IoList.GetLinkData(strIO_Name, nTabIndex, DNET_IO_TYPE.A_INPUT); } if (_IO != null) { if (_IO.IO_Type == DNET_IO_TYPE.D_INPUT || _IO.IO_Type == DNET_IO_TYPE.D_OUTPUT) { string strOnOff = _IO.IsOn == true ? "ON" : "OFF"; if (strOnOff != list.SubItems[3].Text) { list.SubItems[3].Text = strOnOff; } } else { list.SubItems[3].Text = _IO.AnalogValue.ToString(); } } } } } } }