基本信息
源码名称:c#利用modbus通讯实现RFID读写
源码大小:0.12M
文件格式:.rar
开发语言:C#
更新时间:2021-11-09
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
c#利用modbus rtu协议通讯实现RFID的读写

        //读取标签数据
        public bool ReadFRIDLabelData(out string value)
        {
            bool flag = false;
            value = "";        
            try
            {
                byte[] req = new byte[8];
                req[0] = 0x02;
                req[1] = 0x03;
                req[2] = 0x00;
                req[3] = 0x0A;
                req[4] = 0x00;
                req[5] = 0x04;
                ushort crc = AIDACrc.crc16(req, 6);
                req[6] = (byte)(crc >> 8);
                req[7] = (byte)(crc & 0x00FF);            
                if (this.Com.IsOpen)
                {
                    flag = this.Write(req, req.Length);
                }            
                if (flag)
                {
                    int timeout = 500;
                    byte repdatacount = 0x08;
                    byte[] rep_head = new byte[13];                                
                    flag = this.Read(timeout, rep_head , rep_head .Length);
                    if (flag)
                    {
                        if (repdatacount == rep_head[2])
                        {
                                byte[] rep_value = new byte[8];
                                for (var i = 0; i < rep_value.Length; i )
                                {
                                    rep_value[i] = rep_head[i 3];
                                    value = rep_value[i].ToString("X2");
                                }                                         
       
                        }
                    }
                  
                }
            }
            catch 
            {
                throw;
            }      
            return flag;
        }
        public bool ReadFRIDLabelDataTest(out string value, byte addr)
        {
            bool flag = false;
            value = "";
            try
            {
                byte[] req = new byte[8];
                req[0] = 0x02;
                req[1] = 0x03;
                req[2] = 0x00;
                req[3] = addr;
                req[4] = 0x00;
                req[5] = 0x04;
                ushort crc = AIDACrc.crc16(req, 6);
                req[6] = (byte)(crc >> 8);
                req[7] = (byte)(crc & 0x00FF);
                if (this.Com.IsOpen)
                {
                    flag = this.Write(req, req.Length);
                }
                if (flag)
                {
                    int timeout = 500;
                    byte repdatacount = 0x08;
                    byte[] rep_head = new byte[13];
                    flag = this.Read(timeout, rep_head, rep_head.Length);
                    if (flag)
                    {
                        if (repdatacount == rep_head[2])
                        {
                            byte[] rep_value = new byte[8];
                            for (var i = 0; i < rep_value.Length; i )
                            {
                                rep_value[i] = rep_head[i 3];
                                value = rep_value[i].ToString("X2");
                            }
           
                        }
                    }

                }
            }
            catch
            {
                throw;
            }
            return flag;
        }