コード例 #1
0
ファイル: FormStart.cs プロジェクト: HongJunJan/Fa1811ths
        private void 故障碼View_Show()
        {
            try
            {
                if (GlobalData.ListView_Show_OnCode != GlobalData.ListView_Show_OnCode_比對用)
                {
                    listView1.Items.Clear();
                    GlobalData.ListView_Show_OnCode_比對用 = string.Empty;
                    string   ListTime = string.Empty; string ListMsg = string.Empty; string Err = string.Empty;
                    string[] ErrorStrArray = GlobalData.ListView_Show_OnCode.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    int      ErrorNum      = ErrorStrArray.Length;
                    if (ErrorNum >= 1)
                    {
                        for (int i = 0; i < ErrorNum; i++)
                        {
                            string Error_only_Str_Temp = ErrorStrArray[i];
                            int    one, two;
                            string numStr1 = Error_only_Str_Temp.Substring(0, 3);
                            string numStr2 = APP.右邊開始取字串(Error_only_Str_Temp, 2);
                            one      = Convert.ToInt32(numStr1) - DmTable.Err_HR_點位起始;
                            two      = Convert.ToInt32(numStr2);
                            ListTime = GlobalData.ALL_Error[one, two, 0];
                            ListMsg  = GlobalData.ALL_Error[one, two, 1];
                            Err      = Error_only_Str_Temp;
                            if (!string.IsNullOrEmpty(ListTime) && !string.IsNullOrEmpty(ListMsg))
                            {
                                DataRow row = GlobalData.dvTable_All_Error.NewRow();
                                row[0] = ListTime;
                                row[1] = ListMsg;
                                row[2] = Err;

                                GlobalData.dvTable_All_Error.Rows.Add(row);
                                GlobalData.dvTable_All_Error.DefaultView.Sort = "Time DESC";
                                GlobalData.dvTable_All_Error = GlobalData.dvTable_All_Error.DefaultView.ToTable();
                            }
                        }
                        foreach (DataRow row in GlobalData.dvTable_All_Error.Rows)
                        {
                            ListViewItem item = new ListViewItem(row[0].ToString());
                            for (int x = 1; x < GlobalData.dvTable_All_Error.Columns.Count; x++)
                            {
                                item.SubItems.Add(row[x].ToString());
                            }
                            listView1.Items.Add(item);
                        }

                        GlobalData.dvTable_All_Error.Rows.Clear();
                        GlobalData.ListView_Show_OnCode_比對用 = GlobalData.ListView_Show_OnCode.Trim();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception錯誤");
            }
        }
コード例 #2
0
ファイル: FormStart.cs プロジェクト: HongJunJan/Fa1811ths
        private void 紀錄_寫入故障紀錄(string ON_OFF, string alert)
        {
            try
            {
                IErrorDescriptionService errorDescriptionService = new ErrorDescriptionService();
                ResponseModel            responseModel           = errorDescriptionService.GetAllData();
                List <string>            errorList = alert.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                foreach (var errorId in errorList)
                {
                    ErrorDescription list = responseModel.ErrorDescriptionList.Where(x => x.ErrorID == errorId).FirstOrDefault();
                    if (!string.IsNullOrEmpty(list.ChDescription))
                    {
                        int one = Convert.ToInt32(list.ErrorID.Substring(0, 3)) - DmTable.Err_HR_點位起始;
                        int two = Convert.ToInt32(APP.右邊開始取字串(list.ErrorID, 2));
                        if (ON_OFF == "ON")
                        {
                            GlobalData.ALL_Error[one, two, 0] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                            GlobalData.ALL_Error[one, two, 1] = list.ChDescription;
                            GlobalData.ALL_Error[one, two, 4] = list.ErrorID;
                        }
                        else
                        {
                            string startTime = GlobalData.ALL_Error[one, two, 0];
                            string endTime   = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                            string message   = GlobalData.ALL_Error[one, two, 1];

                            // 寫入DB
                            IRecErrorService recErrorService = new RecErrorService();
                            recErrorService.AddData(new RecError
                            {
                                StartTime = Convert.ToDateTime(startTime),
                                EndTime   = Convert.ToDateTime(endTime),
                                ErrorID   = errorId,
                                Message   = message,
                                UserName  = GlobalParameter.UserName
                            });

                            // 寫出txt檔
                            string month     = string.Format("{0}月", DateTime.Now.Month.ToString());
                            string fileName  = string.Format("ErrorCode{0}.txt", DateTime.Now.ToString("yyyy/MM/dd"));
                            string pathWrite = Path.Combine("C:", month, fileName);
                            string content   = string.Format("{0},{1},{2},{3}", startTime, endTime, errorId, message);
                            File.AppendAllText(pathWrite, content, Encoding.Default);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception錯誤");
            }
        }
コード例 #3
0
ファイル: FormStart.cs プロジェクト: HongJunJan/Fa1811ths
        private void 定時偵測故障碼()
        {
            try
            {
                string Alert_ON = string.Empty; string Alert_OFF = string.Empty;
                int[]  Error_On = new int[16]; int[] Error_Xor_On = new int[16];
                GlobalData.ListView_Show_OnCode = string.Empty;

                // 故障碼總組數10組
                for (int i = 0; i < 10; i++)
                {
                    // 比對故障碼 DM Word 是否有變化
                    if (GlobalData.Err_Change_Word[i] != GlobalData.DM[DmTable.DM_8000_Err_DM_故障碼起始 + i])
                    {
                        GlobalData.Err_Change_Word[i] = GlobalData.DM[DmTable.DM_8000_Err_DM_故障碼起始 + i];

                        // (此Word為16進位)將16進位的字串,轉成2進位,並補足16個點位
                        GlobalData.Err_Change_Bit[i] = APP.補足位數(APP.各種進位轉換(GlobalData.Err_Change_Word[i], 16, 2), 16);
                        for (int x = 0; x < 16; x++)
                        {
                            Error_On[x]     = Convert.ToInt32(GlobalData.Err_Change_Bit[i].Substring(x, 1));
                            Error_Xor_On[x] = Error_On[x] ^ Convert.ToInt32(GlobalData.Err_比對用_Bit[i].Substring(x, 1));
                            if (Error_Xor_On[x] == 1 && Error_On[x] == 1)
                            {//異常碼 ON
                                string parameter = APP.補足位數((15 - x).ToString(), 2);
                                Alert_ON += (DmTable.Err_HR_點位起始 + i) + "." + parameter + ";";
                            }
                            else
                            { //異常碼 OFF
                                string parameter = APP.補足位數((15 - x).ToString(), 2);
                                Alert_OFF += (DmTable.Err_HR_點位起始 + i) + "." + parameter + ";";
                            }
                        }

                        GlobalData.Err_比對用_Bit[i] = GlobalData.Err_Change_Bit[i];
                    }
                    for (int m = 0; m < 16; m++)
                    {
                        Error_On[m] = Convert.ToInt32(GlobalData.Err_Change_Bit[i].Substring(m, 1));
                        if (Error_On[m] == 1)
                        {
                            string parameter = APP.補足位數((15 - m).ToString(), 2);
                            GlobalData.ListView_Show_OnCode += (DmTable.Err_HR_點位起始 + i) + "." + parameter + ";";
                        }
                    }
                }

                if (Alert_ON != "")
                {
                    紀錄_寫入故障紀錄("ON", Alert_ON);
                }

                if (Alert_OFF != "")
                {
                    紀錄_寫入故障紀錄("OFF", Alert_OFF);
                }

                故障碼View_Show();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception錯誤");
            }
        }
コード例 #4
0
ファイル: APP.cs プロジェクト: HongJunJan/Fa1811ths
        public static void PLC放入對應的R位置(string ReciveStr)
        {
            int ResponseLen = ReciveStr.Length;

            if (ResponseLen == (GlobalData.PLC_R區結束位址 - GlobalData.PLC_R區起始位址))
            {
                int k = 0;
                for (int j = 0; j < GlobalData.PLC_R_Scan_NUM; j++)
                {
                    GlobalData.R[GlobalData.PLC_R區起始位址 + j + ((0) * GlobalData.PLC_R_Scan_NUM)] = APP.紀錄字串轉int(ReciveStr.Substring(k, 1));
                    k = k + 1;
                }
            }
        }
コード例 #5
0
ファイル: APP.cs プロジェクト: HongJunJan/Fa1811ths
        public static void PLC放入對應的DM位置(string ReciveStr)
        {
            int ResponseLen = ReciveStr.Length / 5;

            if (ResponseLen == (GlobalData.PLC_D區結束位址 - GlobalData.PLC_D區起始位址))
            {
                int k = 0;
                for (int j = 0; j < GlobalData.PLC_DM_Scan_NUM; j++)
                {
                    GlobalData.DM[GlobalData.PLC_D區起始位址 + j + ((0) * GlobalData.PLC_DM_Scan_NUM)] = APP.紀錄字串轉int(ReciveStr.Substring(k, 5));
                    GlobalData.DM[GlobalData.PLC_D區起始位址 + j + ((0) * GlobalData.PLC_DM_Scan_NUM)] = 各種進位轉換(ReciveStr.Substring(k, 5), 10, 16);
                    var xxx = 各種進位轉換(ReciveStr.Substring(k, 5), 10, 16);
                    k = k + 5;
                }
            }
        }