コード例 #1
0
 void WaitingSQL(object LockWatingThread)
 {
     while (true)
     {
         try
         {
             MeasureE0DataDBOption.Get(1);
         }
         catch (System.Exception ex)
         {
             Thread.Sleep(1000);
             lock (LockWatingThread)
             {
                 wp.SetProcessBarPerformStep();
             }
             continue;
         }
         break;
     }
 }
コード例 #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;
            }
        }