信捷用起來感覺真的不方便, 剛好公司最近買了幾臺設(shè)備是用于信捷PLC的, 目前要開發(fā)上位機, 感覺信捷的寄存器什么的太多了, 寫了個地址分析的函數(shù)超長啊
public override ushort AnalyzeAddress(string strAddress)
{
Address address = Address.GetAddress(strAddress);
if (address == null) return 0;
switch (address.Type.ToLower())
{
case "m": if (address.Number <= 20480) return address.Number; break;
case "x":
if (address.Number <= 77) return (ushort)(address.Number + 20480);
else if (address.Number <= 10000 && address.Number <= 10077) return (ushort)(address.Number + 20736);
else if (address.Number <= 10100 && address.Number <= 10177) return (ushort)(address.Number + 20800);
else if (address.Number <= 10200 && address.Number <= 10277) return (ushort)(address.Number + 20864);
break;
case "y":
if (address.Number <= 77) return (ushort)(address.Number + 24576);
else if (address.Number <= 10000 && address.Number <= 10077) return (ushort)(address.Number + 24832);
else if (address.Number <= 10100 && address.Number <= 10177) return (ushort)(address.Number + 24896);
else if (address.Number <= 10200 && address.Number <= 10277) return (ushort)(address.Number + 24960);
break;
case "s": if (address.Number < 8000) return (ushort)(address.Number + 28672); break;
case "sm": if (address.Number < 4096) return (ushort)(address.Number + 36864); break;
case "t": if (address.Number < 4096) return (ushort)(address.Number + 40960); break;
case "c": if (address.Number < 4096) return (ushort)(address.Number + 45056); break;
case "et": if (address.Number < 40) return (ushort)(address.Number + 49152); break;
case "sem": if (address.Number < 128) return (ushort)(address.Number + 49280); break;
case "hm": if (address.Number < 6144) return (ushort)(address.Number + 49408); break;
case "hs": if (address.Number < 1000) return (ushort)(address.Number + 55552); break;
case "ht": if (address.Number < 1024) return (ushort)(address.Number + 57600); break;
case "hc": if (address.Number < 1024) return (ushort)(address.Number + 58624); break;
case "hsc": if (address.Number < 40) return (ushort)(address.Number + 59648); break;
case "d": if (address.Number < 20480) return (ushort)(address.Number + 28672); break;
case "id":
if (address.Number < 100) return (ushort)(address.Number + 20480);
else if (address.Number <= 10000 && address.Number <= 10099) return (ushort)(address.Number + 20736);
else if (address.Number <= 10100 && address.Number <= 10199) return (ushort)(address.Number + 20836);
else if (address.Number <= 10200 && address.Number <= 10299) return (ushort)(address.Number + 20936);
break;
case "qd":
if (address.Number < 100) return (ushort)(address.Number + 24576);
else if (address.Number <= 10000 && address.Number <= 10099) return (ushort)(address.Number + 24832);
else if (address.Number <= 10100 && address.Number <= 10199) return (ushort)(address.Number + 24932);
else if (address.Number <= 10200 && address.Number <= 10299) return (ushort)(address.Number + 25032);
break;
case "sd": if (address.Number < 4096) return (ushort)(address.Number + 28672); break;
case "td": if (address.Number < 4096) return (ushort)(address.Number + 32768); break;
case "cd": if (address.Number < 4096) return (ushort)(address.Number + 36864); break;
case "etd": if (address.Number < 40) return (ushort)(address.Number + 40960); break;
case "hd": if (address.Number < 6144) return (ushort)(address.Number + 41088); break;
case "hsd": if (address.Number < 1024) return (ushort)(address.Number + 47232); break;
case "htd": if (address.Number < 1024) return (ushort)(address.Number + 48256); break;
case "hcd": if (address.Number < 1024) return (ushort)(address.Number + 49280); break;
case "hscd": if (address.Number < 40) return (ushort)(address.Number + 50304); break;
case "fd": if (address.Number < 8192) return (ushort)(address.Number + 50368); break;
case "sfd": if (address.Number < 6000) return (ushort)(address.Number + 58560); break;
case "fs": if (address.Number < 48) return (ushort)(address.Number + 62656); break;
default:
break;
}
return ushort.MaxValue;
}