Esempio n. 1
0
        public byte[] Write_byt_adr(int value, int start_adr)
        {                           //string형 파라미터를 인트로 변환시키고 4짜리 배열에 바이트형으로 변환시켜 넣는다
            byte[] Start_ADR = Get_Start_Adr(start_adr.ToString());
            bool   Ark       = true;
            int    Data      = 21;

            byte[] byt2 = new byte[2];

            byte[] byt = new byte[Data + 2];
            if (byt[00] != Device_Def.SubHeader1 || byt[01] != Device_Def.SubHeader2)
            {
                Ark = false;                                                                         // check Sub header
            }
            else if (byt[02] != Device_Def.NetworkNumber)
            {
                Ark = false;                                             // check Network Number
            }
            byt[00] = Device_Def.SubHeader1;
            byt[01] = Device_Def.SubHeader2;
            byt[02] = 0x00;
            byt[03] = 0xff;                      // PC Number
            byt[04] = Device_Def.Start_IO1;      // Start I/O - 1 (선두 I/O) - Gx Developer에 의해 설정된 번호
            byt[05] = Device_Def.Start_IO2;      // Start I/0 - 2
            byt[06] = Device_Def.Station_Number; // Station Number (국번) - Gx Developer에 의해 설정된 번호
            byt[07] = 0x0C;                      // 데이터 부의 길이 - 1 (data length 이후부터 길이)
            byt[08] = 0x00;                      // 데이터 부의 길이 - 2 (data length 이후부터 길이)
            byt[09] = Device_Def.Monitor_timer1; // 모니터 타이머 1
            byt[10] = Device_Def.Monitor_timer2; // 모니터 타이머 2

            byt[11] = 0x01;                      // Command 1 : 0401
            byt[12] = 0x14;                      // Command 2 : 1401 = 쓰기
            byt[13] = 0x00;                      // Sub Command 1 : 0000 (Word 단위 처리)
            byt[14] = 0x00;                      // Sub Command 2 : 0000 (Word 단위 처리)


            // 아래 [15]번지 ~ [17]번지까지는 D 변수의 시작번지 -

            byt[15] = Start_ADR[0];
            byt[16] = Start_ADR[1];
            byt[17] = Start_ADR[2];


            byt[18] = Device_Def.SearchDeviceCode(Device_Def.Device);

            byt[19] = 0x01;    // 어드레스 길이 1
            byt[20] = 0x00;    // 어드레스 길이 2
            byt2    = BitConverter.GetBytes(value);
            byt[21] = byt2[0]; // 홀수 하이
            byt[22] = byt2[1]; // 홀수 하이
            return(byt);
        }
Esempio n. 2
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     iSelectedRegister = Device_Def.SearchDeviceCode(comboBox1.Text);
     DeviceName        = comboBox1.Text;
 }
Esempio n. 3
0
        void DisplayGridData()
        {
            byte[] tmpdata = new byte[m_nReadLength * 3];

            SendFrame.MakeReadFrame(Device_Def.CMD_WORD_UNIT, Device_Def.SearchDeviceCode(DeviceName), iSelectedAddress, m_nReadLength);

            if (CL.SendMessage(SendFrame) == false)
            {
                return;
            }
            else
            {
                CDataObject data = CL.GetReceiveData();

                if (data != null)
                {
                    if (data.Count == (m_nReadLength * 2 + 11))
                    {
                        if (data.m_Data[9] == 0x00 && data.m_Data[10] == 0x00)
                        {
                            Array.Copy(data.m_Data, 11, tmpdata, 0, m_nReadLength * 2);
                        }
                    }
                    else
                    {
                    }
                }
            }
            //row만큼 반복
            for (int nRow = 0; nRow < Grid.RowCount - 1; nRow++)
            {
                int nColumnIndex = 0;
                // Address
                string szDeviceName = String.Format("{0}{1}", DeviceName, iSelectedAddress + nRow);
                Grid.Rows[nRow].Cells[nColumnIndex].Value = szDeviceName;
                nColumnIndex++;

                //low
                for (int nCol = 0; nCol < 8; nCol++)
                {
                    //데이터 배열값과 값이 같으면0
                    int v = (1 << (nCol % 8));
                    if ((tmpdata[nRow * 2 + 1] & (1 << (nCol % 8))) == 0)
                    {
                        Grid.Rows[nRow].Cells[8 - nCol].Value           = 0;
                        Grid.Rows[nRow].Cells[8 - nCol].Style.BackColor = Color.White;
                    }
                    //다르면 1
                    else
                    {
                        Grid.Rows[nRow].Cells[8 - nCol].Value           = 1;
                        Grid.Rows[nRow].Cells[8 - nCol].Style.BackColor = Color.Cyan;
                    }

                    nColumnIndex++;
                }
                //high
                for (int nCol = 0; nCol < 8; nCol++)
                {
                    if ((tmpdata[nRow * 2] & (1 << (nCol % 8))) == 0)
                    {
                        Grid.Rows[nRow].Cells[16 - nCol].Value           = 0;
                        Grid.Rows[nRow].Cells[16 - nCol].Style.BackColor = Color.White;
                    }
                    else
                    {
                        Grid.Rows[nRow].Cells[16 - nCol].Value           = 1;
                        Grid.Rows[nRow].Cells[16 - nCol].Style.BackColor = Color.Cyan;
                    }


                    nColumnIndex++;
                }
                //17
                Grid.Rows[nRow].Cells[nColumnIndex].Value = tmpdata[nRow * 2 + 1];
                nColumnIndex++;
                //18
                Grid.Rows[nRow].Cells[nColumnIndex].Value = tmpdata[nRow * 2];
                nColumnIndex++;

                // All
                Grid.Rows[nRow].Cells[nColumnIndex].Value = GetIntLengthWord(tmpdata, nRow * 2);
                nColumnIndex++;

                // ASCII
                Grid.Rows[nRow].Cells[nColumnIndex].Value = Encoding.Default.GetString(tmpdata, nRow * 2 + 1, 1) + Encoding.Default.GetString(tmpdata, nRow * 2, 1);
            }
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
        public void Gridset(int Start_ad, String Device)
        {
            byte[] tmpdata = new byte[readL * 2];



            Grid_Array = new int[UI_set.GridLowCount];
            int[] A = Device_Def.Search_Device_Array(Device);

            for (int i = 0; i < Grid_Array.Length; i++)
            {
                Grid_Array[i] = A[Start_ad + i];
            }

            String[] DGV_Data    = new String[Grid.ColumnCount];
            int      value_index = DGV_Data.Length - 4;


            for (int j = Start_ad; j < UI_set.GridLowCount + Start_ad; j++)
            {
                int i       = 1;
                int Address = Start_ad + j;
                //Address값 출력 D0,D1..
                DGV_Data[0] = Device_Def.Device + Address.ToString();

                //디바이스의 배열 j번쨰를 2진법으로
                String bin = Convert.ToString(A[j], 2);

                //17 - 1
                for (; i < value_index - bin.Length; i++)
                {
                    DGV_Data[i] = "0";
                }
                // 1
                for (int k = 0; k < bin.Length; k++)
                {
                    String msg = bin.Substring(k, 1);
                    DGV_Data[i] = msg;
                    i++;
                }

                byte[] b = BitConverter.GetBytes(A[j]);
                DGV_Data[value_index] = b[0].ToString();
                //high 컬럼 값
                DGV_Data[value_index + 1] = ""; //b[1].ToString();
                //low 컬럼 값
                DGV_Data[value_index + 2] = ""; // A[j].ToString();
                try
                {
                    //All 컬럼 값
                    if (Convert.ToChar(b[0].ToString()).ToString().Equals(""))
                    {
                        DGV_Data[value_index + 3] = "";
                    }
                    else
                    {
                        DGV_Data[value_index + 3] = Convert.ToChar(b[0].ToString()).ToString();
                    }
                }
                catch (Exception e)
                {
                    DGV_Data[value_index + 3] += "";
                }


                try
                {
                    if (Convert.ToChar(b[1].ToString()).ToString().Equals(""))
                    {
                        DGV_Data[value_index + 3] += "";
                    }
                    else
                    {
                        DGV_Data[value_index + 3] += Convert.ToChar(b[1].ToString()).ToString();
                    }
                }
                catch (Exception e)
                {
                    DGV_Data[value_index + 3] += "";
                }


                Grid.Rows.Add(DGV_Data);
            }
        }
Esempio n. 6
0
 internal void SendStringValue(byte[] values, int AddressNo)
 {
     SendFrame.MakeWriteFrame(Device_Def.CMD_WORD_UNIT, Device_Def.SearchDeviceCode(Device), values, AddressNo, 1);
     CL.SendMessage(SendFrame);
 }