public void moveToPositionByPulse(Int32 _rotX, Int32 _detY, Int32 _rotC, Int32 _detZ, Int32 _xrayZ)
        {
//            if (!ReadyMotion) return;
            MechanicalPosition msg = new MechanicalPosition(MessageType.MECHANICAL_MOVE_MOTOR);

            msg.setFirstEnginePosition(_rotX);
            msg.setSecondEnginePosition(_detY);
            msg.setThirdEnginePosition(_rotC);
            msg.setFourthEnginePosition(_detZ);
            msg.setFifthEnginePosition(_xrayZ);

            this.mIsDoneMoving = false;
            this.mMechanicalService.processInnerMessage(msg);
        }
        private void handleResponseMessage(BaseMessage msg)
        {
            switch (msg.getMessageType())
            {
            case MessageType.MECHANICAL_REQUEST_INFO:
            {
                Logger.Info("\nRequest Info {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_MOVE_MOTOR:
            {
                Logger.Info("\nMove Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_POSITION_CHANGED:
            {
                this.mIsDoneMoving = true;
                Logger.Info("\nPosition Changed {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_HOME_MOTOR:
            {
                Logger.Info("\nHome Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_MACHINE_READY:
            {
                Logger.Info("\nMachine Ready = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_MACHINE_BUSY:
            {
                Logger.Info("\nMachine Busy = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_MACHINE_ERROR:
            {
                Logger.Info("\nMachine Error = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_ENABLE_MOTOR:
            {
                Logger.Info("\nEnable Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_DISABLE_MOTOR:
            {
                Logger.Info("\nDisable Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;
            }

            case MessageType.MECHANICAL_RT_POSITION:
                MechanicalPosition rtPosMessage = msg as MechanicalPosition;
                if (this.mReadyFlag == false)
                {
                    this.mReadyFlag = true;
                    Logger.Info("ReadMotion Change From {0} --> {1}", this.ReadyMotion, true);
                    this.ReadyMotion = true;
                    this.HomedMotion = true;
                    this.setDefaultMotorPos();
                }
                this.mReadyFlag = true;
                this.Dispatcher.Invoke((MethodInvoker) delegate
                {
                    if (this.mRotCPos != (double)rtPosMessage.getThirdEnginePosition() / PULSES_PER_DEGREE)
                    {
                        if (this.RotCPositionChanged != null)
                        {
                            this.RotCPositionChanged((double)rtPosMessage.getThirdEnginePosition() / PULSES_PER_DEGREE);
                        }
                    }

                    this.mRotXPos = (double)rtPosMessage.getFirstEnginePosition() / PULSES_PER_MILLIMETRE;
                    this.mDetYPos = (double)rtPosMessage.getSecondEnginePosition() / PULSES_PER_MILLIMETRE;
                    this.mRotCPos = (double)rtPosMessage.getThirdEnginePosition() / PULSES_PER_DEGREE;
                    this.mDetZPos = (double)rtPosMessage.getFourthEnginePosition() / PULSES_PER_MILLIMETRE;
                    this.mXRayPos = (double)rtPosMessage.getFifthEnginePosition() / PULSES_PER_MILLIMETRE;

                    this.tbRotXPos.Text  = this.mRotXPos.ToString("0.00");
                    this.tbDetYPos.Text  = this.mDetYPos.ToString("0.00");
                    this.tbRotCPos.Text  = this.mRotCPos.ToString("0.00");
                    this.tbDetZPos.Text  = this.mDetZPos.ToString("0.00");
                    this.tbXRayZPos.Text = this.mXRayPos.ToString("0.00");

                    //Logger.Info("Update Pos: {0}, {1}, {2}, {3}, {4} | {5}", this.mRotXPos, this.mDetYPos, this.mRotCPos, this.mDetZPos, this.mXRayPos, this.mReadyFlag);
                });
                break;

            case MessageType.MECHANICAL_UNKNOWN:
                //Logger.Info("Unkown Message: {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)msg.getMessageType())));
                break;

            default:
            {
                //Logger.Info("\nMotionCodec key = {0} does NOT match any key", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }
            }
        }
Beispiel #3
0
        private BaseMessage makeMessage(MessageType _key, byte[] payload)
        {
            BaseMessage message = null;

            switch (_key)
            {
            case MessageType.MECHANICAL_REQUEST_INFO:
            {
                //Logger.Info("\nRequest Info {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_MOVE_MOTOR:
            {
                //Logger.Info("\nMove Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_POSITION_CHANGED:
            {
                message = new MechanicalResponse(MessageType.MECHANICAL_POSITION_CHANGED);
                message.deserialize(payload);
                break;
            }

            case MessageType.MECHANICAL_HOME_MOTOR:
            {
                message = new MechanicalResponse(MessageType.MECHANICAL_HOME_MOTOR);
                message.deserialize(payload);
                //Logger.Info("\nHome Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_MACHINE_READY:
            {
                message = new MechanicalResponse(MessageType.MECHANICAL_MACHINE_READY);
                message.deserialize(payload);
                //Logger.Info("\nMachine Ready = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_MACHINE_BUSY:
            {
                message = new MechanicalResponse(MessageType.MECHANICAL_MACHINE_BUSY);
                message.deserialize(payload);
                //Logger.Info("\nMachine Busy = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_MACHINE_ERROR:
            {
                message = new MechanicalResponse(MessageType.MECHANICAL_MACHINE_ERROR);
                message.deserialize(payload);
                //Logger.Info("\nMachine Error = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_ENABLE_MOTOR:
            {
                //Logger.Info("\nEnable Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_DISABLE_MOTOR:
            {
                //Logger.Info("\nDisable Motor = {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            case MessageType.MECHANICAL_RT_POSITION:
            {
                message = new MechanicalPosition(MessageType.MECHANICAL_RT_POSITION);
                message.deserialize(payload);
                break;
            }

            case MessageType.MECHANICAL_UNKNOWN:
            {
                //Logger.Info("Unkown Message: {0}", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }

            default:
            {
                //Logger.Info("\nMotionCodec key = {0} does NOT match any key", BitConverter.ToString(BitConverter.GetBytes((ushort)_key)));
                break;
            }
            }
            return(message);
        }