private void button_read_short_Click(object sender, EventArgs e) { // 读取short变量 if (textBox14.Text == "1") { DemoUtils.ReadResultRender(allenBradleyNet.ReadInt16(textBox3.Text), textBox3.Text, textBox4); } else { DemoUtils.ReadResultRender(allenBradleyNet.ReadInt16(textBox3.Text, ushort.Parse(textBox14.Text)), textBox3.Text, textBox4); } }
public static object ABRead(AllenBradleyNet plc, string address, string dataType, ushort dataLength) { lock (_lock) { object value = new object(); switch (dataType) { case "int": value = plc.ReadInt32(address).Content; break; case "bool": value = plc.ReadBool(address).Content; break; case "float": value = plc.ReadFloat(address).Content; break; case "double": value = plc.ReadDouble(address).Content; break; case "string": value = plc.ReadString(address, dataLength).Content; break; case "short": value = plc.ReadInt16(address).Content; break; case "long": value = plc.ReadInt64(address).Content; break; default: break; } return(value); } }
private void button_read_short_Click(object sender, EventArgs e) { // 读取short变量 readResultRender(allenBradleyNet.ReadInt16(textBox3.Text), textBox3.Text, textBox4); }
private void ShowDataRoots( ) { if (rootTags != null) { foreach (var item in rootTags) { // 不是结构体及数组的情况则给予显示 if (!item.IsStruct) { if (item.ArrayDimension == 0) { if (item.SymbolType == AllenBradleyHelper.CIP_Type_Byte) { OperateResult <byte> read = allenBradleyNet.ReadByte(item.Name); if (read.IsSuccess) { item.Tag = (sbyte)read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Word) { OperateResult <short> read = allenBradleyNet.ReadInt16(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_DWord) { OperateResult <int> read = allenBradleyNet.ReadInt32(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_LInt) { OperateResult <long> read = allenBradleyNet.ReadInt64(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_USInt) { OperateResult <byte> read = allenBradleyNet.ReadByte(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_UInt) { OperateResult <ushort> read = allenBradleyNet.ReadUInt16(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_UDint) { OperateResult <uint> read = allenBradleyNet.ReadUInt32(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_ULint) { OperateResult <ulong> read = allenBradleyNet.ReadUInt64(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Bool) { OperateResult <bool> read = allenBradleyNet.ReadBool(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Real) { OperateResult <float> read = allenBradleyNet.ReadFloat(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Double) { OperateResult <double> read = allenBradleyNet.ReadDouble(item.Name); if (read.IsSuccess) { item.Tag = read.Content; } } } else if (item.ArrayDimension == 1) { if (item.SymbolType == AllenBradleyHelper.CIP_Type_Byte) { OperateResult <byte[]> read = allenBradleyNet.Read(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { sbyte[] data = new sbyte[read.Content.Length]; for (int i = 0; i < data.Length; i++) { data[i] = (sbyte)read.Content[i]; } item.Tag = data.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Word) { OperateResult <short[]> read = allenBradleyNet.ReadInt16(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_DWord) { OperateResult <int[]> read = allenBradleyNet.ReadInt32(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_LInt) { OperateResult <long[]> read = allenBradleyNet.ReadInt64(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_USInt) { OperateResult <byte[]> read = allenBradleyNet.Read(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_UInt) { OperateResult <ushort[]> read = allenBradleyNet.ReadUInt16(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_UDint) { OperateResult <uint[]> read = allenBradleyNet.ReadUInt32(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_ULint) { OperateResult <ulong[]> read = allenBradleyNet.ReadUInt64(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Real) { OperateResult <float[]> read = allenBradleyNet.ReadFloat(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_Double) { OperateResult <double[]> read = allenBradleyNet.ReadDouble(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = read.Content.ToArrayString( ); } } else if (item.SymbolType == AllenBradleyHelper.CIP_Type_D3) { OperateResult <int[]> read = allenBradleyNet.ReadInt32(item.Name, (ushort)item.ArrayLength[0]); if (read.IsSuccess) { item.Tag = SoftBasic.BoolArrayToString(allenBradleyNet.ByteTransform.TransByte(read.Content).ToBoolArray( )); } } } } } } }