private void button_read_uint_Click(object sender, EventArgs e) { // 读取uint变量 if (textBox14.Text == "1") { DemoUtils.ReadResultRender(allenBradleyNet.ReadUInt32(textBox3.Text), textBox3.Text, textBox4); } else { DemoUtils.ReadResultRender(allenBradleyNet.ReadUInt32(textBox3.Text, ushort.Parse(textBox14.Text)), textBox3.Text, textBox4); } }
private void button_read_uint_Click(object sender, EventArgs e) { // 读取uint变量 readResultRender(allenBradleyNet.ReadUInt32(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( )); } } } } } } }
public OperateResult <string> Read(AllenBradleyDataConfig dataConfig) { try { AllenBradleyNet allenBradleyNet = new AllenBradleyNet(); allenBradleyNet.IpAddress = IP; allenBradleyNet.Port = Port; OperateResult connect = allenBradleyNet.ConnectServer(); if (!connect.IsSuccess) { return(new OperateResult <string>("PLC连接失败")); } OperateResult <string> isRead = new OperateResult <string> { IsSuccess = false }; switch (dataConfig.DataType) { case AllenBradleyDataTypeEnum.BOOL: var bRes = allenBradleyNet.ReadBool(dataConfig.DataAdr); if (bRes.IsSuccess == true) { isRead.IsSuccess = true; isRead.Content = bRes.Content.ToString(); } break; case AllenBradleyDataTypeEnum.BYTE: var cRes = allenBradleyNet.ReadByte(dataConfig.DataAdr); if (cRes.IsSuccess == true) { isRead.IsSuccess = true; isRead.Content = cRes.Content.ToString(); } break; case AllenBradleyDataTypeEnum.SHORT: var ui16Res = allenBradleyNet.ReadUInt16(dataConfig.DataAdr); if (ui16Res.IsSuccess == true) { isRead.IsSuccess = true; isRead.Content = ui16Res.Content.ToString(); } break; case AllenBradleyDataTypeEnum.INT: var ui32Res = allenBradleyNet.ReadUInt32(dataConfig.DataAdr); if (ui32Res.IsSuccess == true) { isRead.IsSuccess = true; isRead.Content = ui32Res.Content.ToString(); } break; case AllenBradleyDataTypeEnum.LONG: var ui64Res = allenBradleyNet.ReadUInt64(dataConfig.DataAdr); if (ui64Res.IsSuccess == true) { isRead.IsSuccess = true; isRead.Content = ui64Res.Content.ToString(); } break; default: isRead.IsSuccess = false; break; } allenBradleyNet.ConnectClose(); return(isRead); } catch { return(new OperateResult <string>("AB PLC通讯发生致命错误")); } }