Example #1
0
        private void btnReadF_Click(object sender, EventArgs e)
        {
            txtValueF.Text = "";
            float  rd;
            string address = txtAddress.Text.Trim();
            short  re      = ENT.ReadReal(PlcMemory.DM, short.Parse(address), out rd);

            if (re != 0)
            {
                //写入数据出错
                txtValueF.Text = "数据读取出错!";
            }
            else
            {
                txtValueF.Text = rd.ToString();
            }
        }
Example #2
0
        public bool ReadSingleElement(PlcScanItems item, ref object value)
        {
            PlcMemory memorytype      = item.AddressType;
            string    bitstartaddress = string.Empty;
            short     startaddress    = 0;

            if (item.DataType == DataType.BIT)
            {
                bitstartaddress = item.Address;
            }
            else
            {
                startaddress = short.Parse(item.Address);
            }
            lock (readLock)
            {
                switch (item.DataType)
                {
                case DataType.BIT:
                    short shortvalue = 0;
                    if (0 != omronethernetplc.GetBitState(memorytype, bitstartaddress, out shortvalue))
                    {
                        bConnectOmronPLC = false;
                        return(false);
                    }
                    value = shortvalue == 1 ? true : false;
                    break;

                case DataType.INT16:
                    Int16 int16value = 0;
                    if (0 != omronethernetplc.ReadInt16(memorytype, startaddress, out int16value))
                    {
                        bConnectOmronPLC = false;
                        return(false);
                    }
                    value = int16value;
                    break;

                case DataType.INT32:
                    Int32 int32value = 0;
                    if (0 != omronethernetplc.ReadInt32(memorytype, startaddress, out int32value))
                    {
                        bConnectOmronPLC = false;
                        return(false);
                    }
                    value = int32value;
                    break;

                case DataType.REAL:
                    float floatvalue = 0.0f;
                    if (0 != omronethernetplc.ReadReal(memorytype, startaddress, out floatvalue))
                    {
                        bConnectOmronPLC = false;
                        return(false);
                    }
                    value = floatvalue;
                    break;

                case DataType.UINT16:
                    UInt16 uint16value = 0;
                    if (0 != omronethernetplc.ReadUInt16(memorytype, startaddress, out uint16value))
                    {
                        bConnectOmronPLC = false;
                        return(false);
                    }
                    value = uint16value;
                    break;

                case DataType.UINT32:
                    UInt32 uint32value = 0;
                    if (0 != omronethernetplc.ReadUint32(memorytype, startaddress, out uint32value))
                    {
                        bConnectOmronPLC = false;
                        return(false);
                    }
                    value = uint32value;
                    break;
                }
                return(true);
            }
        }