//处理线程函数
    void DealData()
    {
        int num = dataQueue.Count;

        byte[] results = new byte[num];
        for (int i = 0; i < num; i++)
        {
            byte result = dataQueue.Dequeue();
            results[i] = result;
        }
        //showInfo(results);
        completed = true;//串口是一个消息收->发,所以发一个消息必须等到这个消息的反馈才能继续发下一个消息
        switch (num)
        {
        case 6:    //获取线圈寄存器的状态
            byte   runbyte = results[3];
            byte[] addr    = new byte[2];
            addr[0] = results[0];
            addr[1] = 0x00;
            int  address = System.BitConverter.ToInt16(addr, 0);
            bool run     = runbyte == 0x01 ? true : false;
            Loom.QueueOnMainThread((param) =>
            {
                controller.updateCoilStatus(address, run);
            }, null);
            break;

        case 15:    //实时分析电机的状态
            int currStatus   = getFinalValue(results, new int[] { 4, 3 });
            int currSpeed    = getFinalValue(results, new int[] { 6, 5 });
            int currLocation = getFinalValue(results, new int[] { 8, 7, 10, 9 });
            int currMode     = getFinalValue(results, new int[] { 12, 11 });
            Loom.QueueOnMainThread((param) =>
            {
                controller.updateStatusValue(currStatus, currSpeed, currLocation, currMode);
            }, null);
            break;

        case 35:    //获取命令寄存器的状态
            moveSphere sphere = new moveSphere();
            sphere.mode             = getFinalValue(results, new int[] { 4, 3 });
            sphere.speed            = getFinalValue(results, new int[] { 10, 9 });
            sphere.location         = getFinalValue(results, new int[] { 12, 11, 14, 13 });
            sphere.speedPlusTime    = getFinalValue(results, new int[] { 16, 15 });
            sphere.speedMinusTime   = getFinalValue(results, new int[] { 18, 17 });
            sphere.cycleIndex       = getFinalValue(results, new int[] { 20, 19 });
            sphere.waitingTime      = getFinalValue(results, new int[] { 22, 21 });
            sphere.address          = getFinalValue(results, new int[] { 24, 23 });
            sphere.waitingTimeUnit  = getFinalValue(results, new int[] { 28, 27 });
            sphere.locationProperty = getFinalValue(results, new int[] { 30, 29 });
            sphere.locationPeriod   = getFinalValue(results, new int[] { 32, 31 });
            Loom.QueueOnMainThread((param) =>
            {
                controller.updateCommandStatus(sphere);
            }, null);

            break;
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        spheres = new List <moveSphere>();
        //Debug.Log(transform.name);
        //Transform[] gather = GetComponentsInChildren<Transform>();
        int i = 1;

        foreach (Transform child in transform)
        {
            moveSphere ms = new moveSphere();
            ms.sphere = child;
            ms.name   = child.name;
            spheres.Add(ms);
            i++;
            //Debug.Log(child.name);
        }
    }
Example #3
0
    //得到电机的初始化状态
    public void updateCommandStatus(moveSphere sphere)
    {
        //初始化页面参数
        inputSpeedPlusTime.text    = sphere.speedPlusTime.ToString();
        inputSpeedMinusTime.text   = sphere.speedMinusTime.ToString();
        inputSpeed.text            = sphere.speed.ToString();
        inputLocationPeriod.text   = sphere.locationPeriod.ToString();
        inputLocation.text         = sphere.location.ToString();
        inputLocationProperty.text = sphere.locationProperty.ToString();
        inputCycleIndex.text       = sphere.cycleIndex.ToString();
        inputWaitingTime.text      = sphere.waitingTime.ToString();
        inputWaitingTimeUnit.text  = sphere.waitingTimeUnit.ToString();
        showMode.text = modes[sphere.mode];
        //更新动画小球参数
        moveController.setSpeedPlusTime(sphere.address, sphere.speedPlusTime);
        moveController.setSpeedMinusTime(sphere.address, sphere.speedMinusTime);
        moveController.setSpeed(sphere.address, (int)sphere.speed);
        moveController.setLocationPeriod(sphere.address, sphere.locationPeriod);
        moveController.setLocationProperty(sphere.address, sphere.locationProperty);
        moveController.setLocation(sphere.address, (int)sphere.location);
        moveController.setCycleIndex(sphere.address, sphere.cycleIndex);
        moveController.setWaitingTime(sphere.address, sphere.waitingTime);
        moveController.setWaitingTimeUnit(sphere.address, sphere.waitingTimeUnit);
        moveController.setMode(currentAddress, sphere.mode);
        switch (sphere.mode)
        {
        case 1:
            speedMode.isOn    = true;
            locationMode.isOn = false;
            pointMode.isOn    = false;
            break;

        case 2:
            speedMode.isOn    = false;
            locationMode.isOn = true;
            pointMode.isOn    = false;
            break;

        case 3:
            speedMode.isOn    = false;
            locationMode.isOn = false;
            pointMode.isOn    = true;
            break;
        }
    }