Example #1
0
        public void ConnectDevice4()
        {
            DeviceUsageEnum currentUsage = DeviceUsageEnum.出库;
            var             item         = SV.DeviceDictonary.FirstOrDefault(p => p.Key.Usage == currentUsage);

            DeviceSetting setting = item.Key;

            if (!setting.IsSettingValid())
            {
                SV.Logger.Info($"{currentUsage.ToString()}设备: 配置无效,无法连接。");
                return;
            }

            DeviceProxy deviceProxy = item.Value;

            deviceProxy.Connected += () => { this.OnDeviceConnected(_frmExWarehouse); };
            deviceProxy.Closing   += () => { this.OnDeviceDisconnected(_frmExWarehouse); };
            int status = deviceProxy.ConnectViaNetwork(item.Key.DeviceIpAddress, item.Key.DevicePort);

            if (status == 0)
            {
                deviceProxy.IsConnected = true;
                SV.Logger.Info($"{currentUsage.ToString()}设备: 成功建立连接。");
            }
        }