private void gridControl_View_CellDoubleClick(object sender, DataGridViewCellEventArgs e) // 그리드뷰 더블클릭 쓰기 { int row = Grid.CurrentCell.RowIndex; int col = Grid.CurrentCell.ColumnIndex; if (state == 1) { if (e.ColumnIndex > 0) // column : 15 ~ 0 { //18~21열 if (e.ColumnIndex >= 17) // Column : HIGH ~ ASCII { string selectAddr = Grid[e.ColumnIndex, 0].Value.ToString(); string dataType = string.Empty; if (string.IsNullOrEmpty(selectAddr)) { return; } int addressNo = row; if (e.ColumnIndex == 17) { dataType = PLCSetDataType.HIGHT_BYTE; // HIGH (08 ~ 15 비트) } else if (e.ColumnIndex == 18) { dataType = PLCSetDataType.LOW_BYTE; // LOW (00 ~ 07 비트) } else if (e.ColumnIndex == 19) { dataType = PLCSetDataType.INTEGER; // ALL } else if (e.ColumnIndex == 20) { dataType = PLCSetDataType.ASCII; // ASCII } InputUI form = new InputUI(dataType, iSelectedRegister, iSelectedAddress + addressNo, this); form.ShowDialog(); } //1~16열 else { Grid[col, row].Value = 1; // 선택한 셀 데이터 값 1 int tmp = 0; try { tmp = int.Parse(Grid[e.ColumnIndex, e.RowIndex].Value.ToString()); // 문자열을 숫자로 변환 함수 } catch { return; } CDataSet ds = new CDataSet(2); byte[] tmpbyte = new byte[2]; tmpbyte = PLCManager.ReadForByte(Device_Def.SearchDeviceCode(Device_Def.Device), iSelectedAddress + (e.RowIndex), 2); // 바이트로 읽기 ds.SetSourceByteArray(0, tmpbyte); ds.SetSource(16 - e.ColumnIndex, (ds.GetSource(16 - e.ColumnIndex) == true) ? false : true); PLCManager.WriteForByte(Device_Def.SearchDeviceCode(Device_Def.Device), iSelectedAddress + (e.RowIndex), ds.GetSource()); // 바이트로 쓰기 } } RefreshDisplayPLCData(); } if (state == 2) { if (e.ColumnIndex > 0) // column : 15 ~ 0 { //18~21열 if (e.ColumnIndex >= 17) // Column : HIGH ~ ASCII { string selectAddr = Grid[e.ColumnIndex, 0].Value.ToString(); string dataType = string.Empty; if (string.IsNullOrEmpty(selectAddr)) { return; } int addressNo = row; if (e.ColumnIndex == 17) { dataType = PLCSetDataType.HIGHT_BYTE; // HIGH (08 ~ 15 비트) } else if (e.ColumnIndex == 18) { dataType = PLCSetDataType.LOW_BYTE; // LOW (00 ~ 07 비트) } else if (e.ColumnIndex == 19) { dataType = PLCSetDataType.INTEGER; // ALL } else if (e.ColumnIndex == 20) { dataType = PLCSetDataType.ASCII; // ASCII } InputUI form = new InputUI(dataType, iSelectedRegister, iSelectedAddress + addressNo, this); form.ShowDialog(); //RefreshDisplayPLCData(); } else { Grid[col, row].Value = 1; CDataSet ds = new CDataSet(2); byte[] tmpbyte = new byte[2]; tmpbyte = PLCManager.ReadForByte(Device_Def.SearchDeviceCode(Device_Def.Device), iSelectedAddress + (e.RowIndex), 2); // 바이트로 읽기 ds.SetSourceByteArray(0, tmpbyte); ds.SetSource(16 - e.ColumnIndex, (ds.GetSource(16 - e.ColumnIndex) == true) ? false : true); PLCManager.WriteForByte(Device_Def.SearchDeviceCode(Device_Def.Device), iSelectedAddress + (e.RowIndex), ds.GetSource()); wSendFrame.MakeWriteFrame(Device_Def.CMD_WORD_UNIT, Device_Def.SearchDeviceCode(Device), ds.GetSource(), iSelectedAddress + (e.RowIndex), 1); if (CL.SendMessage(wSendFrame) == false) { } } } DisplayGridData(); } }