private void button_read_bool_Click(object sender, EventArgs e)
 {
     // 读取bool变量
     if (textBox12.Text == "1")
     {
         DemoUtils.ReadResultRender(keyence_net.ReadBool(textBox3.Text), textBox3.Text, textBox4);
     }
     else
     {
         DemoUtils.ReadResultRender(keyence_net.ReadBool(textBox3.Text, ushort.Parse(textBox12.Text)), textBox3.Text, textBox4);
     }
 }
Beispiel #2
0
        private void test1()
        {
            // 如果我们想要读取M100-M109,我们可以按照如下的代码进行操作

            // if we want read M100-M109, so we can do like this
            OperateResult <bool[]> read = keyence_net.ReadBool("M100", 10);

            if (read.IsSuccess)
            {
                bool m100 = read.Content[0];
                // and so on
                // ...
                // then
                bool m109 = read.Content[9];
            }
            else
            {
                // failed, the follow operation is output the wrong msg
                Console.WriteLine("Read failed: " + read.ToMessageShowString( ));
            }
        }
Beispiel #3
0
 private void button_read_bool_Click(object sender, EventArgs e)
 {
     // 读取bool变量
     DemoUtils.ReadResultRender(keyence_net.ReadBool(textBox3.Text), textBox3.Text, textBox4);
 }
Beispiel #4
0
        //PLC读取
        private object ReadSieTcpValue(Config.PlcTypeItem plctype, Config.PlcDataItem plcdata, KeyenceMcNet plc)
        {
            try
            {
                if (plctype == null || !plctype.IsConnected || plcdata == null || plc == null)
                {
                    return(null);
                }

                switch (plcdata.DataType)
                {
                case Common.DataTypes.Bool:    //Bool
                    plcdata.ValueNew = plc.ReadBool(plcdata.Address).Content;
                    break;

                case Common.DataTypes.Byte:    //Byte
                    plcdata.ValueNew = plc.Read(plcdata.Address, 1).Content;
                    break;

                case Common.DataTypes.Short:
                    plcdata.ValueNew = plc.ReadInt16(plcdata.Address).Content;
                    break;

                case Common.DataTypes.Ushort:
                    plcdata.ValueNew = plc.ReadUInt16(plcdata.Address).Content;
                    break;

                case Common.DataTypes.Int:
                    plcdata.ValueNew = plc.ReadInt32(plcdata.Address).Content;
                    break;

                case Common.DataTypes.UInt:
                    plcdata.ValueNew = plc.ReadUInt32(plcdata.Address).Content;
                    break;

                case Common.DataTypes.Long:
                    long lValueNew = 0;
                    if (long.TryParse(plc.ReadInt64(plcdata.Address).Content.ToString(), out lValueNew))
                    {
                        long temp = BpLong.SwapInt64(lValueNew);
                        plcdata.ValueNew = temp;
                    }
                    // plcdata.ValueNew = plc.ReadInt64(plcdata.Address).Content;
                    break;

                case Common.DataTypes.ULong:
                    plcdata.ValueNew = plc.ReadUInt64(plcdata.Address).Content;
                    break;

                case Common.DataTypes.Float:
                    plcdata.ValueNew = plc.ReadFloat(plcdata.Address).Content;
                    break;

                case Common.DataTypes.Double:
                    plcdata.ValueNew = plc.ReadDouble(plcdata.Address).Content;
                    break;

                case Common.DataTypes.String:
                    HslCommunication.OperateResult <byte[]> data = (HslCommunication.OperateResult <byte[]>)plc.Read(plcdata.Address, 50);
                    if (data != null && data.Content != null && data.Content.Length > 2)
                    {
                        List <byte> lstData = new List <byte>();
                        int         nLen    = data.Content[1];
                        for (int i = 2; i < nLen + 2; i++)
                        {
                            lstData.Add(data.Content[i]);
                        }
                        plcdata.ValueNew = System.Text.Encoding.ASCII.GetString(lstData.ToArray());
                    }
                    break;

                default:
                    break;
                }
            }
            catch
            {
                //MessageBox.Show(ex.Message);
            }

            return(plcdata.ValueNew);
        }