Пример #1
0
        //查看网络配置参数
        public Status_enum GetCommCfg(byte ReaderID, ref CommCfg cfg)
        {
            byte[]  temp    = new byte[20];
            Package package = new Package(CmdEnum.CMD_GET_TCP_CFG, ReaderID);

            if (SendPackage(package))
            {
                //接收
                Status_enum status = WaitResp(package.CMD, ref temp, ref tempbyte);

                if (status == Status_enum.SUCCESS)
                {
                    if (cfg == null)
                    {
                        cfg = new CommCfg();
                    }
                    cfg.ConvBytesToUserCfg(temp);
                }
                else
                {
                    status = Status_enum.FAILURE;
                }

                return(status);
            }
            else
            {
                return(Status_enum.SERIAL_CLOSED);
            }
        }
Пример #2
0
        public static byte[] ConvUserCfgToBytes(CommCfg cfg)
        {
            try
            {
                if (!ValidCfgPara(cfg))
                {
                    return(null);
                }
                byte[] data = new byte[20];

                byte[] data_temp = tool.IpStringToByte(cfg.IPAddr);
                Array.Copy(data_temp, 0, data, 0, 4);

                data_temp = tool.IpStringToByte(cfg.Mask);
                Array.Copy(data_temp, 0, data, 4, 4);

                data_temp = tool.IpStringToByte(cfg.GateWay);
                Array.Copy(data_temp, 0, data, 8, 4);

                Array.Copy(cfg.MAC, 0, data, 12, 6);

                return(data);
            }
            catch { return(null); }
        }
Пример #3
0
        public static bool ValidCfgPara(CommCfg cfg)
        {
            try
            {
                System.Net.IPAddress.Parse(cfg.IPAddr);
                System.Net.IPAddress.Parse(cfg.Mask);
                System.Net.IPAddress.Parse(cfg.GateWay);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        //设置网络配置参数
        public Status_enum SetCommCfg(byte ReaderID, CommCfg cfg)
        {
            byte[] temp      = null;
            byte[] cfg_array = CommCfg.ConvUserCfgToBytes(cfg);

            if (cfg_array == null)
            {
                return(Status_enum.PARAM_ERR);
            }

            Package package = new Package(CmdEnum.CMD_SET_TCP_CFG, ReaderID, cfg_array, 0, 12);

            if (SendPackage(package))
            {
                //接收
                return(WaitResp(package.CMD, ref temp, ref tempbyte, SET_CFG_TIMEOUT));
            }
            else
            {
                return(Status_enum.SERIAL_CLOSED);
            }
        }