Exemple #1
0
        private void button25_Click(object sender, EventArgs e)
        {
            try
            {
                //    OperateResult write = allenBradleyNet.Write( "Array", new short[] { 101, 102, 103, 104, 105, 106 } );

                // OperateResult<short[]> readResult = allenBradleyNet.ReadInt16( "Array", 300 );

                OperateResult <byte[]> read = null;
                if (!textBox6.Text.Contains(";"))
                {
                    //MessageBox.Show( HslCommunication.BasicFramework.SoftBasic.ByteToHexString( allenBradleyNet.BuildReadCommand( new string[] { textBox6.Text }, new int[] { int.Parse(textBox9.Text) } ).Content , ' ') );
                    read = allenBradleyNet.Read(textBox6.Text, ushort.Parse(textBox9.Text));
                }
                else
                {
                    //MessageBox.Show( HslCommunication.BasicFramework.SoftBasic.ByteToHexString( allenBradleyNet.BuildReadCommand( textBox6.Text.Split( ';' ) ).Content, ' ' ) );
                    read = allenBradleyNet.Read(textBox6.Text.Split(';'));
                }

                if (read.IsSuccess)
                {
                    textBox10.Text = "结果:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content);
                }
                else
                {
                    MessageBox.Show("读取失败:" + read.ToMessageShowString( ));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("读取失败:" + ex.Message);
            }
        }
        private void button25_Click(object sender, EventArgs e)
        {
            try
            {
                OperateResult <byte[]> read = null;
                if (!textBox6.Text.Contains(";"))
                {
                    MessageBox.Show(HslCommunication.BasicFramework.SoftBasic.ByteToHexString(allenBradleyNet.BuildReadCommand(new string[] { textBox6.Text }).Content, ' '));
                    read = allenBradleyNet.Read(textBox6.Text, 0);
                }
                else
                {
                    MessageBox.Show(HslCommunication.BasicFramework.SoftBasic.ByteToHexString(allenBradleyNet.BuildReadCommand(textBox6.Text.Split(';')).Content, ' '));
                    read = allenBradleyNet.Read(textBox6.Text.Split(';'));
                }

                if (read.IsSuccess)
                {
                    textBox10.Text = "结果:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content);
                }
                else
                {
                    MessageBox.Show("读取失败:" + read.ToMessageShowString( ));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("读取失败:" + ex.Message);
            }
        }
Exemple #3
0
        private void button_read_bool_Click(object sender, EventArgs e)
        {
            // 读取bool变量
            // readResultRender( allenBradleyNet.ReadBool( textBox3.Text ), textBox3.Text, textBox4 );
            OperateResult <byte[]> read = allenBradleyNet.Read("Start_out", 0);

            if (!read.IsSuccess)
            {
                MessageBox.Show("失败");
            }
            else
            {
                MessageBox.Show(HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content, ' '));
            }
        }
 private void button25_Click(object sender, EventArgs e)
 {
     try
     {
         OperateResult <byte[]> read = allenBradleyNet.Read(textBox6.Text, ushort.Parse(textBox9.Text));
         if (read.IsSuccess)
         {
             textBox10.Text = "结果:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content);
         }
         else
         {
             MessageBox.Show("读取失败:" + read.ToMessageShowString( ));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("读取失败:" + ex.Message);
     }
 }
 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( ));
                         }
                     }
                 }
             }
         }
     }
 }