示例#1
0
        // control event handle
        private void OnEvent(object sender)
        {
            if (!isConnectted)
            {
                return;
            }

            UInt64 cmdIndex = 0;
            Button obj      = (Button)sender;
            String con      = obj.Content.ToString();

            switch (con)
            {
            case "R+":
            case "Joint4+":
            {
                currentCmd.isJoint = isJoint;
                currentCmd.cmd     = (byte)JogCmdType.JogDPPressed;
                DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
            }
            break;

            case "R-":
            case "Joint4-":
            {
                currentCmd.isJoint = isJoint;
                currentCmd.cmd     = (byte)JogCmdType.JogDNPressed;
                DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
            }
            break;

            default:
                break;
            }
        }
示例#2
0
        async void dispatcherTimer_Tick(object sender, object e)
        {
            UInt64         cmdIndex = 0;
            GattReadResult result   = await myCharacteristic.ReadValueAsync(BluetoothCacheMode.Uncached);

            if (result.Status == GattCommunicationStatus.Success)
            {
                var    reader = DataReader.FromBuffer(result.Value);
                byte[] input  = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(input);
                float XOrientation = BitConverter.ToSingle(new Byte[] { input[0], input[1], input[2], input[3] }, 0);
                float YOrientation = BitConverter.ToSingle(new Byte[] { input[4], input[5], input[6], input[7] }, 0);
                float ZOrientation = BitConverter.ToSingle(new Byte[] { input[8], input[9], input[10], input[11] }, 0);
                float DX           = XOrientation - oldXOrientation;
                oldXOrientation = XOrientation;
                if (DX > 1)
                {
                    currentCmd.isJoint = isJoint;
                    currentCmd.cmd     = (byte)JogCmdType.JogAPPressed;
                    DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
                }
                else if (DX < -1)
                {
                    currentCmd.isJoint = isJoint;
                    currentCmd.cmd     = (byte)JogCmdType.JogANPressed;
                    DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
                }

                float DY = YOrientation - oldYOrientation;
                oldYOrientation = YOrientation;
                if (DY > 1)
                {
                    currentCmd.isJoint = isJoint;
                    currentCmd.cmd     = (byte)JogCmdType.JogBPPressed;
                    DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
                }
                else if (DY < -1)
                {
                    currentCmd.isJoint = isJoint;
                    currentCmd.cmd     = (byte)JogCmdType.JogBNPressed;
                    DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
                }

                float DZ = ZOrientation - oldZOrientation;
                oldZOrientation = ZOrientation;
                if (DZ > 1)
                {
                    currentCmd.isJoint = isJoint;
                    currentCmd.cmd     = (byte)JogCmdType.JogCPPressed;
                    DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
                }
                else if (DZ < -1)
                {
                    currentCmd.isJoint = isJoint;
                    currentCmd.cmd     = (byte)JogCmdType.JogCNPressed;
                    DobotDll.SetJOGCmd(ref currentCmd, false, ref cmdIndex);
                }

                String s = String.Format("X={0} ; Y={1} ; Z={2}", XOrientation, YOrientation, ZOrientation);

                textBlock.Text = s;
            }
        }