private void button24_Click(object sender, EventArgs e)
 {
     // bool写入
     DemoUtils.WriteResultRender(() => keyence_net.Write(textBox8.Text, new bool[] { bool.Parse(textBox7.Text) }), textBox8.Text);
 }
Ejemplo n.º 2
0
        //PLC写入
        private bool WriteSieTcpValue(Config.PlcTypeItem plctype, Config.PlcDataItem plcdata, KeyenceMcNet plc, object value)
        {
            HslCommunication.OperateResult rlt = new HslCommunication.OperateResult();
            rlt.IsSuccess = false;
            try
            {
                //string[] strAdrss = plcdata.Address.Split('.');
                //string Address = strAdrss[0] + "." + Regex.Replace(strAdrss[1], @"^[A-Za-z]+", string.Empty);

                if (plctype == null || !plctype.IsConnected || plcdata == null || plc == null)
                {
                    return(rlt.IsSuccess);
                }

                switch (plcdata.DataType)
                {
                case Common.DataTypes.Bool:    //Bool
                    rlt = plc.Write(plcdata.Address, Convert.ToBoolean(value));
                    break;

                case Common.DataTypes.Byte:    //Byte
                    rlt = plc.Write(plcdata.Address, Convert.ToChar(value));
                    break;

                case Common.DataTypes.Short:
                    rlt = plc.Write(plcdata.Address, Convert.ToInt16(value));
                    break;

                case Common.DataTypes.Ushort:
                    rlt = plc.Write(plcdata.Address, Convert.ToUInt16(value));
                    break;

                case Common.DataTypes.Int:
                    rlt = plc.Write(plcdata.Address, Convert.ToInt32(value));
                    break;

                case Common.DataTypes.UInt:
                    rlt = plc.Write(plcdata.Address, Convert.ToUInt32(value));
                    break;

                case Common.DataTypes.Long:
                    long lValue = 0;
                    if (long.TryParse(value.ToString(), out lValue))
                    {
                        long lValueNew = BpLong.SwapInt64(lValue);
                        rlt = plc.Write(plcdata.Address, lValueNew);
                    }
                    //plc.Write(plcdata.Address, Convert.ToInt64(value));
                    break;

                case Common.DataTypes.ULong:
                    rlt = plc.Write(plcdata.Address, Convert.ToUInt64(value));
                    break;

                case Common.DataTypes.Float:
                    rlt = plc.Write(plcdata.Address, float.Parse(value.ToString()));
                    break;

                case Common.DataTypes.Double:
                    rlt = plc.Write(plcdata.Address, Convert.ToDouble(value));
                    break;

                case Common.DataTypes.String:
                    if (value != null)
                    {
                        byte[] btValue = System.Text.Encoding.ASCII.GetBytes(value.ToString());
                        byte[] arrData = new byte[btValue.Length + 2];
                        arrData[0] = 50;
                        arrData[1] = (byte)btValue.Length;
                        btValue.CopyTo(arrData, 2);
                        rlt = plc.Write(plcdata.Address, arrData);
                    }
                    break;

                default: break;
                }
                return(rlt.IsSuccess);
            }
            catch
            {
                //MessageBox.Show(ex.Message);
                return(rlt.IsSuccess);
            }
        }
Ejemplo n.º 3
0
        private void test2( )
        {
            // the next we want write data
            bool[]        values = new bool[] { true, false, true, true, false, true, false, true, true, false };
            OperateResult read   = keyence_net.Write("M100", values);

            if (read.IsSuccess)
            {
                // success
            }
            else
            {
                // failed
            }
        }
Ejemplo n.º 4
0
 private void button24_Click(object sender, EventArgs e)
 {
     // bool写入
     try
     {
         writeResultRender(keyence_net.Write(textBox8.Text, new bool[] { bool.Parse(textBox7.Text) }), textBox8.Text);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }