Esempio n. 1
0
 static void Main()
 {
     List<DeviceListItem> list = Jrk.getConnectedDevices();
      while(true) {
     string line;
     while((line=Console.ReadLine())!=null) {
        string[] p = line.Split();
        if(p.Length==1) {
           ushort id = Convert.ToUInt16(p[0]);
           if(id>=list.Count){Console.WriteLine(-1);continue;};
           jrk = new Jrk(list[id]);
           double current = 0.0;
           for(int i=0; i<100; i++)
              current += jrk.getVariables().current;
           Console.WriteLine(current);
           jrk.disconnect();
        }
        if(p.Length==2) {
           ushort id = Convert.ToUInt16(p[0]);
           if(id>=list.Count)continue;
           ushort v = Convert.ToUInt16(Convert.ToDouble(p[1])*40.95);
           if(v>4095)v=4095;
           jrk = new Jrk(list[id]);
           jrk.setTarget(v);
           jrk.disconnect();
        }
     }
      }
 }
Esempio n. 2
0
        /// <summary>
        /// Steps through a simple sequence, setting the target to
        /// 1500, 2000, and 2500 with 1 second between frames.
        /// This function is run every 100 ms when the motion sequence
        /// is activated.
        /// </summary>
        void RunSequence()
        {
            if (sequenceCounter < 10)
            {
                jrk.setTarget(1500);
            }
            else if (sequenceCounter < 20)
            {
                jrk.setTarget(2000);
            }
            else if (sequenceCounter < 30)
            {
                jrk.setTarget(2500);
            }
            else
            {
                sequenceCounter = 0;
            }

            // increment the counter by 1 every 100 ms
            sequenceCounter += 1;
        }
Esempio n. 3
0
 // Starts the motor
 public static void startMotors()
 {
     if (NumOfConnectedJrks > 0)
     {
         UInt16 target = Jrk1.getVariables().target;
         Jrk1.setTarget(target);
     }
     if (NumOfConnectedJrks > 1)
     {
         UInt16 target = Jrk2.getVariables().target;
         Jrk2.setTarget(target);
     }
     if (NumOfConnectedJrks > 2)
     {
         UInt16 target = Jrk3.getVariables().target;
         Jrk3.setTarget(target);
     }
     if (NumOfConnectedJrks > 3)
     {
         UInt16 target = Jrk4.getVariables().target;
         Jrk4.setTarget(target);
     }
 }
Esempio n. 4
0
        static void MainWithExceptions(string[] args)
        {
            // If no arguments are given, just show the help message.
            if (args.Length == 0)
            {
                Console.Write(helpMessage());
                Environment.Exit(2);
            }

            // Parse the arguments.
            Dictionary <String, String> opts = new Dictionary <string, string>();
            string name = null;

            foreach (string rawArg in args)
            {
                string arg = rawArg;

                // Transform the short names in to the long names.
                switch (arg)
                {
                case "-l": arg = "--list"; break;

                case "-d": arg = "--device"; break;

                case "-s": arg = "--status"; break;
                }

                Match m = Regex.Match(arg, "^--(.*)");
                if (m.Success)
                {
                    name       = m.Groups[1].ToString();
                    opts[name] = ""; // start it off with no string value
                }
                else if (name != null)
                {
                    // This argument is right after a -- argument, so this argument
                    // is its value.
                    opts[name] = arg;
                    name       = null;
                }
                else
                {
                    throw new ArgumentException("Unexpected argument \"" + arg + "\".");
                }
            }

            if (opts.ContainsKey("list"))
            {
                if (args.Length > 1)
                {
                    throw new ArgumentException("If --list is present, it must be the only option.");
                }
                listDevices();
                return;
            }

            // Otherwise, we have to connect to a device.

            List <DeviceListItem> list = Jrk.getConnectedDevices();

            // Make sure there is a device available..
            if (list.Count == 0)
            {
                throw new Exception("No jrks found.");
            }

            DeviceListItem item = null;

            if (!opts.ContainsKey("device"))
            {
                // No serial number specified: connect to the first item in the list.
                item = list[0];
            }
            else
            {
                // Serial number specified.

                // Remove the leading # sign.  It is not standard to put it there,
                // but if someone writes it, this program should still work.
                string check_serial_number = opts["device"].TrimStart('#');

                // Find the device with the specified serial number.
                foreach (DeviceListItem check_item in list)
                {
                    if (check_item.serialNumber == check_serial_number)
                    {
                        item = check_item;
                        break;
                    }
                }
                if (item == null)
                {
                    throw new Exception("Could not find a jrk with serial number " + opts["device"] + ".\n" +
                                        "To list devices, use the --list option.");
                }
            }

            // Connect to the device.
            jrk = new Jrk(item);

            if (opts.ContainsKey("bootloader"))
            {
                jrk.startBootloader();
                return;
            }

            if (opts.ContainsKey("restoredefaults"))
            {
                jrk.setJrkParameter(jrkParameter.PARAMETER_INITIALIZED, 0xFF);
                jrk.reinitialize();
                Thread.Sleep(1000);
            }

            if (opts.ContainsKey("configure"))
            {
                string       filename = opts["configure"];
                Stream       stream   = File.Open(filename, FileMode.Open);
                StreamReader sr       = new StreamReader(stream);
                ConfigurationFile.load(sr, jrk);
                sr.Close();
                stream.Close();
                jrk.reinitialize();
            }

            if (opts.ContainsKey("getconf"))
            {
                string       filename = opts["getconf"];
                Stream       stream   = File.Open(filename, FileMode.Create);
                StreamWriter sw       = new StreamWriter(stream);
                ConfigurationFile.save(sw, jrk);
                sw.Close();
                stream.Close();
            }

            if (opts.ContainsKey("clearerrors"))
            {
                jrk.clearErrors();
            }

            if (opts.ContainsKey("target"))
            {
                UInt16 target = stringToU12(opts["target"]);
                jrk.setTarget(target);
            }

            if (opts.ContainsKey("run"))
            {
                UInt16 target = jrk.getVariables().target;
                jrk.setTarget(target);
            }

            if (opts.ContainsKey("stop"))
            {
                jrk.motorOff();
            }

            if (opts.ContainsKey("status"))
            {
                displayStatus(jrk);
            }

            if (opts.ContainsKey("stream"))
            {
                streamVariables(jrk, opts);
            }

            jrk.disconnect();
        }