Example #1
0
            /// <summary>
            /// アクションコマンドを生成する
            /// </summary>
            /// <param name="cid">コマンドID</param>
            /// <param name="pin">ピン番号[0,1(M1/2)2-9(Servo)10-18(Sensor)19(SPI)</param>
            /// <param name="args">各コマンドに応じた引数の配列</param>
            /// <returns>アクションコマンド(2バイト)</returns>
            public byte[] actCommand(CommandID cid, PinID pin, byte[] args)
            {
                byte[] msg = new byte[2];
                msg[0] = (byte)(128 + ((int)cid << 4 & 0x70) + ((int)pin << 1));
                switch (cid)
                {
                case CommandID.DC:
                    msg[0] = (byte)(128 + (int)pin * 8 + args[0]);
                    msg[1] = (byte)args[1];
                    break;

                case CommandID.SV:
                    msg[0]  = (byte)(128 + ((int)cid << 4 & 0x70) + ((int)(pin - 2) << 1));
                    msg[0] += (byte)(args[0] >> 7 & 0x01);
                    msg[1]  = (byte)(args[0] & 0x7f);
                    break;

                case CommandID.LED:
                    if (args.Length >= 1)
                    {
                        msg[0] += (byte)(args[0] & 0x01);
                    }
                    if (args.Length >= 2)
                    {
                        msg[1] = (byte)((args[1] & 0x01) << 6);
                    }
                    break;

                case CommandID.SyncSV:
                    msg[1] = (byte)args[0];
                    break;
                }

                return(msg);
            }
Example #2
0
        private void btnFindMe_Click(object sender, EventArgs e)
        {
            string test = txtAccessIDEntry.Text;
            int    intTest;
            bool   isNumerical = int.TryParse(test, out intTest);

            /*
             * First checks if the user input is numeric
             */

            if (isNumerical)
            {
                /*
                 * Second checks if the user input is appropriate length
                 */

                if (test.Length != Globals.BookStore.accessIDLength)
                {
                    MessageBox.Show("Please enter a valid Access ID!", "Invalid Access ID Detected");
                    tryCount++;
                    txtAccessIDEntry.Text = "";
                    txtAccessIDEntry.Focus();
                }
                else
                {
                    int accessID = int.Parse(txtAccessIDEntry.Text);
                    //Console.WriteLine(accessID);
                    if (Globals.BookStore.findEmployee(accessID))
                    {
                        // MessageBox.Show("Employee ID has been found!", "You have been found!");
                        this.Hide();
                        PinID PINForm = new PinID();
                        PINForm.Show();
                        tryCount = 0;
                    }
                    else
                    {
                        MessageBox.Show("Please enter a valid Access ID.", "Invalid Access ID Detected");
                        tryCount++;
                    }
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid Access ID!", "Invalid Access ID Detected");
                tryCount++;
                txtAccessIDEntry.Focus();
            }

            /*
             * This if statement tracks the attempts the user makes before force exitting the program.
             */

            if (tryCount == Globals.BookStore.tryCountMax)
            {
                MessageBox.Show("You have reached the max attempts... Force Exitting now...", "Intrusion Detected");
                this.Close();
            }
        }
Example #3
0
 /** コンストラクタ.
  */
 public PinSet()
 {
     PinID   = 0;
     PinName = "";
     PinNum  = "";
     PinInit = "";
     PinC    = "";
     PinD    = "";
     PinE    = "";
     PinF    = "";
 }
Example #4
0
        protected override void setDCMotorSwitch(byte port, bool onoff)
        {
            base.setDCMotorSwitch(port, onoff);

            byte[] args = new byte[2];
            args[0] = onoff ? (byte)0x01 : (byte)0x02;   // 0x01: 回転 0x02: 停止
            args[1] = 0;                                 // 回転:: 0:正転 1:逆転 | 停止:: 0:ブレーキあり 1:ブレーキなし
            PinID pin = (port == 0) ? PinID.M1 : PinID.M2;

            //setDCMotorPower(port, 100);
            tcom.sendCommand(CommandID.DC, pin, args);
        }
Example #5
0
        protected override void setDCMotorPower(byte port, byte power)
        {
            if (canSend)
            {
                canSend = false;
                base.setDCMotorPower(port, power);

                byte[] args = new byte[2];
                args[0] = (byte)0x04;                        // 0x04: 速度
                args[1] = power;
                PinID pin = (port == 0) ? PinID.M1 : PinID.M2;
                tcom.sendCommand(CommandID.DC, pin, args);
                canSend = true;
            }
        }
Example #6
0
 /// <summary>
 /// テストモードの初期化用データを生成する
 /// </summary>
 /// <param name="pin">ピン番号[0,1(M1/2)2-9(Servo)10-18(Sensor)19(SPI)</param>
 /// <param name="pid">パーツID</param>
 /// <returns></returns>
 public byte[] initCommand(PinID pin, PartID pid)
 {
     byte[] msg = new byte[2];
     msg[0] = (byte)(192 + ((int)pin >> 1 & 0x0f));
     msg[1] = (byte)(((int)pin << 6 & 0x40) | (int)pid);
     Debug.Write("Port initialization\t");
     Debug.Write(pin);
     Debug.Write("\t");
     Debug.Write(pid);
     Debug.Write("\t");
     Debug.Write(msg[0]);
     Debug.Write("\t");
     Debug.WriteLine(msg[1]);
     return(msg);
 }
Example #7
0
        void nudAngle_ValueChanged(object sender, EventArgs e)
        {
            if (canSend)
            {
                canSend = false;
                int    offset = (int)(sender as NumericUpDown).Value;
                PinID  port   = PinID.D5;
                object target = (sender as NumericUpDown).Parent;

                if (target == saD5)
                {
                    port = PinID.D5;
                }
                if (target == saD6)
                {
                    port = PinID.D6;
                }
                if (target == saD9)
                {
                    port = PinID.D9;
                }
                if (target == saD10)
                {
                    port = PinID.D10;
                }
                if (target == saD11)
                {
                    port = PinID.D11;
                }

                // サーボモーターに角度情報を送信
                setServoMotor(port, offset);
                //if (setServoMotor(port, offset) != RET_SUCCESS)
                //{   // 通信が切断された場合
                //    // エラーコードを設定して、キャンセルボタンをクリック
                //    btCancel.PerformClick();
                //    errorCode = (byte)ConnectingCondition.DISCONNECT;
                //    isConnectiong = false;  // 通信切断状態を設定
                //}
                canSend = true;
            }
        }
Example #8
0
 void setServoMotor(PinID port, int offset)
 {
     byte[] angle = { (byte)(90 + offset) };
     tcom.sendCommand(CommandID.SV, port, angle);
 }
Example #9
0
 public bool sendCommand(CommandID cid, PinID pin, byte[] args)
 {
     return(sendCommand(comGen.actCommand(cid, pin, args)));
 }
Example #10
0
 public bool sendCommand(PinID pin, PartID part)
 {
     return(sendCommand(comGen.initCommand(pin, part)));
 }
Example #11
0
 /** �R���X�g���N�^.
  */
 public PinSet()
 {
     PinID = 0;
     PinName = "";
     PinNum = "";
     PinInit = "";
     PinC = "";
     PinD = "";
     PinE = "";
     PinF = "";
 }