示例#1
0
 public TcpServer(PLCDevice pLCDevice, ILogWrite logWrite)
 {
     _log          = logWrite;
     _device       = pLCDevice;
     serverAddress = IPAddress.Parse(_device.Ip);
     serverPort    = _device.Port;
 }
示例#2
0
 /// <summary>
 /// 获取标签的属性
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="databaseTag"></param>
 /// <param name="tag"></param>
 private static void GetDbTagInfoAndAdd <T>(PLCDevice plcDevice, DatabaseTag databaseTag, Tag <T> tag)
 {
     // tag.DataType = (TagDataType)databaseTag.DataType;//类型自动判断了
     tag.CycleRead   = databaseTag.CycleRead;
     tag.Length      = databaseTag.Length;
     tag.TagName     = databaseTag.TagName;
     tag.TagAddr     = databaseTag.TagAddr;
     tag.GroupId     = databaseTag.GroupId;
     tag.description = databaseTag.description;
     plcDevice.AddToGroup <T>(tag);
 }
示例#3
0
        /// <summary>
        /// 加载标签组和标签
        /// </summary>
        public static void LoadTags()
        {
            var list = _plcGroupService.QueryableToList(x => x.Active == true);//查找出激活的PLC

            foreach (var plcgroupItem in list)
            {
                PLCDevice plcDevice = new PLCDevice();
                plcDevice.Name        = plcgroupItem.Name;
                plcDevice.Ip          = plcgroupItem.Ip;
                plcDevice.Type        = (PLCType)plcgroupItem.DeviceType;
                plcDevice.Port        = plcgroupItem.Port;
                plcDevice.CycleTime   = plcgroupItem.CycleTime;
                plcDevice.HeartBit    = plcgroupItem.HeartBit;
                plcDevice.Description = plcgroupItem.Description;

                var dbTags = _tagService.QueryableToList(x => x.GroupId == plcgroupItem.id);

                foreach (var dbTag in dbTags)
                {
                    switch (dbTag.DataType)
                    {
                    case (int)TagDataType.Bool:
                        Tag <bool> boolTag = new Tag <bool>();
                        GetDbTagInfoAndAdd <bool>(plcDevice, dbTag, boolTag);
                        break;

                    case (int)TagDataType.Short:
                        Tag <short> shortTag = new Tag <short>();
                        GetDbTagInfoAndAdd <short>(plcDevice, dbTag, shortTag);
                        break;

                    case (int)TagDataType.Int:
                        Tag <int> intTag = new Tag <int>();
                        GetDbTagInfoAndAdd <int>(plcDevice, dbTag, intTag);
                        break;

                    case (int)TagDataType.Float:
                        Tag <float> floatTag = new Tag <float>();
                        GetDbTagInfoAndAdd <float>(plcDevice, dbTag, floatTag);
                        break;

                    case (int)TagDataType.String:
                        Tag <string> stringTag = new Tag <string>();
                        GetDbTagInfoAndAdd <string>(plcDevice, dbTag, stringTag);
                        break;
                    }
                }
                PLCScanTask scanTask = new PLCScanTask(plcDevice, logWrite);
                scanTask.StartTask();
                TagList.PLCGroups.Add(scanTask);
            }
        }
        public void InitConfig(string type)
        {
            // 初始化配置文件信息
            foreach (string workType in InitConfigInfo.WorkGroups.Keys)
            {
                if (workType == type)
                {
                    WorkGroupElement workGroup = InitConfigInfo.WorkGroups[workType];
                    for (int i = 0; i < workGroup.Devices.Count; i++)
                    {
                        DeviceElement deviceElement = workGroup.Devices[i];
                        dictionaryDevices.Add(deviceElement.DeviceNumber, deviceElement);
                    }
                }
            }

            this.OPCServerIP   = ConfigurationManager.AppSettings["OPCServerIP"];
            this.OPCServerPort = ConfigurationManager.AppSettings["OPCServerPort"];
            this.localHostIP   = ConfigurationManager.AppSettings["LocalHostIP"];
            this.localHostPort = ConfigurationManager.AppSettings["LocalHostPort"];
            if (InitConfigInfo.PingIpOrDomainName(OPCServerIP, localHostIP, dictionaryDevices["1"].PLCip))
            {
                this.service = DeviceService.Register(1, localHostIP, int.Parse(localHostPort), OPCServerIP, int.Parse(OPCServerPort));
                this.device  = new PLCDevice(dictionaryDevices["1"].PLCip, DeviceType.Siemens_S7_1200);

                this.Title = string.Format("{0}             本机IP:{1}  本机端口:{2}             远程IP:{3}  远程端口:{4}          PLCIP地址:{5}", "PLC监听", localHostIP, localHostPort, OPCServerIP, OPCServerPort, dictionaryDevices["1"].PLCip);



                address = new PLCAddress[dictionaryDevices.Count];
                for (int i = 0; i < dictionaryDevices.Count; i++)
                {
                    address[i] = device.Add(dictionaryDevices[(i + 1).ToString()].PLCAddress);
                }
                CommandResult res = service.ListenDevice(device);
                ReadPLCValue();
            }
            else
            {
                MessageBox.Show("网络错误,请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
示例#5
0
        public PLCScanTask(PLCDevice plcDevice, ILogWrite logWrite)
        {
            _log      = logWrite;
            PlcDevice = plcDevice;
            try
            {
                switch (plcDevice.Type)
                {
                case PLCType.Simens1200:
                case PLCType.Simens1500:
                case PLCType.Simens300:
                case PLCType.Simens200Smart:
                    plcDriverHelper = new SimensPLCHelper(plcDevice, _log);   //指定为西门子PLC连接
                    break;

                case PLCType.Omron:
                    plcDriverHelper = new OmronPLCHelper(plcDevice, _log);    //指定为欧姆龙PLC连接
                    break;

                case PLCType.Fx:
                    plcDriverHelper = new FxPLCHelper(plcDevice, _log);    //指定为三菱PLC连接
                    break;

                case PLCType.Modbus:
                    plcDriverHelper = new ModbusTcpHelper(plcDevice, _log);    //指定为Modbus连接(Robot机械手)
                    break;

                case PLCType.TcpServer:
                    plcDriverHelper = new TcpServer(plcDevice, _log);    //指定为Modbus连接(Robot机械手)
                    break;

                default:                                                    //默认西门子
                    plcDriverHelper = new SimensPLCHelper(plcDevice, _log); //指定为西门子PLC连接

                    break;
                }
            }
            catch (Exception ex)
            {
                _log.WriteLog(ex.Message);
            }
        }
示例#6
0
        private void DeviceInit()
        {
            //实例化扫码枪
            scanner = new Scanner((ScannerModel)Enum.Parse(typeof(ScannerModel), lineDevice.QRCodeReaderModel), lineDevice.QRCodeReaderIP);

            Init();

            device = Devices["StackTray"];
            //忽略异常
            device.DeviceServer.ExceptionSkip = true;

            this.lineDevice.trayArrivedAddr              = device.Listeners["trayArrivedAddr"];
            this.lineDevice.trayArrivedAddr.ValueChange += trayArrivedAddr_ValueChanged;

            this.lineDevice.requestBindDataAddr              = device.Listeners["requestBindDataAddr"];
            this.lineDevice.requestBindDataAddr.ValueChange += requestBindDataAddr_ValueChanged;

            this.lineDevice.trayCountAddr        = device.Listeners["trayCountAddr"];
            this.lineDevice.scanCodeFeedbackAddr = device.Writers["scanCodeFeedbackAddr"];
            this.lineDevice.scanErrorCodeAddr    = device.Writers["scanErrorCodeAddr"];
            this.lineDevice.bindDataResultAddr   = device.Writers["bindDataResultAddr"];
        }
示例#7
0
 public OmronPLCHelper(PLCDevice device, ILogWrite logWrite)
 {
     _device = device;
     _log    = logWrite;
 }
示例#8
0
 public ModbusTcpHelper(PLCDevice device, ILogWrite logWrite)
 {
     _device = device;
     _log    = logWrite;
 }
示例#9
0
 public SimensPLCHelper(PLCDevice device, ILogWrite logWrite)
 {
     _device = device;
     _log    = logWrite;
 }