Beispiel #1
0
 public WebApiService()
 {
     InitializeComponent();
     BasicLog.writeLog("WebApi: Start");
     Program.mControl = new MotionControl();
     BasicLog.writeLog(string.Format("Motion Control {0} configured", Program.mControl.appConfigured ? "is" : "is not"));
 }
Beispiel #2
0
        public void OutputBit(int port, int bit, int val)
        {
            if (port < 0 || port > 5)
            {
                error = "port out of range";
                return;
            }
            if (bit < 0 || bit > 7)
            {
                error = "bit out of range";
                return;
            }
            byte data = (byte)(1 << bit);

            if (val > 0)
            {
                this.Ports[port].data |= data;
            }
            else
            {
                this.Ports[port].data &= (byte)(~data);
            }

            if (this.Ports[port].data != this.Ports[port].oldValue)
            {
                BasicLog.writeLog(String.Format("OutputBit(port: {0}, bit: {1}, val: {2})", port, bit, val));
                this.Ports[port].oldValue = this.Ports[port].data;
            }
        }
Beispiel #3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            WebApiService webapiservice = null;

#if DEBUG
            if (Debugger.IsAttached)
            {
                BasicLog.writeLog("Debug Console mode");
                webapiservice = new WebApiService();
                BasicLog.writeLog("OnStart: Call");
                webapiservice.OnStart();
                BasicLog.writeLog("OnStart: Complete");
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
            if (webapiservice == null)
            {
                BasicLog.writeLog("Service mode");
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new WebApiService()
                };
                BasicLog.writeLog("Run: Call");
                ServiceBase.Run(ServicesToRun);
            }
        }
Beispiel #4
0
 public void SetDirection(int port, int direction)
 {
     if (port < 0 || port > 5)
     {
         error = "port out of range";
         return;
     }
     BasicLog.writeLog(String.Format("SetDirection(port: {0}, val: {1})", port, direction));
     this.Ports[port].portDir = (byte)direction;
 }
Beispiel #5
0
 public void SetPwmParameters(int channel, Eth32PwmChannel state, double freq, double duty)
 {
     if (channel < 0 || channel > 1)
     {
         error = "Channel out of range";
     }
     PwmChans[channel].state = state;
     PwmChans[channel].freq  = freq;
     PwmChans[channel].duty  = duty;
     BasicLog.writeLog(String.Format("SetPwmParameters(channel: {0}, freq: {1}, duty: {2})", channel, freq, duty));
 }
Beispiel #6
0
        protected override void OnStart(string[] args)
        {
            if (Program.mControl.appConfigured)
            {
                BasicLog.writeLog("Initialize Motion Control");
                Program.mControl.Connect();
                BasicLog.writeLog(string.Format("Motion Control Connection {0}", Program.mControl.isConnected() ? "Succeeded" : "Failed"));
            }
            string baseAddress = ConfigurationManager.AppSettings["WebAPIBaseAddress"];

            BasicLog.writeLog("WebApi: Start");
            WebApp.Start <WebApi>(url: baseAddress);
            BasicLog.writeLog("WebApi: Complete");
        }
Beispiel #7
0
        public void OutputByte(int port, int val)
        {
            if (port < 0 || port > 5)
            {
                error = "port out of range";
                return;
            }

            this.Ports[port].data = (byte)val;
            if (this.Ports[port].data != this.Ports[port].oldValue)
            {
                BasicLog.writeLog(String.Format("OutputByte(port: {0}, val: {1})", port, val));
                this.Ports[port].oldValue = this.Ports[port].data;
            }
        }
Beispiel #8
0
 private void Run()
 {
     while (true)
     {
         try
         {
             int sleepTime = (int)(1000 / computeHz);
             Thread.Sleep(sleepTime);
             Compute();
             if (motionComplete)
             {
                 break;
             }
         }
         catch (Exception e)
         {
             BasicLog.writeLog(e.Message);
         }
     }
 }
Beispiel #9
0
        public void SetDirectionBit(int port, int bit, int direction)
        {
            if (port < 0 || port > 5)
            {
                error = "port out of range";
                return;
            }
            if (bit < 0 || bit > 7)
            {
                error = "bit out of range";
                return;
            }
            BasicLog.writeLog(String.Format("SetDirectionBit(port: {0}, bit: {1}, direction: {2})", port, bit, direction));
            byte dir = (byte)((direction & 0x01) << (bit - 1));

            if (dir > 0)
            {
                this.Ports[port].portDir |= dir;
            }
            else
            {
                this.Ports[port].portDir &= (byte)(~dir);
            }
        }
Beispiel #10
0
        public void Connect(bool bSameAddress = true)
        {
            if (settings.eth32Address.Length == 0)
            {
                BasicLog.writeLog("Please configure the eht32 in Options->Settings");
                return;
            }

            // If we're already connected, disconnect and reconnect
            if (dev.Connected && !bSameAddress)
            {
                enableDrive(false);
                Thread.Sleep(1000);
                dev.Disconnect();
                Thread.Sleep(1000);
                dev = null;
            }

            try
            {
                // Connect, use a 1 second timeout
                if (dev == null)
                {
                    dev = new Eth32();
                }
                if (!dev.Connected)
                {
                    dev.Connect(settings.eth32Address, Eth32.DefaultPort, 1000);
                }

                if (dev.Connected)
                {
                    state = DishState.Stopped;
                    dev.ResetDevice();
                    MotionSetup();

                    azEncoder.SetupEncoderPorts();
                    elEncoder.SetupEncoderPorts();
                    //setup output port
                    this.dev.SetDirection(this.outputPortNum, 0xff);
                    //watchdog output
                    this.dev.SetDirection(4, 1);
                    Thread.Sleep(100);
                    //set up initial state of output control bits
                    this.setControlBits(true, true, false);
                    this.setControlBits(false, true, false);

                    //setup PWM
                    this.dev.PwmClockState = Eth32PwmClock.Enabled;
                    this.dev.PwmBasePeriod = 199; //10 khz

                    this.setAz(0.0);
                    this.setEl(0.0);
                    this.enableDrive(true);
                }
            }
            catch (Eth32Exception etherr)
            {
#if !_TEST
                BasicLog.writeLog("Error connecting to the ETH32: " + Eth32.ErrorString(etherr.ErrorCode));
#endif
            }
            if (!updateThread.IsAlive)
            {
                this.updateThread          = new Thread(updateThreadCallback);
                this.updateThread.Priority = ThreadPriority.Highest;
            }
            updateThread.Start();
        }
Beispiel #11
0
 protected override void OnStop()
 {
     BasicLog.writeLog("WebApi: OnStop");
     // noone seems to worry about the shutdown...
 }