public void SetDO(int port, bool status)
        {
            var p = port;

            if (p < 0)
            {
                return;
            }

            if (p < 16)
            {
                N.GT_SetDoBit(card, Api.MC_GPO, (short)(p + 1), status.ToInt16()).Verify();
                return;
            }
            p -= 16;

            if (p < 8)
            {
                N.GT_SetDoBit(card, Api.MC_ENABLE, (short)(p + 1), status.ToInt16()).Verify();
                return;
            }
            p -= 8;

            if (p < 8)
            {
                N.GT_SetDoBit(card, Api.MC_CLEAR, (short)(p + 1), status.ToInt16()).Verify();
                return;
            }
        }
        int GetRawStatus(int axis)
        {
            int s;

            N.GT_GetSts(card, Axis.Of(axis), out s).Verify();
            return(s);
        }
        public void Offset(int axis, double offset, double speed, double taccel_sec, double tdecel_sec)
        {
            int pos;

            N.GT_GetPos(card, Axis.Of(axis), out pos).Verify();
            Locate(axis, offset + pos, speed, taccel_sec, tdecel_sec);
        }
        public double GetPosition(int axis)
        {
            double pos;

            N.GT_GetAxisPrfPos(card, Axis.Of(axis), out pos).Verify();
            return(pos);
        }
        public bool GetDO(int port)
        {
            Func <short, int> getDO = ty =>
            {
                int s;
                N.GT_GetDo(card, ty, out s).Verify();
                return(s);
            };

            var p = port;

            if (p < 0)
            {
                return(false);
            }

            if (p < 16)
            {
                return(CheckBit(getDO(Api.MC_GPO), p));
            }
            p -= 16;

            if (p < 8)
            {
                return(CheckBit(getDO(Api.MC_ENABLE), p));
            }
            p -= 8;

            if (p < 8)
            {
                return(CheckBit(getDO(Api.MC_CLEAR), p));
            }

            return(false);
        }
        public void Initialize()
        {
            var path = typeof(MotionController).Assembly.Location;
            var dir  = System.IO.Path.GetDirectoryName(path);
            var cfg  = System.IO.Path.Combine(dir, "gts.cfg");

            if (System.IO.File.Exists(cfg))
            {
                N.GT_LoadConfig(card, cfg).Verify();
            }
        }
        public bool GetDI(int port)
        {
            Func <short, int> getDI = ty =>
            {
                int s;
                N.GT_GetDi(card, ty, out s).Verify();
                return(s);
            };

            var p = port;

            if (p < 0)
            {
                return(false);
            }

            if (p < 16)
            {
                return(CheckBit(getDI(Api.MC_GPI), p));
            }
            p -= 16;

            if (p < 8)
            {
                return(CheckBit(getDI(Api.MC_LIMIT_POSITIVE), p));
            }
            p -= 8;

            if (p < 8)
            {
                return(CheckBit(getDI(Api.MC_LIMIT_NEGATIVE), p));
            }
            p -= 8;

            if (p < 8)
            {
                return(CheckBit(getDI(Api.MC_ALARM), p));
            }
            p -= 8;

            if (p < 8)
            {
                return(CheckBit(getDI(Api.MC_HOME), p));
            }
            p -= 8;

            if (p < 8)
            {
                return(CheckBit(getDI(Api.MC_ARRIVE), p));
            }

            return(false);
        }
 public IMotionController[] GetMotionControllers()
 {
     if (_motionControllers == null)
     {
         _motionControllers =
             Enumerable.Range(0, 2)
             .Select(Card.Of)
             .Where(c => N.GT_Open(c) == 0)
             .Select(c => (IMotionController) new MotionController(c))
             .ToArray();
     }
     return(_motionControllers);
 }
        public void ToSpeed(int axis, double speed, double taccel_sec, double tdecel_sec)
        {
            var pls_ms = speed / 1000.0;
            var acc_ms = speed / taccel_sec / (1000.0 * 1000.0);
            var dec_ms = speed / tdecel_sec / (1000.0 * 1000.0);
            var a      = Axis.Of(axis);

            N.GT_AxisOn(card, a).Verify();
            N.GT_ClrSts(card, a, 1).Verify();
            N.GT_PrfJog(card, a).Verify();
            Api.TJogPrm param;
            N.GT_GetJogPrm(card, a, out param).Verify();
            param.acc = acc_ms;
            param.dec = acc_ms;
            N.GT_SetJogPrm(card, a, ref param).Verify();
            N.GT_SetVel(card, a, pls_ms).Verify();
            N.GT_Update(card, a.Mask).Verify();
        }
Exemple #10
0
        void HomeAsync(int axis, double speed)
        {
            var a      = Axis.Of(axis);
            var pls_ms = speed / 1000.0;
            var acc_ms = (speed * 10.0) / (1000.0 * 1000.0);

            N.GT_ClrSts(card, a, 1).Verify();
            N.GT_AxisOn(card, a).Verify();
            N.GT_SetCaptureMode(card, a, Api.CAPTURE_HOME).Verify();
            N.GT_ZeroPos(card, a, 1).Verify();
            Offset(axis, -10000000, speed, 0.01, 0.01);

            Task.Run(async() =>
            {
                try
                {
                    short cap = 0;
                    int pos   = 0;
                    do
                    {
                        N.GT_GetCaptureStatus(card, a, out cap, out pos).Verify();
                        if (cap != 0)
                        {
                            N.GT_SetPos(card, a, pos).Verify();
                            N.GT_Update(card, a.Mask).Verify();
                            break;
                        }
                        await Task.Delay(1);
                    } while (!IsStop(axis));

                    while (!IsStop(axis))
                    {
                        await Task.Delay(1);
                    }

                    return(cap != 0);
                }
                catch (Exception)
                {
                    return(false);
                }
            });
        }
Exemple #11
0
        public void Locate(int axis, double position, double speed, double taccel_sec, double tdecel_sec)
        {
            var pls_ms = speed / 1000.0;
            var acc_ms = speed / taccel_sec / (1000.0 * 1000.0);
            var dec_ms = speed / tdecel_sec / (1000.0 * 1000.0);
            var a      = Axis.Of(axis);

            N.GT_ClrSts(card, a, 1).Verify();
            N.GT_AxisOn(card, a).Verify();
            N.GT_PrfTrap(card, a).Verify();
            Api.TTrapPrm param;
            N.GT_GetTrapPrm(card, a, out param).Verify();
            param.velStart = 0;
            param.acc      = acc_ms;
            param.dec      = dec_ms;

            N.GT_SetTrapPrm(card, a, ref param).Verify();
            N.GT_SetPos(card, a, position.Round()).Verify();
            N.GT_SetVel(card, a, pls_ms).Verify();
            N.GT_Update(card, a.Mask).Verify();
        }
Exemple #12
0
 public void Stop(int axis)
 {
     N.GT_Stop(card, Axis.Of(axis).Mask, 0).Verify();
 }
Exemple #13
0
 public void ZeroPosition(int axis)
 {
     N.GT_ZeroPos(card, Axis.Of(axis), 1).Verify();
 }