Exemplo n.º 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()}设备: 成功建立连接。");
            }
        }
Exemplo n.º 2
0
        public int TestSocketConnect(string ipString, string portString)
        {
            DeviceSetting setting = new DeviceSetting()
            {
                DeviceIpAddress = ipString, DevicePort = portString
            };

            if (!setting.IsSettingValid())
            {
                return(-2);
            }
            else
            {
                RFID_StandardProtocol Reader = new RFID_StandardProtocol();
                Socket temp = null;

                int status = Reader.Socket_ConnectSocket(ref temp, ipString, portString.ToDefaultInt32());
                if (status == RFID_StandardProtocol.SUCCESS)
                {
                    temp.Close();
                    temp.Dispose();
                    return(0);       //连接成功(connect success)
                }
                else
                {
                    temp.Close();
                    temp.Dispose();
                    return(-1);      //连接失败(connect fail)
                }
            }
        }