Ejemplo n.º 1
0
        public static DataTable ReadAlarmHistory18i(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.ODBAHIS             obj18i = new FocasLibBase.ODBAHIS();
                    List <FocasLibBase.ALM_HIS_data> focasAlarmsObjobj18i = new List <FocasLibBase.ALM_HIS_data>();

                    ushort loop_count = (ushort)(totalAlarms / 10);
                    ushort remainder = (ushort)(totalAlarms % 10);
                    ushort i = 0, s_no = 0, e_no = 0;
                    ushort length18i = (ushort)Marshal.SizeOf(obj18i);
                    for (i = 0; i <= loop_count; i++)
                    {
                        focasAlarmsObjobj18i.Clear();
                        if (i == loop_count)
                        {
                            if (remainder == 0)
                            {
                                continue;
                            }
                            s_no = (ushort)(i * 10 + 1);
                            e_no = (ushort)(s_no + (remainder - 1));
                            ret  = FocasLib.cnc_rdalmhistry(focasLibHandle, s_no, e_no, length18i, obj18i);
                            if (ret != 0)
                            {
                                Logger.WriteErrorLog("cnc_rdalmhistry() failed. return value is = " + ret);
                            }
                            get_ahd_objects(ref focasAlarmsObjobj18i, obj18i);
                            for (int j = 0; j < remainder; j++)
                            {
                                row = alarms.NewRow();
                                Utility.get_datatable_row(focasAlarmsObjobj18i[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_rdalmhistry(focasLibHandle, s_no, e_no, length18i, obj18i);
                            if (ret != 0)
                            {
                                Logger.WriteErrorLog("cnc_rdalmhistry() failed. return value is = " + ret);
                            }
                            get_ahd_objects(ref focasAlarmsObjobj18i, obj18i);
                            for (int j = 0; j < 10; j++)
                            {
                                row = alarms.NewRow();
                                Utility.get_datatable_row(focasAlarmsObjobj18i[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);
        }