コード例 #1
0
        public void GetProcessTable(ref DataTable dta)
        {
            int    iReturnCode;                         //Return code
            int    iStartAddr;
            int    iStart;
            string szAdd = "ZR";
            string szDeviceName;                //List data for 'DeviceName'
            int    iNumberOfData = 32;          //Data for 'DeviceSize'

            short[] arrDeviceValue   = new short[iNumberOfData];
            int     iProcessType     = 0;
            int     iProcessDepth    = 0;
            int     iNormalReverse   = 0;
            int     iReverseWidth    = 0;
            int     iMarginofAdvance = 0;
            int     iMarginofDelay   = 0;
            int     iCutOff          = 0;
            string  szProcessName    = "";
            List <ProcessTableData> processtables = new List <ProcessTableData>();

            //DataTable dta = new DataTable();

            try
            {
                int idx = 0;
                for (int cclink = 1; cclink <= 4; cclink++)
                {
                    iStart = ((cclink - 1) * 1000) + 3000;
                    for (int stno = 1; stno <= 30; stno++)
                    {
                        iStartAddr   = ((stno - 1) * 32) + iStart;
                        szDeviceName = szAdd + iStartAddr.ToString();
                        iReturnCode  = 0;
                        if (Connected == true)
                        {
                            iReturnCode = plc.ReadDeviceBlock2(szDeviceName, iNumberOfData, out arrDeviceValue[0]);
                        }
                        if (iReturnCode == 0)
                        {
                            int k = 0;
                            szProcessName = "";
                            foreach (var baca in arrDeviceValue)
                            {
                                if (k < 16)
                                {
                                    switch (k)
                                    {
                                    case 0:
                                        iProcessType = baca;
                                        break;

                                    case 1:
                                        iProcessDepth = baca;
                                        break;

                                    case 2:
                                        iNormalReverse = baca;
                                        break;

                                    case 3:
                                        iReverseWidth = baca;
                                        break;

                                    case 4:
                                        iMarginofAdvance = baca;
                                        break;

                                    case 5:
                                        iMarginofDelay = baca;
                                        break;

                                    case 6:
                                        iCutOff = baca;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                else
                                {
                                    byte[] kon = BitConverter.GetBytes(baca);

                                    foreach (byte m in kon)
                                    {
                                        char tchar = Convert.ToChar(m);
                                        szProcessName += tchar.ToString();
                                    }
                                }
                                k++;
                            }
                            //insert to datatable
                            processtables.Add(new ProcessTableData
                            {
                                id              = idx,
                                cc_link_no      = cclink,
                                stno            = stno,
                                process_type    = iProcessType,
                                depth           = iProcessDepth,
                                normal_reverse  = iNormalReverse,
                                margin_reverse  = iReverseWidth,
                                margin_of_adv   = iMarginofAdvance,
                                margin_of_delay = iMarginofDelay,
                                cut_off         = iCutOff,
                                process_name    = szProcessName
                            });
                        }
                        idx++;
                    }
                }
                //ListtoDataTable lsttodt = new ListtoDataTable();
                dta = ListtoDataTable.ListToDataTable(processtables);
            }
            //Exception processing
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                string stringFormat = "Read Process Table Failed";
                StatusPLCLog = stringFormat;
            }
            //return dta;
        }