コード例 #1
0
 private void test3()
 {
     // These are the underlying operations that ignore validation of success
     short  d100_short  = melsecSerial.ReadInt16("D100").Content;
     ushort d100_ushort = melsecSerial.ReadUInt16("D100").Content;
     int    d100_int    = melsecSerial.ReadInt32("D100").Content;
     uint   d100_uint   = melsecSerial.ReadUInt32("D100").Content;
     long   d100_long   = melsecSerial.ReadInt64("D100").Content;
     ulong  d100_ulong  = melsecSerial.ReadUInt64("D100").Content;
     float  d100_float  = melsecSerial.ReadFloat("D100").Content;
     double d100_double = melsecSerial.ReadDouble("D100").Content;
     // need to specify the text length
     string d100_string = melsecSerial.ReadString("D100", 10).Content;
 }
コード例 #2
0
        public void ReadExample( )
        {
            #region ReadExample1


            MelsecFxSerial melsecFx = new MelsecFxSerial( );
            melsecFx.SerialPortInni(sp =>
            {
                sp.PortName = "COM1";
                sp.BaudRate = 9600;
                sp.DataBits = 7;
                sp.StopBits = System.IO.Ports.StopBits.One;
                sp.Parity   = System.IO.Ports.Parity.Even;
            });
            melsecFx.Open( );

            // 此处以D寄存器作为示例
            short  short_D1000  = melsecFx.ReadInt16("D100").Content;         // 读取D1000的short值
            ushort ushort_D1000 = melsecFx.ReadUInt16("D100").Content;        // 读取D1000的ushort值
            int    int_D1000    = melsecFx.ReadInt32("D100").Content;         // 读取D1000-D1001组成的int数据
            uint   uint_D1000   = melsecFx.ReadUInt32("D100").Content;        // 读取D1000-D1001组成的uint数据
            float  float_D1000  = melsecFx.ReadFloat("D100").Content;         // 读取D1000-D1001组成的float数据
            long   long_D1000   = melsecFx.ReadInt64("D100").Content;         // 读取D1000-D1003组成的long数据
            ulong  ulong_D1000  = melsecFx.ReadUInt64("D100").Content;        // 读取D1000-D1003组成的long数据
            double double_D1000 = melsecFx.ReadDouble("D100").Content;        // 读取D1000-D1003组成的double数据
            string str_D1000    = melsecFx.ReadString("D100", 10).Content;    // 读取D1000-D1009组成的条码数据

            // 读取数组
            short[]  short_D1000_array  = melsecFx.ReadInt16("D100", 10).Content;         // 读取D1000的short值
            ushort[] ushort_D1000_array = melsecFx.ReadUInt16("D100", 10).Content;        // 读取D1000的ushort值
            int[]    int_D1000_array    = melsecFx.ReadInt32("D100", 10).Content;         // 读取D1000-D1001组成的int数据
            uint[]   uint_D1000_array   = melsecFx.ReadUInt32("D100", 10).Content;        // 读取D1000-D1001组成的uint数据
            float[]  float_D1000_array  = melsecFx.ReadFloat("D100", 10).Content;         // 读取D1000-D1001组成的float数据
            long[]   long_D1000_array   = melsecFx.ReadInt64("D100", 10).Content;         // 读取D1000-D1003组成的long数据
            ulong[]  ulong_D1000_array  = melsecFx.ReadUInt64("D100", 10).Content;        // 读取D1000-D1003组成的long数据
            double[] double_D1000_array = melsecFx.ReadDouble("D100", 10).Content;        // 读取D1000-D1003组成的double数据

            #endregion
        }
コード例 #3
0
 private void button_read_string_Click(object sender, EventArgs e)
 {
     // 读取字符串
     readResultRender(melsecSerial.ReadString(textBox3.Text, ushort.Parse(textBox5.Text)), textBox3.Text, textBox4);
 }
コード例 #4
0
        public override object ReadTag(Tag tag)
        {
            if (tag.AccessType == TagAccessType.Read || tag.AccessType == TagAccessType.ReadWrite)
            {
                try
                {
                    if (tag.TagType == "bool")
                    {
                        var res = PLC.ReadBool(tag.Address);
                        if (res.IsSuccess)
                        {
                            tag.TagValue = res.Content;
                            tag.Quality  = Quality.Good;
                        }
                        else
                        {
                            tag.Quality = Quality.Bad;
                        }
                    }
                    else if (tag.TagType == "string")
                    {
                        if (tag.Address.Contains("."))
                        {
                            try
                            {
                                string address = tag.Address.Split('.')[0];
                                ushort len     = Convert.ToUInt16(tag.Address.Split('.')[1]);
                                var    res     = PLC.ReadString(tag.Address.Split('.')[0], len);
                                if (res.IsSuccess)
                                {
                                    tag.TagValue = res.Content.Replace("\0", "");
                                    tag.Quality  = Quality.Good;
                                }
                                else
                                {
                                    tag.Quality = Quality.Bad;
                                }
                            }
                            catch (Exception)
                            {
                                LOG.Error($"Tag Address Error {tag.Address}");
                            }
                        }
                        else
                        {
                            LOG.Error($"Tag Address Error {tag.Address}");
                        }
                    }
                    else
                    {
                        ushort len = ConvertUtils.GetLength(tag);

                        var res = PLC.Read(tag.Address, len);
                        ConvertUtils.DecodeTagValue(tag, res);
                    }
                    return(tag.TagValue);
                }
                catch (Exception ex)
                {
                    LOG.Error($"Datasource[{SourceName}] read error. Tag[{tag.TagName}] Address[{tag.Address}] Message[{ex.Message}]");
                    tag.TagValue = null;
                    tag.Quality  = Quality.Bad;
                    return(tag.TagValue);
                }
            }
            else
            {
                return(null);
            }
        }