using System; using System.Collections.Generic; using System.Linq; namespace IMCS_CCS.Utils.DeviceProtocol { public class DeviceFanuc { public ushort h = 0; public DeviceFanuc(string ip, string port) { Fanuc.cnc_allclibhndl3(ip, Convert.ToUInt16(port), 1, out h); } public void freehand() { Focas1.cnc_freelibhndl(h); } public string MainProg() { Focas1.ODBPRO pnum = new Focas1.ODBPRO(); int ret = Focas1.cnc_rdprgnum(h, pnum); if (ret == Fanuc.EW_OK) { return pnum.data.ToString().PadLeft(4, '0'); } else { return "error"; } } public string Status() { Focas1.ODBST cncStatus = new Focas1.ODBST(); string[] str = new string[3]; int ret = Focas1.cnc_statinfo(h, cncStatus); if (ret == Fanuc.EW_OK) { return cncStatus.run.ToString(); } else { return "error"; } } public string Mode() { Focas1.ODBST cncStatus = new Focas1.ODBST(); string[] str = new string[3]; int ret = Focas1.cnc_statinfo(h, cncStatus); if (ret == Fanuc.EW_OK) { return cncStatus.aut.ToString(); } else { return "error"; } } public string EMG() { Focas1.IODBPMC0 iodbpmc0 = new Focas1.IODBPMC0(); int ret = Focas1.pmc_rdpmcrng(h, 0, 0, 7, 12, 14, iodbpmc0); if (ret == Fanuc.EW_OK) { byte[] data = iodbpmc0.cdata; string value = Convert.ToString(data[1], 16).ToString().PadLeft(2, '0').ToUpper(); string str = Convert.ToString(Convert.ToInt32(value.ToString().Substring(0, 1)), 2).PadLeft(4, '0').Substring(3, 1); if (str == "1") return "1"; else return "0"; } else { return "error"; } } public string ActFeed() { Focas1.IODBPMC0 iodbpmco = new Focas1.IODBPMC0(); int ret = Focas1.pmc_rdpmcrng(h, 0, 1, 12, 13, 10, iodbpmco); if (ret == Fanuc.EW_OK) { return iodbpmco.cdata[0].ToString(); } else { return "error"; } } public string ActSpindle() { Focas1.ODBACT pindle = new Focas1.ODBACT(); int ret = Focas1.cnc_acts(h, pindle); if (ret == Fanuc.EW_OK) { return pindle.data.ToString(); } else { return "error"; } } public string ServoLoadX() { Focas1.ODBSVLOAD sv = new Focas1.ODBSVLOAD(); short a = 6;//伺服轴的数量 int ret = Focas1.cnc_rdsvmeter(h, ref a, sv); if (ret == Fanuc.EW_OK) { return sv.svload1.data.ToString(); } else { return "error"; } } public string ServoLoadY() { Focas1.ODBSVLOAD sv = new Focas1.ODBSVLOAD(); short a = 6;//伺服轴的数量 int ret = Focas1.cnc_rdsvmeter(h, ref a, sv); if (ret == Fanuc.EW_OK) { return sv.svload2.data.ToString(); } else { return "error"; } } public string ServoLoadZ() { Focas1.ODBSVLOAD sv = new Focas1.ODBSVLOAD(); short a = 6;//伺服轴的数量 int ret = Focas1.cnc_rdsvmeter(h, ref a, sv); if (ret == Fanuc.EW_OK) { return sv.svload3.data.ToString(); } else { return "error"; } } public string PowerOnTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(h, 6750, 0, 8, iodbpsd); if (ret == Fanuc.EW_OK) { return iodbpsd.ldata.ToString(); } else { return "error"; } } public string AccumulateCuttingTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(h, 6754, 0, 8, iodbpsd); if (ret == Fanuc.EW_OK) { return iodbpsd.ldata.ToString(); } else { return "error"; } } public string CuttingTimePerCycle() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int min = 0; int sec = 0; int ret = Focas1.cnc_rdparam(h, 6757, 0, 8, iodbpsd);//秒 if (ret == Focas1.EW_OK) { sec = iodbpsd.ldata; ret = Focas1.cnc_rdparam(h, 6758, 0, 8, iodbpsd);//分 if (ret == Focas1.EW_OK) { min = iodbpsd.ldata; return (min * 60 * 1000 + sec).ToString(); } else { return "error"; } } else { return "error"; } } public string WorkTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(h, 6752, -1, 8, iodbpsd); if (ret == Fanuc.EW_OK) { return iodbpsd.ldata.ToString(); } else { return "error"; } } public string Part_Count() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(h, 6712, 0, 8, iodbpsd); if (ret == Fanuc.EW_OK) { return iodbpsd.ldata.ToString(); } else { return "error"; } } public string ToolNo() { Focas1.ODBM odb = new Focas1.ODBM(); int ret = Focas1.cnc_rdmacro(h, 523, 10, odb); if (ret == Fanuc.EW_OK) { return (odb.mcr_val * Math.Pow(10, -odb.dec_val)).ToString(); } else { return "error"; } } public string ToolLife() { Fanuc.ODBTLIFE5 tool = new Focas1.ODBTLIFE5();//读取刀片组的序号 Fanuc.ODBTLIFE2 tool1 = new Focas1.ODBTLIFE2();//读取刀片组的全部数量 Fanuc.ODBTLIFE3 tool2 = new Focas1.ODBTLIFE3();//刀具的数量 Fanuc.ODBTG btg = new Focas1.ODBTG(); Fanuc.ODBUSEGRP grp = new Focas1.ODBUSEGRP(); int m = 2; Fanuc.cnc_rdgrpid2(h, m, tool); int group_numer = tool.data; int all = Fanuc.cnc_rdngrp(Fanuc.h, tool1);//刀片组的全部数量 short b = Convert.ToInt16(group_numer); Fanuc.cnc_rdntool(h, b, tool2);//刀具的数量 Fanuc.cnc_rdlife(h, b, tool2);//刀具寿命 Fanuc.cnc_rdcount(h, b, tool2);//刀具计时器 Fanuc.cnc_rdtoolgrp(h, 2, 20 + 20 * 1, btg);//根据刀组号读出所有信息,很重要; int ret = Fanuc.cnc_rdtlusegrp(h, grp);//读出正在使用的到组号; if (ret == Fanuc.EW_OK) { return tool2.data.ToString(); } else { return "error"; } } public List AlmMsg(out string IsAlarm) { List stateinfo = new List(); IsAlarm = "0"; ushort h = 0; short b = -1;//哪一类报警,-1所有报警 short num = 11;//设大一些没关系 Focas1.ODBALMMSG odbalmmsg2 = new Focas1.ODBALMMSG(); int ret = Focas1.cnc_rdalmmsg(h, b, ref num, odbalmmsg2); System.Type type = odbalmmsg2.GetType(); if (ret == 0) { if (num > 0) { IsAlarm = "1"; for (int i = 0; i <= num - 1; i++) { string str1 = "msg"; str1 = str1 + (i + 1); object obj = type.GetField(str1).GetValue(odbalmmsg2); //if(obj.) System.Type type1 = obj.GetType(); if (type1.GetField("alm_msg").GetValue(obj).ToString() != "") { AlmInfo s = new AlmInfo(); s.no = Convert.ToInt32(type1.GetField("alm_no").GetValue(obj).ToString()).ToString(); s.msg = type1.GetField("alm_msg").GetValue(obj).ToString(); stateinfo.Add(s); } } return stateinfo; } else { IsAlarm = "0"; AlmInfo s2 = new AlmInfo(); s2.no = "0"; s2.msg = "无报警"; stateinfo.Add(s2); return stateinfo; } } else { IsAlarm = "0"; AlmInfo s3 = new AlmInfo(); s3.no = "0"; s3.msg = "无报警"; stateinfo.Add(s3); return stateinfo; } } public string ReadSpindleSpeed() { Focas1.ODBACT pindle = new Focas1.ODBACT(); string str = ""; int ret = Focas1.cnc_acts(Fanuc.h, pindle); if (ret == 0) str = pindle.data.ToString(); else str = "错误"; return str; } public string GetSpload() { string str = ""; Focas1.ODBSPLOAD ODBSPLOAD = new Focas1.ODBSPLOAD(); short typel = 0; short bl = 4; int ret = Focas1.cnc_rdspmeter(Fanuc.h, typel, ref bl, ODBSPLOAD); if (ret == Focas1.EW_OK) str = ODBSPLOAD.spload1.spload.data.ToString(); else str = "返回错误"; return str; } public string GetSpload1() { string str = ""; Focas1.ODBSPLOAD ODBSPLOAD = new Focas1.ODBSPLOAD(); short typel = 0; short bl = 1; int ret = Focas1.cnc_rdspmeter(Fanuc.h, typel, ref bl, ODBSPLOAD); if (ret == Focas1.EW_OK) str = ODBSPLOAD.spload1.spload.data.ToString(); else str = "返回错误"; return str; } public string GetSpload2() { string str = ""; Focas1.ODBSPLOAD ODBSPLOAD = new Focas1.ODBSPLOAD(); short typel = 0; short bl = 2; int ret = Focas1.cnc_rdspmeter(Fanuc.h, typel, ref bl, ODBSPLOAD); if (ret == Focas1.EW_OK) str = ODBSPLOAD.spload1.spload.data.ToString(); else str = "返回错误"; return str; } public string GetSpload3() { string str = ""; Focas1.ODBSPLOAD ODBSPLOAD = new Focas1.ODBSPLOAD(); short typel = 0; short bl = 3; int ret = Focas1.cnc_rdspmeter(Fanuc.h, typel, ref bl, ODBSPLOAD); if (ret == Focas1.EW_OK) str = ODBSPLOAD.spload1.spload.data.ToString(); else str = "返回错误"; return str; } /// /// fanuc单次计数 /// /// public string GetNumber() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(Fanuc.h, 6711, 0, 50, iodbpsd); if (ret == 0) { return iodbpsd.idata.ToString(); } else { return "0"; } } /// /// fanuc累计计数 /// /// public string GetTotalNumber() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(Fanuc.h, 6712, 0, 8, iodbpsd); if (ret == 0) { return iodbpsd.ldata.ToString(); } else { return "0"; } } static Focas1.IODBPMC0 iodbpmco = new Focas1.IODBPMC0(); public string GetSploadRatio() { int ret = Focas1.pmc_rdpmcrng(Fanuc.h, 0, 1, 30, 31, 10, iodbpmco); if (ret == 0) { return iodbpmco.cdata[0].ToString(); } else { return "0"; } } public string GetFeedrate() { int ret = Focas1.pmc_rdpmcrng(Fanuc.h, 0, 1, 12, 13, 10, iodbpmco); if (ret == 0) { return (255 - iodbpmco.cdata[0]).ToString(); } else { return "0"; } } public string GetEmergencyStopStatus() { try { Focas1.IODBPMC0 iodbpmc0 = new Focas1.IODBPMC0(); int ret = Focas1.pmc_rdpmcrng(Fanuc.h, 0, 0, 7, 12, 14, iodbpmc0); if (ret == Focas1.EW_OK) { byte[] data = iodbpmc0.cdata; string value = Convert.ToString(data[1], 16).ToString().PadLeft(2, '0').ToUpper(); string str = Convert.ToString(Convert.ToInt32(value.ToString().Substring(0, 1)), 2).PadLeft(4, '0').Substring(3, 1); if (str == "1") { return "否"; } else { return "是"; } } else { return ret.ToString(); } } catch { return "Filed"; } } /// /// 有效轴数 /// /// 相对位置 /// 绝对位置 /// 机械位置 /// 剩余位置 /// public string GetPostion(out string xd, out string jd, out string jx, out string sy) { xd = ""; jd = ""; jx = ""; sy = ""; Fanuc.ODBPOS fos = new Focas1.ODBPOS(); short num = Fanuc.MAX_AXIS; short type = -1; short ret = Fanuc.cnc_rdposition(Fanuc.h, type, ref num, fos); if (ret == 0) { xd += fos.p1.rel.name.ToString() + ": " + fos.p1.rel.data * Math.Pow(10, -fos.p1.rel.dec) + ","; xd += fos.p2.rel.name.ToString() + ": " + fos.p2.rel.data * Math.Pow(10, -fos.p2.rel.dec) + ","; xd += fos.p3.rel.name.ToString() + ": " + fos.p3.rel.data * Math.Pow(10, -fos.p3.rel.dec) + ","; xd += fos.p4.rel.name.ToString() + ": " + fos.p4.rel.data * Math.Pow(10, -fos.p4.rel.dec) + ","; xd += fos.p5.rel.name.ToString() + ": " + fos.p5.rel.data * Math.Pow(10, -fos.p5.rel.dec); jd += fos.p1.abs.name.ToString() + ": " + fos.p1.abs.data * Math.Pow(10, -fos.p1.abs.dec) + ","; jd += fos.p2.abs.name.ToString() + ": " + fos.p2.abs.data * Math.Pow(10, -fos.p2.abs.dec) + ","; jd += fos.p3.abs.name.ToString() + ": " + fos.p3.abs.data * Math.Pow(10, -fos.p3.abs.dec) + ","; jd += fos.p4.abs.name.ToString() + ": " + fos.p4.abs.data * Math.Pow(10, -fos.p3.abs.dec) + ","; jd += fos.p5.abs.name.ToString() + ": " + fos.p5.abs.data * Math.Pow(10, -fos.p5.abs.dec); jx += fos.p1.mach.name.ToString() + ": " + fos.p1.mach.data * Math.Pow(10, -fos.p1.mach.dec) + ","; jx += fos.p2.mach.name.ToString() + ": " + fos.p2.mach.data * Math.Pow(10, -fos.p2.mach.dec) + ","; jx += fos.p3.mach.name.ToString() + ": " + fos.p3.mach.data * Math.Pow(10, -fos.p3.mach.dec) + ","; jx += fos.p4.mach.name.ToString() + ": " + fos.p4.mach.data * Math.Pow(10, -fos.p4.mach.dec) + ","; jx += fos.p5.mach.name.ToString() + ": " + fos.p5.mach.data * Math.Pow(10, -fos.p5.mach.dec); sy += fos.p1.dist.name.ToString() + ": " + fos.p1.dist.data * Math.Pow(10, -fos.p1.dist.dec) + ","; sy += fos.p2.dist.name.ToString() + ": " + fos.p2.dist.data * Math.Pow(10, -fos.p2.dist.dec) + ","; sy += fos.p3.dist.name.ToString() + ": " + fos.p3.dist.data * Math.Pow(10, -fos.p3.dist.dec) + ","; sy += fos.p4.dist.name.ToString() + ": " + fos.p3.dist.data * Math.Pow(10, -fos.p4.dist.dec) + ","; sy += fos.p5.dist.name.ToString() + ": " + fos.p5.dist.data * Math.Pow(10, -fos.p5.dist.dec); } return num.ToString(); } public string GetFeedSpeed() { Focas1.ODBACT feedspeed = new Focas1.ODBACT(); Focas1.cnc_actf(Fanuc.h, feedspeed); return feedspeed.data.ToString(); } public string GetSdTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(Fanuc.h, 6750, 0, 8, iodbpsd); if (ret == 0) { return iodbpsd.ldata.ToString(); } else { return "Filed"; } } public string GetRunningTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(Fanuc.h, 6752, -1, 8, iodbpsd); if (ret == 0) { return iodbpsd.ldata.ToString(); } else { return "Filed"; } } public string GetQXTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int ret = Focas1.cnc_rdparam(Fanuc.h, 6754, 0, 8, iodbpsd); if (ret == 0) { return iodbpsd.ldata.ToString(); } else { return "Filed"; } } public string GetCycleTime() { Focas1.IODBPSD_1 iodbpsd = new Focas1.IODBPSD_1(); int min = 0; int sec = 0; int ret = Focas1.cnc_rdparam(Fanuc.h, 6757, 0, 8, iodbpsd);//秒 if (ret == Focas1.EW_OK) { sec = iodbpsd.ldata; ret = Focas1.cnc_rdparam(Fanuc.h, 6758, 0, 8, iodbpsd);//分 if (ret == Focas1.EW_OK) { min = iodbpsd.ldata; return (min * 60 * 1000 + sec).ToString(); } else { return "Filed"; } } else { return "Filed"; } } public enum MacModeLists { MDI = 0, MEMory = 1, Null = 2, EDIT = 3, HaNDle = 4, JOG = 5, TeachInJOG = 6, TeachInHaNDle = 7, INCfeed = 8, REFerence = 9, ReMoTe = 10, } /// /// /// /// 工作模式 /// 加工状态 public void GetStateInfo(out string Macmode, out string Runstatus) { Focas1.ODBST cncStatus = new Focas1.ODBST(); string[] str = new string[3]; Focas1.cnc_statinfo(Fanuc.h, cncStatus); Macmode = Enum.GetNames(typeof(MacModeLists))[cncStatus.aut]; Runstatus = Enum.GetNames(typeof(MacModeLists))[cncStatus.run]; } /// /// 返回注册程序量 /// /// 可用程序数量 /// 未使用的内存 /// 已经使用内存 /// public string GetRegPrg(out string unreg_prg, out string unused_mem, out string used_mem) { Focas1.ODBNC_1 odbnc_1 = new Focas1.ODBNC_1(); short ret = Focas1.cnc_rdproginfo(Fanuc.h, 0, 16, odbnc_1); if (ret == Focas1.EW_OK) { unreg_prg = odbnc_1.unreg_prg.ToString(); unused_mem = ((int)(Convert.ToDouble(odbnc_1.unused_mem) / 1024.0 + 0.5)).ToString(); used_mem = ((int)(Convert.ToDouble(odbnc_1.used_mem) / 1024.0 + 0.5)).ToString(); return odbnc_1.reg_prg.ToString(); } else { unreg_prg = "Filed"; unused_mem = "Filed"; used_mem = "Filed"; return "Filed"; } } /// /// 获取当前执行的刀号 /// /// /// public string FGetToolNum() { string result = ""; Focas1.ODBM odb = new Focas1.ODBM(); var ret = Focas1.cnc_rdmacro(Fanuc.h, 4320, 10, odb); if (ret == 0) { result = (odb.mcr_val * Math.Pow(10, -odb.dec_val)).ToString(); return result; } else { return "获取失败"; } } /// /// 执行行号 /// /// /// /// public string FGetPrgSeq() { string result = ""; Focas1.ODBSEQ snum = new Focas1.ODBSEQ(); var ret = Focas1.cnc_rdseqnum(Fanuc.h, snum); if (ret == Focas1.EW_OK) { //return result = (String.Format("N{0:00000}", snum.data)); return result = snum.data.ToString(); } else { return "失败"; } } /// /// 当前执行代码 /// /// public string FGetCurrentPrg() { ushort length = 48; short b = 0; char[] c = new char[length]; var ret = Focas1.cnc_rdexecprog(Fanuc.h, ref length, out b, c); if (ret == Focas1.EW_OK) { return new string(c); } else { return "失败"; } } public string GetCanUsePrg() { Focas1.ODBNC_1 odbnc_1 = new Focas1.ODBNC_1(); short ret = Focas1.cnc_rdproginfo(Fanuc.h, 0, 16, odbnc_1); if (ret == Focas1.EW_OK) { return odbnc_1.unreg_prg.ToString(); } else { return "Filed"; } } public string GetUnUsedMes() { Focas1.ODBNC_1 odbnc_1 = new Focas1.ODBNC_1(); short ret = Focas1.cnc_rdproginfo(Fanuc.h, 0, 16, odbnc_1); if (ret == Focas1.EW_OK) { return ((int)(Convert.ToDouble(odbnc_1.unused_mem) / 1024.0 + 0.5)).ToString(); } else { return "Filed"; } } public string GetUsedMes() { Focas1.ODBNC_1 odbnc_1 = new Focas1.ODBNC_1(); short ret = Focas1.cnc_rdproginfo(Fanuc.h, 0, 16, odbnc_1); if (ret == Focas1.EW_OK) { return ((int)(Convert.ToDouble(odbnc_1.used_mem) / 1024.0 + 0.5)).ToString(); } else { return "Filed"; } } public string GetPmcProgramNumber() { Focas1.ODBPRO pnum = new Focas1.ODBPRO(); int ret = Focas1.cnc_rdprgnum(Fanuc.h, pnum); if (ret == Focas1.EW_OK) { return pnum.data.ToString().PadLeft(4, '0'); } else { return "程序号Filed"; } } public string GetProgramCodes(out string ProgramNumber) { ProgramNumber = GetPmcProgramNumber(); if (ProgramNumber != "Filed") { short cncNb = Convert.ToInt16(ProgramNumber); string data = ""; short ret = Fanuc.upload(Fanuc.h, 0, cncNb, ref data, null); if (ret == 0) { data = data.Replace("\n", "\r\n"); return data; } else { return "Filed,可能受保护"; } } else { return "Filed,可能受保护"; } } public string Get_tool_offset() { Fanuc.ODBTLINF inf = new Focas1.ODBTLINF(); Fanuc.ODBTOFS tof = new Focas1.ODBTOFS(); Fanuc.cnc_rdtofsinfo(Fanuc.h, inf); short a = inf.use_no; short b = inf.ofs_type; short ret = Fanuc.cnc_rdtofs(Fanuc.h, a, b, 8, tof); if (ret == 0) { return tof.data.ToString(); } else return "Filed"; } /// /// /// /// 刀片组数量 /// 刀片号 /// 刀组号 /// 寿命计时 public void Get_tool_life(out string dpsl, out string dph, out string dpzh, out string smjs)//读取获得刀片的有关信息 { Fanuc.ODBTLIFE5 tool = new Focas1.ODBTLIFE5();//读取刀片组的序号 Fanuc.ODBTLIFE2 tool1 = new Focas1.ODBTLIFE2();//读取刀片组的全部数量 Fanuc.ODBTLIFE3 tool2 = new Focas1.ODBTLIFE3();//刀具的数量 Fanuc.ODBTG btg = new Focas1.ODBTG(); Fanuc.ODBUSEGRP grp = new Focas1.ODBUSEGRP(); int m = 2; Fanuc.cnc_rdgrpid2(Fanuc.h, m, tool); int group_numer = tool.data; int all = Fanuc.cnc_rdngrp(Fanuc.h, tool1);//刀片组的全部数量 short b = Convert.ToInt16(group_numer); Fanuc.cnc_rdntool(Fanuc.h, b, tool2);//刀具的数量 Fanuc.cnc_rdlife(Fanuc.h, b, tool2);//刀具寿命 Fanuc.cnc_rdcount(Fanuc.h, b, tool2);//刀具计时器 Fanuc.cnc_rdtoolgrp(Fanuc.h, 2, 20 + 20 * 1, btg);//根据刀组号读出所有信息,很重要; Fanuc.cnc_rdtlusegrp(Fanuc.h, grp);//读出正在使用的到组号; dpsl = all.ToString(); dph = tool2.ToString(); dpzh = group_numer.ToString(); smjs = tool2.data.ToString(); } public int FreeHndl() { int ret = Focas1.cnc_freelibhndl(Fanuc.h); return ret; } public string bj() { string alarmmsg = ""; short b = -1;//哪一类报警,-1所有报警 short num = 11;//设大一些没关系 Focas1.ODBALMMSG odbalmmsg2 = new Focas1.ODBALMMSG(); var ret = Focas1.cnc_rdalmmsg(Fanuc.h, b, ref num, odbalmmsg2); System.Type type = odbalmmsg2.GetType(); if (ret == 0) { if (num > 0) { for (int i = 0; i <= num - 1; i++) { string str1 = "msg"; str1 = str1 + (i + 1); object obj = type.GetField(str1).GetValue(odbalmmsg2); //if(obj.) System.Type type1 = obj.GetType(); if (type1.GetField("alm_msg").GetValue(obj).ToString() != "") { alarmmsg += "第" + i + "行" + "警报号 " + type1.GetField("alm_no").GetValue(obj).ToString().Trim() + "警报信息" + type1.GetField("alm_msg").GetValue(obj).ToString().Trim() + ","; } } } else { } } else { } if (alarmmsg == "") { alarmmsg = "暂无报警"; } return alarmmsg; } public class AlmInfo { public string no { get; set; } public string msg { get; set; } } public class NcInfo { public string no { get; set; } public string lentgh { get; set; } public string comment { get; set; } } } }