public int WriteShort(DeviceAddress deviceAddress, short datas) { lock (_async) { _handler = _handler++ >= 65535 ? 0 : _handler; var source = createWriteHeader(deviceAddress, _handler, UnsafeNetConvert.ShortToBytes(datas, ByteOrder.BigEndian)); return(writedata(deviceAddress, source)); } }
/// <summary> /// 16位无符号整形点绑定16位整形数据 /// </summary> /// <param name="source">16位整形源数据</param> /// <param name="sourceindex">源数据点索引</param> /// <param name="target">目标数据,点长度为1的虚拟点</param> /// <param name="bindingWay">绑定方式,默认为单方向</param> public static bool UshortBinding(IPoint <short> source, int sourceindex, IPoint <ushort> target, BindingWay bindingWay = BindingWay.OneWay) { if (sourceindex >= source.Length) { return(false); } switch (bindingWay) { case BindingWay.OneWay: source.PropertyChanged += (s, p) => { if (int.Parse(p.PropertyName) == sourceindex) { byte[] temp1 = UnsafeNetConvert.ShortToBytes(source[(byte)sourceindex], ByteOrder.None); ushort temp2 = UnsafeNetConvert.BytesToUShort(temp1, 0, ByteOrder.None); target.ValueUpdate(temp2, 0); } }; return(true); case BindingWay.TwoWay: source.PropertyChanged += (s, p) => { if (int.Parse(p.PropertyName) == sourceindex) { byte[] temp1 = UnsafeNetConvert.ShortToBytes(source[(byte)sourceindex], ByteOrder.None); ushort temp2 = UnsafeNetConvert.BytesToUShort(temp1, 0, ByteOrder.None); target.ValueUpdate(temp2, 0); } }; target.PropertyChanged += (s, p) => { var temp1 = UnsafeNetConvert.UShortToBytes(target[0], ByteOrder.None); var temp2 = UnsafeNetConvert.BytesToShort(temp1, 0, ByteOrder.None); source.ValueUpdate(temp2, sourceindex); }; return(true); case BindingWay.ReverseWay: target.PropertyChanged += (s, p) => { var temp1 = UnsafeNetConvert.UShortToBytes(target[0], ByteOrder.None); var temp2 = UnsafeNetConvert.BytesToShort(temp1, 0, ByteOrder.None); source.ValueUpdate(temp2, sourceindex); }; return(true); default: return(false); } }
public int WriteShort(DeviceAddress deviceAddress, short datas) { ushort startAddress; if (Function.EnableWriteRegister(deviceAddress.Address, out startAddress)) { byte[] valueBytes = UnsafeNetConvert.ShortToBytes(datas, deviceAddress.ByteOrder); byte[] sendBytes = getWriteSigRegisterHeader((byte)deviceAddress.SalveId, startAddress, valueBytes); return(writeBytes(sendBytes)); } else { return(-1); } }