Exemplo n.º 1
0
        static comparedVal compareValue(int old_val_index, int new_val, string refer = "n")
        {
            comparedVal cv = new comparedVal();

            //Console.WriteLine(refer + " new_val = " + new_val + " | old_val = " + old_coordinates);
            cv.difference = new_val - old_coordinates[old_val_index];
            cv.positive   = true;
            if (cv.difference < 0)
            {
                cv.positive = false;
            }
            old_coordinates[old_val_index] = new_val;
            return(cv);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is the function which gets called when the data is recieved by the
        /// desktop API
        /// </summary>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="z">The z coordinate.</param>
        /// <param name="u">The u coordinate.</param>
        /// <param name="v">The v coordinate.</param>
        /// <param name="w">The w coordinate.</param>

        public static void onRecieveCtrlData(int x, int y, int z, int u, int v, int w, int LP, int RP, int POS_S, int PRES_S)            // LP = left pressure, RP = right pressure
        {
            string pos_s  = resolveSensitivityParameter(POS_S);
            string pres_s = resolveSensitivityParameter(PRES_S);

            Console.WriteLine("X = " + x.ToString());
            Console.WriteLine("Y = " + y.ToString());
            Console.WriteLine("Z = " + z.ToString());
            Console.WriteLine("U = " + u.ToString());
            Console.WriteLine("V = " + v.ToString());
            Console.WriteLine("W = " + w.ToString());
            Console.WriteLine("LP = " + LP.ToString());
            Console.WriteLine("RP = " + RP.ToString());
            Console.WriteLine("POS_S = " + pos_s);
            Console.WriteLine("PRES_S = " + pres_s);
            Console.WriteLine("Sending data to machine...");
            comparedVal cv_x  = compareValue(oc_X, x);
            comparedVal cv_y  = compareValue(oc_Y, y);
            comparedVal cv_z  = compareValue(oc_Z, z);
            comparedVal cv_u  = compareValue(oc_U, u);
            comparedVal cv_v  = compareValue(oc_V, v);
            comparedVal cv_w  = compareValue(oc_W, w);
            comparedVal cv_lp = compareValue(oc_LP, LP);
            comparedVal cv_rp = compareValue(oc_RP, RP);

            sendDataToComport(cv_x, _serialport, "X", "x");
            sendDataToComport(cv_y, _serialport, "Y", "y");
            sendDataToComport(cv_z, _serialport, "Z", "z");
            sendDataToComport(cv_u, _serialport, "U", "u");
            sendDataToComport(cv_v, _serialport, "V", "v");
            sendDataToComport(cv_w, _serialport, "W", "w");
            sendDataToComport(cv_lp, _p_serialport, "Q", "q");
            sendDataToComport(cv_rp, _p_serialport, "P", "p");
            int charSendDelayMS = 1;

            try
            {
                _serialport.Write(pos_s);
                Thread.Sleep(charSendDelayMS);
                _p_serialport.Write(pres_s);
                Thread.Sleep(charSendDelayMS);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not send data to comport. \nError : " + ex.Message);
            }
        }
Exemplo n.º 3
0
        static void sendDataToComport(comparedVal cv, SerialPort serialport, string ch_inc, string ch_dec)
        {
            int charSendDelayMS = 1;

            try
            {
                string ch_toSend = ch_inc;
                if (!cv.positive)
                {
                    ch_toSend = ch_dec;
                }
                Console.WriteLine("Difference (" + ch_inc + ")= " + cv.difference.ToString());
                for (int c = 0; c < Math.Abs(cv.difference); c++)
                {
                    serialport.Write(ch_toSend);
                    Thread.Sleep(charSendDelayMS);
                }
            }catch (Exception ex) {
                Console.WriteLine("Could not send data to comport. \nError : " + ex.Message);
            }
        }