public int GetDevice2(string Device) { int value = -1; int i = 0; for (; i < Device.Length; i++) { if (Device.ToCharArray()[i] >= 0x30 && Device.ToCharArray()[i] <= 0x39) { break; } } string ext = Device.Substring(0, i); int currentIndex = Convert.ToInt32(Device.Substring(i, Device.Length - i)); int nextIndex = currentIndex + 1; string DeviceH = ext + nextIndex.ToString(); string DeviceL = ext + currentIndex.ToString(); int valueL = 0; int valueH = 0; SLMPResult staH = GetDevice(DeviceH); SLMPResult staL = GetDevice(DeviceL); if (staH.Status == SLMPStatus.SUCCESSFULLY && staL.Status == SLMPStatus.SUCCESSFULLY) { valueH = staH.Value; valueL = staL.Value; valueH = valueH << 16; value = valueH | valueL; } return(value); }
public int SetDevice2(string Device, int value) { uint val = (uint)value; int valueL = Convert.ToUInt16((int)val & 0xffff); int valueH = Convert.ToUInt16((int)(val >> 16 & 0xffff)); int i = 0; for (; i < Device.Length; i++) { if (Device.ToCharArray()[i] >= 0x30 && Device.ToCharArray()[i] <= 0x39) { break; } } string ext = Device.Substring(0, i); int currentIndex = Convert.ToInt32(Device.Substring(i, Device.Length - i)); int nextIndex = currentIndex + 1; string DeviceH = ext + nextIndex.ToString(); string DeviceL = ext + currentIndex.ToString(); SLMPResult sta = SetDevice(DeviceH, valueH); if (sta.Status == SLMPStatus.SUCCESSFULLY) { sta = SetDevice(DeviceL, valueL); if (sta.Status == SLMPStatus.SUCCESSFULLY) { return(0); } else { return(-1); } } else { return(-1); } }
public SLMPResult GetDevice(string device) { SLMPResult slmpResult = new SLMPResult(); slmpResult.Status = SLMPStatus.FAIL; slmpResult.Value = 0; string acommand = string.Empty; string ccommand = string.Empty; string bcommand = string.Empty; if (_Listsp.Contains(device.Substring(0, 1).ToUpper())) { acommand = _SubHeader + _Network + _Station + _Moduleio + _Multidrop; ccommand = "D000" + _Network + _Station + _Moduleio + _Multidrop; int length = 24; if ((device.Substring(0, 1).ToUpper() == "D") || (device.Substring(0, 1).ToUpper() == "W")) { bcommand = acommand + length.ToString("X4") + _reserved + _read + _word + device.Substring(0, 1).ToUpper() + (char)0x2A + Convert.ToInt32(device.Substring(1).ToUpper()).ToString("D6") + "0001"; } else if ((device.Substring(0, 2).ToUpper() == "SD")) { bcommand = acommand + length.ToString("X4") + _reserved + _read + _word + device.Substring(0, 2).ToUpper() + Convert.ToInt32(device.Substring(2).ToUpper()).ToString("D6") + "0001"; } else { bcommand = acommand + length.ToString("X4") + _reserved + _read + _bit + device.Substring(0, 1).ToUpper() + (char)0x2A + Convert.ToInt32(device.Substring(1).ToUpper()).ToString("D6") + "0001"; } try { int i = 0; string result; do { result = SendCommand(bcommand); i++; } while ((result == "-1") && (i < 3)); if (result == "-1") { slmpResult.Value = 0; slmpResult.Status = SLMPStatus.TIME_OUT; } if (Convert.ToInt32(result.Substring(ccommand.Length + 4, 4), 16) == 0) { slmpResult.Value = Convert.ToInt32(result.Substring(ccommand.Length + 8), 16); slmpResult.Status = SLMPStatus.SUCCESSFULLY; } } catch (Exception ex) { mLog.Error(ex.Message); slmpResult.Value = 0; slmpResult.Status = SLMPStatus.FAIL; } } return(slmpResult); }
public SLMPResult SetDevice(string device, int value) { SLMPResult slmpResult = new SLMPResult(); slmpResult.Status = SLMPStatus.FAIL; slmpResult.Value = 0; string acommand = string.Empty; string ccommand = string.Empty; string bcommand = string.Empty; if (_Listsp.Contains(device.Substring(0, 1).ToUpper())) { acommand = _SubHeader + _Network + _Station + _Moduleio + _Multidrop; ccommand = "D000" + _Network + _Station + _Moduleio + _Multidrop; int length = 24; if ((device.Substring(0, 1).ToUpper() == "D") || (device.Substring(0, 1).ToUpper() == "W")) { if ((value < 655535) && (value >= 0)) { length += 4; bcommand = acommand + length.ToString("X4") + _reserved + _write + _word + device.Substring(0, 1).ToUpper() + (char)0x2A + Convert.ToInt32(device.Substring(1).ToUpper()).ToString("D6") + "0001" + value.ToString("X4"); } else { return(slmpResult); } } else if (device.Substring(0, 2).ToUpper() == "SD") { length += 4; bcommand = acommand + length.ToString("X4") + _reserved + _write + _word + device.Substring(0, 2).ToUpper() + Convert.ToInt32(device.Substring(1).ToUpper()).ToString("D6") + "0001" + value.ToString("X4"); } else { if ((value == 1) || (value == 0)) { length += 1; bcommand = acommand + length.ToString("X4") + _reserved + _write + _bit + device.Substring(0, 1).ToUpper() + (char)0x2A + Convert.ToInt32(device.Substring(1).ToUpper()).ToString("D6") + "0001" + value.ToString("X1"); } else { return(slmpResult); } } try { string result; result = SendCommand(bcommand); if (result == "-1") { return(slmpResult); } if (Convert.ToInt32(result.Substring(ccommand.Length + 4)) == 0) { slmpResult.Status = SLMPStatus.SUCCESSFULLY; slmpResult.Value = 0; } else { return(slmpResult); } } catch (Exception ex) { mLog.Error(ex.Message); return(slmpResult); } } return(slmpResult); }