public static AlarmHistoryDTO ReadCurrentAlarm(ushort handle) { int ret = 0; AlarmHistoryDTO latestAlarm = new AlarmHistoryDTO(); try { ret = FocasLib.cnc_stopophis(handle); ushort totalAlarms = 0; FocasLibBase.ODBAHIS5 obj = new FocasLibBase.ODBAHIS5(); ret = FocasLib.cnc_rdalmhisno(handle, out totalAlarms); ret = FocasLib.cnc_rdalmhistry5(handle, totalAlarms, totalAlarms, (ushort)Marshal.SizeOf(obj), obj); if (ret == 0 && obj != null) { latestAlarm.AlarmNo = obj.alm_his.data1.alm_no; latestAlarm.AlarmGroupNo = obj.alm_his.data1.alm_grp; latestAlarm.AlarmMessage = obj.alm_his.data1.alm_msg; latestAlarm.AlarmTime = Utility.ConvertToDate(obj.alm_his.data1); } } catch (Exception ex) { } finally { ret = FocasLib.cnc_startophis(handle); } return(latestAlarm); }
public static DataTable ReadAlarmHistory(string machineID, string ipAddress, ushort portNo) { int ret = 0; ushort focasLibHandle = 0; DataTable alarms = Utility.get_table(); try { ret = FocasLib.cnc_allclibhndl3(ipAddress, portNo, 10, out focasLibHandle); if (ret == 0) { ret = FocasLib.cnc_stopophis(focasLibHandle); if (ret != 0) { Logger.WriteErrorLog("cnc_stopophis() failed. return value is = " + ret); } ushort totalAlarms = 0; ret = FocasLib.cnc_rdalmhisno(focasLibHandle, out totalAlarms); if (ret != 0) { Logger.WriteErrorLog("cnc_rdalmhisno() failed. return value is = " + ret); } if (totalAlarms == 0) { return(alarms); } //10 rows at a time DataRow row = default(DataRow); FocasLibBase.ODBAHIS5 obj = new FocasLibBase.ODBAHIS5(); List <FocasLibBase.ALM_HIS5_data> focasAlarmsObj = new List <FocasLibBase.ALM_HIS5_data>();//almhisdata object list ushort loop_count = (ushort)(totalAlarms / 10); ushort remainder = (ushort)(totalAlarms % 10); ushort i = 0, s_no = 0, e_no = 0; //ushort length = 4 + 512 * 10; ushort length = (ushort)Marshal.SizeOf(obj); for (i = 0; i <= loop_count; i++) { if (i == loop_count) { if (remainder == 0) { continue; } s_no = (ushort)(i * 10 + 1); e_no = (ushort)(s_no + (remainder - 1)); ret = FocasLib.cnc_rdalmhistry5(focasLibHandle, s_no, e_no, length, obj); if (ret != 0) { Logger.WriteErrorLog("cnc_rdalmhistry5() failed. return value is = " + ret); } focasAlarmsObj.Clear(); get_ahd_objects(ref focasAlarmsObj, obj); for (int j = 0; j < remainder; j++) { row = alarms.NewRow(); Utility.get_datatable_row(focasAlarmsObj[j], ref row); row["MachineID"] = machineID; alarms.Rows.Add(row); } } else { s_no = (ushort)(i * 10 + 1); e_no = (ushort)(s_no + 9); ret = FocasLib.cnc_rdalmhistry5(focasLibHandle, s_no, e_no, length, obj); if (ret != 0) { Logger.WriteErrorLog("cnc_rdalmhistry5() failed. return value is = " + ret); } focasAlarmsObj.Clear(); get_ahd_objects(ref focasAlarmsObj, obj);// for (int j = 0; j < 10; j++) { row = alarms.NewRow(); Utility.get_datatable_row(focasAlarmsObj[j], ref row); row["MachineID"] = machineID; alarms.Rows.Add(row); } } } } } catch (Exception ex) { Logger.WriteErrorLog(ex.ToString()); } finally { if (focasLibHandle > 0) { ret = FocasLib.cnc_startophis(focasLibHandle); FocasData.cnc_freelibhndl(focasLibHandle); } } return(alarms); }