예제 #1
0
        //**************************************************************************
        //EPX64の初期化
        //引数:なし
        //戻値:なし
        //**************************************************************************
        public bool InitEpx64R(byte DirectionData)
        {
            try
            {
                // Device Number
                this.Status = EPX64R.EPX64R_GetNumberOfDevices(ref this.Number);
                if (this.Status != EPX64R.EPX64R_OK)
                {
                    return(false);
                }
                if (this.Number == 0)
                {
                    return(false);
                }

                // Device Open
                this.Status = EPX64R.EPX64R_Open(ref this.hDevice);
                if (this.Status != EPX64R.EPX64R_OK)
                {
                    return(false);
                }

                // Direction 0=入力 1=出力
                this.Direction = DirectionData;//0x37; // P7:0 P6:0 P5:1 P4:1 P3:0 P2:1 P1:1 P0:1
                this.Status    = EPX64R.EPX64R_SetDirection(this.hDevice, this.Direction);
                if (this.Status != EPX64R.EPX64R_OK)
                {
                    EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                    return(false);
                }
                return(true);
            }
            catch
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                return(false);
            }
        }
예제 #2
0
        //****************************************************************************
        //メソッド名:OutBit(指定ポートにビット単位での出力)
        //引数:引数�@ ポート名("P00"、"P01"・・・"P07")引数�A出力値(H:0/ L: 1)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutBit(PORT pName, BIT bName, OUT data)
        {
            //ポートの特定
            byte PortOutData = 0;

            switch (pName)
            {
            case PORT.P0:
                this.Port   = EPX64R_PORT0;
                PortOutData = this.p0Outdata;
                break;

            case PORT.P1:
                this.Port   = EPX64R_PORT1;
                PortOutData = this.p1Outdata;
                break;

            case PORT.P2:
                this.Port   = EPX64R_PORT2;
                PortOutData = this.p2Outdata;
                break;

            case PORT.P3:
                this.Port   = EPX64R_PORT3;
                PortOutData = this.p3Outdata;
                break;

            case PORT.P4:
                this.Port   = EPX64R_PORT4;
                PortOutData = this.p4Outdata;
                break;

            case PORT.P5:
                this.Port   = EPX64R_PORT5;
                PortOutData = this.p5Outdata;
                break;

            case PORT.P6:
                this.Port   = EPX64R_PORT6;
                PortOutData = this.p6Outdata;
                break;

            case PORT.P7:
                this.Port   = EPX64R_PORT7;
                PortOutData = this.p7Outdata;
                break;

            default:
                return(1);
            }

            //ビットの特定
            byte Temp = 0;
            int  Num  = 0;

            switch (bName)
            {
            case BIT.b0:
                Num = 0; Temp = 0xFE;
                break;

            case BIT.b1:
                Num = 1; Temp = 0xFD;
                break;

            case BIT.b2:
                Num = 2; Temp = 0xFB;
                break;

            case BIT.b3:
                Num = 3; Temp = 0xF7;
                break;

            case BIT.b4:
                Num = 4; Temp = 0xEF;
                break;

            case BIT.b5:
                Num = 5; Temp = 0xDF;
                break;

            case BIT.b6:
                Num = 6; Temp = 0xBF;
                break;

            case BIT.b7:
                Num = 7; Temp = 0x7F;
                break;
            }


            //データの出力
            byte Data = 0;

            switch (data)
            {
            case OUT.H:
                Data = 1;
                break;

            case OUT.L:
                Data = 0;
                break;
            }


            byte OutputValue = (byte)((PortOutData & Temp) | (Data << Num));//byteでキャストしないと怒られる
            int  flag        = EPX64R.EPX64R_OutputPort(this.hDevice, Port, OutputValue);

            if (flag != EPX64R.EPX64R_OK)
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                //MessageBox.Show("EPX64R_OutputPort() Error");
                return(1);
            }

            switch (pName)
            {
            case PORT.P0:
                this.p0Outdata = OutputValue;
                break;

            case PORT.P1:
                this.p1Outdata = OutputValue;
                break;

            case PORT.P2:
                this.p2Outdata = OutputValue;
                break;

            case PORT.P3:
                this.p3Outdata = OutputValue;
                break;

            case PORT.P4:
                this.p4Outdata = OutputValue;
                break;

            case PORT.P5:
                this.p5Outdata = OutputValue;
                break;

            case PORT.P6:
                this.p6Outdata = OutputValue;
                break;

            case PORT.P7:
                this.p7Outdata = OutputValue;
                break;
            }
            return(0);
        }
예제 #3
0
        //****************************************************************************
        //メソッド名:OutByte(指定ポートにバイト単位での出力)
        //引数:引数�@ ポート名("P0"、"P1"・・・"P7")引数�A出力値(0x00〜0xFF)
        //戻り値:正常0、異常1
        //****************************************************************************
        public int OutByte(PORT pName, byte Data)
        {
            int flag = 0;

            //ポートの特定と出力データバッファの更新
            switch (pName)
            {
            case PORT.P0:
                this.Port      = EPX64R_PORT0;
                this.p0Outdata = Data;
                break;

            case PORT.P1:
                this.Port      = EPX64R_PORT1;
                this.p1Outdata = Data;
                break;

            case PORT.P2:
                this.Port      = EPX64R_PORT2;
                this.p2Outdata = Data;
                break;

            case PORT.P3:
                this.Port      = EPX64R_PORT3;
                this.p3Outdata = Data;
                break;

            case PORT.P4:
                this.Port      = EPX64R_PORT4;
                this.p4Outdata = Data;
                break;

            case PORT.P5:
                this.Port      = EPX64R_PORT5;
                this.p5Outdata = Data;
                break;

            case PORT.P6:
                this.Port      = EPX64R_PORT6;
                this.p6Outdata = Data;
                break;

            case PORT.P7:
                this.Port      = EPX64R_PORT7;
                this.p7Outdata = Data;
                break;

            default:
                return(1);   //ポート名間違えたら異常とする
            }

            //データの出力
            flag = EPX64R.EPX64R_OutputPort(this.hDevice, this.Port, Data);
            if (flag != EPX64R.EPX64R_OK)
            {
                EPX64R.EPX64R_Close(this.hDevice);   // Device Close
                //MessageBox.Show("EPX64R_OutputPort() Error");
                return(1);
            }

            return(0);
        }
예제 #4
0
        //****************************************************************************
        //メソッド名:ReadInputData(指定ポートのデータを取り込む)
        //引数:ポート名("P0"、"P1"・・・"P7")
        //戻り値:取り込んだデータ正常0、異常1
        //****************************************************************************
        public bool ReadInputData(PORT pName)
        {
            try
            {
                switch (pName)
                {
                case PORT.P0:
                    this.Port = EPX64R.EPX64R_PORT0;     // PORT0
                    break;

                case PORT.P1:
                    this.Port = EPX64R.EPX64R_PORT1;     // PORT1
                    break;

                case PORT.P2:
                    this.Port = EPX64R.EPX64R_PORT2;     // PORT2
                    break;

                case PORT.P3:
                    this.Port = EPX64R.EPX64R_PORT3;     // PORT3
                    break;

                case PORT.P4:
                    this.Port = EPX64R.EPX64R_PORT4;     // PORT4
                    break;

                case PORT.P5:
                    this.Port = EPX64R.EPX64R_PORT5;     // PORT5
                    break;

                case PORT.P6:
                    this.Port = EPX64R.EPX64R_PORT6;     // PORT6
                    break;

                case PORT.P7:
                    this.Port = EPX64R.EPX64R_PORT7;     // PORT7
                    break;

                default:
                    break;
                }

                // Input
                this.Status = EPX64R.EPX64R_InputPort(this.hDevice, this.Port, ref this.InputValue);
                if (Status != EPX64R.EPX64R_OK)
                {
                    //MessageBox.Show("EPX64R_InputPort() Error");
                    EPX64R.EPX64R_Close(hDevice);   // Device Close
                    return(false);
                }

                switch (pName)
                {
                case PORT.P0:
                    this.P0InputData = this.InputValue;
                    break;

                case PORT.P1:
                    this.P1InputData = this.InputValue;
                    break;

                case PORT.P2:
                    this.P2InputData = this.InputValue;
                    break;

                case PORT.P3:
                    this.P3InputData = this.InputValue;
                    break;

                case PORT.P4:
                    this.P4InputData = this.InputValue;
                    break;

                case PORT.P5:
                    this.P5InputData = this.InputValue;
                    break;

                case PORT.P6:
                    this.P6InputData = this.InputValue;
                    break;

                case PORT.P7:
                    this.P7InputData = this.InputValue;
                    break;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #5
0
        public static void Init周辺機器()//TODO:
        {
            Flags.Initializing周辺機器 = true;

            Target.OpenPort();//COM1のため、無条件でOKとする 判定はしない

            //EPX64Sの初期化
            bool StopEpx64 = false;

            Task.Run(() =>
            {
                //IOボードの初期化
                io = new EPX64R();
                while (true)
                {
                    if (Flags.StopInit周辺機器)
                    {
                        break;
                    }

                    Flags.StateEpx64 = General.io.InitEpx64R(0x7F);//0111 1111  ※P7入力 その他出力
                    if (Flags.StateEpx64)
                    {
                        //IOボードのリセット(出力をすべてLする)
                        ResetIo();
                        break;
                    }

                    Sleep(500);
                }
                StopEpx64 = true;
            });

            //ファンクションジェネレータの初期化
            bool StopWavGen = false;

            Task.Run(() =>
            {
                while (true)
                {
                    if (Flags.StopInit周辺機器)
                    {
                        break;
                    }

                    Flags.StateWavGen = WaveFormGenerator.Initialize();
                    if (Flags.StateWavGen)
                    {
                        break;
                    }

                    Thread.Sleep(400);
                }

                StopWavGen = true;
            });

            //HIOKI7012の初期化
            bool Stop7012 = false;

            Task.Run(() =>
            {
                while (true)
                {
                    if (Flags.StopInit周辺機器)
                    {
                        break;
                    }

                    Flags.State7012 = HIOKI7012.Init7012();
                    if (Flags.State7012)
                    {
                        HIOKI7012.StopSource();
                        break;
                    }
                    Sleep(500);
                }

                Stop7012 = true;
            });

            //USBシリアル変換器を使うので、通信がかち合わないように順番に初期化を行う
            //マルチメータの初期化
            //オシロスコープの初期化
            bool Stop323x  = false;
            bool Stop5107B = false;

            osc = new DS_5107B();
            Task.Run(() =>
            {
                while (true)
                {
                    if (Flags.StopInit周辺機器 || (Flags.State323x && Flags.State5107B))
                    {
                        break;
                    }


                    if (!Flags.State323x)
                    {
                        Flags.State323x = Hioki3239.Init323x();
                    }

                    if (!Flags.State5107B)
                    {
                        Flags.State5107B = osc.Init();
                        if (Flags.State5107B)
                        {
                            osc.SetBasicConf();
                        }
                    }
                    Sleep(500);
                }
                Stop323x = Stop5107B = true;
            });

            Task.Run(() =>
            {
                while (true)
                {
                    CheckAll周辺機器フラグ();

                    //EPX64Sの初期化の中で、K100、K101の溶着チェックを行っているが、これがNGだとしてもInit周辺機器()は終了する
                    var IsAllStopped = StopEpx64 && Stop7012 && Stop5107B && Stop323x && StopWavGen;

                    if (Flags.AllOk周辺機器接続 || IsAllStopped)
                    {
                        break;
                    }
                    Thread.Sleep(400);
                }
                Flags.Initializing周辺機器 = false;
            });
        }