示例#1
0
        public static Communication.PeripheralStatus CallScaleFunction(CallScaleFunctionClickEvent.ScallFunctionType type, IPort port, ref DisplayedWeightStatus weightStatus, ref string weight)
        {
            Communication.PeripheralStatus result = Communication.PeripheralStatus.Invalid;

            switch (type)
            {
            default:
            case CallScaleFunctionClickEvent.ScallFunctionType.CheckStatus:
                result = GetScaleStatus(port);
                break;

            case CallScaleFunctionClickEvent.ScallFunctionType.DisplayedWeight:
                result = GetScaleDisplayedWeight(port, ref weightStatus, ref weight);
                break;

            case CallScaleFunctionClickEvent.ScallFunctionType.ZeroClear:
                result = SendZeroClearCommands(port);
                break;

            case CallScaleFunctionClickEvent.ScallFunctionType.UnitChange:
                result = SendUnitChangeCommands(port);
                break;
            }

            return(result);
        }
示例#2
0
        public static Communication.PeripheralStatus CallScaleFunctionWithProgressBar(CallScaleFunctionClickEvent.ScallFunctionType type, ref DisplayedWeightStatus weightStatus, ref string weight)
        {
            Communication.PeripheralStatus result = Communication.PeripheralStatus.Invalid;

            DisplayedWeightStatus tempWeightStatus = DisplayedWeightStatus.Invalid;
            string tempWeight = "";

            ProgressBarWindow progressBarWindow = new ProgressBarWindow("Communicating...", () =>
            {
                IPort port = null;

                try
                {
                    string portName     = SharedInformationManager.GetSelectedPortName();
                    string portSettings = SharedInformationManager.GetSelectedPortStrrings();

                    port = Factory.I.GetPort(portName, portSettings, 30000);

                    result = CallScaleFunction(type, port, ref tempWeightStatus, ref tempWeight);
                }
                catch (PortException)
                {
                }
                finally
                {
                    if (port != null)
                    {
                        Factory.I.ReleasePort(port);
                    }
                }
            });

            progressBarWindow.ShowDialog();

            weightStatus = tempWeightStatus;
            weight       = tempWeight;

            return(result);
        }