Example #1
0
        void InitPCIE()
        {
            byte[] readList = new byte[0x100];
            byte   read     = 0;

            //获得中断号
            CH368.CH367mGetIntLine(CH368Index, ref oIntLine);
            //取得操作基地址
            CH368.CH367mGetIoBaseAddr(CH368Index, out mBaseAddr);
            CH368.CH368mGetMemBaseAddr(CH368Index, out mMemAddr);
            //RAM CE 高电平 A15
            CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xf8, ref read);
            BytesOP.SetBit(ref read, 0);
            BytesOP.ClrBit(ref read, 2);//清中断标志
            CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, read);
            //8位数据总线
            CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xfa, ref read);
            BytesOP.ClrBit(ref read, 6);
            CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xfa, read);
            //SCS 高电平
            CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xe8, ref read);
            BytesOP.SetBit(ref read, 2);
            CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, read);
            //配置中断服务程序
            _CH368IntProc = new CH368.mPCH367_INT_ROUTINE(CH368IntProc);
            CH368.CH367mSetIntRoutine(CH368Index, _CH368IntProc);
            //低电平中断
            read = 0xe2;
            CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xeb, read);
            //首次判断
//             CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xf8, ref read);
//             if (!BytesOP.GetBit(read, 3))
//             {
//                 CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xe8, ref read);
//                 BytesOP.ClrBit(ref read, 2);//拉低SCS
//                 CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, read);
//                 while (true)
//                 {
//                     CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xf8, ref read);
//                     if (BytesOP.GetBit(read, 3))
//                         break;
//                 }
//             }
            //CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadIoByte, mBaseAddr->mCH367IoPort[mAddr], read, 1);
        }
Example #2
0
        void CH368IntProc()
        {
            byte[] readHeaderList = new byte[7];
            byte[] readDataList   = new byte[0x100];
            byte   read           = 0;

            /************************************************************************/
            /*  读ram                                                               */
            /************************************************************************/
            //拉低片选
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, 0xb0) == 0)
            {
                MessageBox.Show("1");
                return;
            }
            //读7个字节,判断是否为有效帧
//             CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr, readList, 64);
//             this.Invoke((EventHandler)(delegate { textBox1.Text = StringsFunction.byteToHexStr(readList, 0, (int)64, " "); }));
            //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, (int)9, " "));
            if (CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr, readHeaderList, 7) == 0)
            {
                MessageBox.Show("2");
                return;
            }
            if (bLog)
            {
                this.Invoke((EventHandler)(delegate
                {
                    try
                    {
                        textBox1.AppendText(DateTime.Now.ToString() + ":");
                        textBox1.AppendText(StringsFunction.byteToHexStr(readHeaderList, 0, 7, " "));
                    }
                    catch
                    {
                    }
                }));
                //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, 7, " "));
            }

            if (readHeaderList[0] == 0xfa && readHeaderList[1] == 0xf3 && readHeaderList[2] == 0x30)
            {
                //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, 7, " "));
                uint readDataLen = readHeaderList[6];// BytesOP.MakeShort(readHeaderList[5], readHeaderList[6]);
                if (CH368.CH367mAccessBlock(CH368Index, CH368.mFuncReadMemByte, mMemAddr + 7, readDataList, readDataLen) == 0)
                {
                    MessageBox.Show("3");
                    return;
                }
                if (bLog)
                {
                    string str = StringsFunction.byteToHexStr(readDataList, 0, (int)readDataLen, " ");
                    try
                    {
                        this.Invoke((EventHandler)(delegate
                        {
                            textBox1.AppendText(str);
                        }));
                    }
                    catch
                    {
                    }
                }
                if (readHeaderList[3] == 0xe0 || readHeaderList[3] == 0xe2)
                {
                    MeasureE0Data e0 = new MeasureE0Data();
                    e0.Source = readHeaderList[3];
                    Fuction.AnalyzeE0Data(ref e0, readDataList, readDataLen);
                    e0.Time = DateTime.Now;
                    MeasureE0DataDBOption.Insert(e0);
                }
                else if (readHeaderList[3] == 0xe1 || readHeaderList[3] == 0xe3)
                {
                    MeasureE1Data e1 = new MeasureE1Data();
                    e1.Source = readHeaderList[3];
                    Fuction.AnalyzeE1Data(ref e1, readDataList, readDataLen);
                    e1.Time = DateTime.Now;
                    MeasureE1DataDBOption.Insert(e1);
                }
                //Debug.WriteLine(StringsFunction.byteToHexStr(readList, 0, (int)len, " "));
            }
            if (bLog)
            {
                this.Invoke((EventHandler)(delegate
                {
                    try
                    {
//                         bLog = false;
//                         timerLog.Enabled = true;
                        textBox1.AppendText("\r\n");
                    }
                    catch
                    {
                    }
                }));
            }
            //拉高片选
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xf8, 0xb1) == 0)
            {
                MessageBox.Show("4");
                return;
            }
            /************************************************************************/
            /*  完成读取,告知单片机                                                */
            /************************************************************************/
            //拉低SCS,表示在处理完成
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, 0x03) == 0)
            {
                MessageBox.Show("5");
                return;
            }
            //等待单片机退出通信流程
            while (true)
            {
                if (CH368.CH367mReadIoByte(CH368Index, mBaseAddr + 0xf8, ref read) == 0)
                {
                    MessageBox.Show("10");
                    return;
                }
                if (BytesOP.GetBit(read, 3))
                {
                    break;
                }
            }
            //SCS 高电平
            if (CH368.CH367mWriteIoByte(CH368Index, mBaseAddr + 0xe8, 0x07) == 0)
            {
                MessageBox.Show("12");
                return;
            }
        }