コード例 #1
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            Connect();

            XGTData vData = new XGTData();

            List <XgtAddressData> lstAdress = new List <XgtAddressData>();

            string[] ArrayAdress = txtAdress.Text.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string item in ArrayAdress)
            {
                XgtAddressData addrData = new XgtAddressData();
                addrData.Address = item;
                lstAdress.Add(addrData);
            }

            if (lstAdress.Count == 0)
            {
                txtLog.Text    = "메모리 주소를 입력하세요.";
                txtAdress.Text = string.Empty;
                txtAdress.Focus();
                return;
            }

            if (rd1.Checked)  //개별
            {
                vData = xgt.Read(XGT_DataType.Word, lstAdress, XGT_MemoryType.DataRegister, 1);

                txtTX.Text  = vData.TXstring;
                txtRX.Text  = vData.RXstring;
                txtLog.Text = vData.Message;
            }

            if (rd2.Checked)  //연속
            {
                if (lstAdress.Count > 1)
                {
                    txtLog.Text    = "연속읽기는 메모리 시작 번지 1개만 입력하세요.";
                    txtAdress.Text = string.Empty;
                    txtAdress.Focus();
                    return;
                }

                int vDataCount = 0;
                if (!int.TryParse(txtCount.Text, out vDataCount))
                {
                    txtLog.Text   = "카운터는 숫자형식 이여야 합니다.";
                    txtCount.Text = string.Empty;
                    txtCount.Focus();
                    return;
                }

                vData       = xgt.Read(XGT_DataType.Continue, lstAdress, XGT_MemoryType.DataRegister, 1, vDataCount);
                txtTX.Text  = vData.TXstring;
                txtRX.Text  = vData.RXstring;
                txtLog.Text = vData.Message;
            }


            txtRead.Text  = vData.BlockCount.ToString() + Environment.NewLine;
            txtRead.Text += vData.DataType.ToString() + Environment.NewLine;
            txtRead.Text += vData.ResponseStatus.ToString() + Environment.NewLine;
            txtRead.Text += vData.ResponseType.ToString() + Environment.NewLine;
            txtRead.Text += vData.NAK_ErrorCotent.ToString() + Environment.NewLine;
            txtRead.Text += vData.Message.ToString() + Environment.NewLine;
            txtRead.Text += "<데이터 정보>" + Environment.NewLine;
            foreach (var item in vData.DataList)
            {
                txtRead.Text += item.Data.ToString() + Environment.NewLine;
            }

            DisConnect();
        }
コード例 #2
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //BIT 쓰기
            Connect();
            XGTData vData = new XGTData();
            List <XgtAddressData> lstAdress = new List <XgtAddressData>();

            string[] ArrayAdress = txtAdress.Text.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string item in ArrayAdress)
            {
                XgtAddressData addrData = new XgtAddressData();
                addrData.Address = item;
                addrData.Data    = txtInputValue.Text.ToString(); //입력데이터

                lstAdress.Add(addrData);
            }


            string vMessage = string.Empty;

            if (rd1.Checked)
            {
                vData = xgt.Write(XGT_DataType.Bit, lstAdress, XGT_MemoryType.SubRelay, 1);

                txtTX.Text  = vData.TXstring;
                txtRX.Text  = vData.RXstring;
                txtLog.Text = vData.Message;
            }

            if (rd2.Checked)
            {
                if (lstAdress.Count > 1)
                {
                    txtLog.Text    = "연속쓰기는 메모리 시작 번지 1개만 입력하세요.";
                    txtAdress.Text = string.Empty;
                    txtAdress.Focus();
                    return;
                }

                int vDataCount = 0;
                if (!int.TryParse(txtCount.Text, out vDataCount))
                {
                    txtLog.Text   = "카운터는 숫자형식 이여야 합니다.";
                    txtCount.Text = string.Empty;
                    txtCount.Focus();
                    return;
                }

                vData       = xgt.Write(XGT_DataType.Continue, lstAdress, XGT_MemoryType.DataRegister, 1, vDataCount);
                txtTX.Text  = vData.TXstring;
                txtRX.Text  = vData.RXstring;
                txtLog.Text = vData.Message;
            }

            DisConnect();

            txtWrite.Text  = vData.BlockCount.ToString() + Environment.NewLine;
            txtWrite.Text += vData.DataType.ToString() + Environment.NewLine;
            txtWrite.Text += vData.ResponseStatus.ToString() + Environment.NewLine;
            txtWrite.Text += vData.ResponseType.ToString() + Environment.NewLine;
            txtWrite.Text += vData.NAK_ErrorCotent.ToString() + Environment.NewLine;
            txtWrite.Text += vData.Message.ToString() + Environment.NewLine;
            txtWrite.Text += "<데이터 정보>" + Environment.NewLine;
            foreach (var item in vData.DataList)
            {
                txtWrite.Text += item.Data.ToString() + Environment.NewLine;
            }
        }