Exemple #1
0
        private void ProcVersion()
        {
            FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x01);

            byte[] frameData   = new byte[20];
            int    frameLength = 0;

            try
            {
                SerialManager.Send(new byte[] { 0x01, 0x00 }, 0, 2);
                string txt = "";
                if (frameUnit.WaitData(2000))
                {
                    frameLength = frameUnit.ReadTotalData(frameData, frameData.Length);

                    if (frameData[4] == 0x77) //返回成功
                    {
                        txt = "版本:" + frameData[6] + "." + frameData[7] + " 日期:" + frameData[8] + "月" + frameData[9] + "日";
                    }
                }
                ShowVersion(txt);
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrameUnit(frameUnit);
            }
        }
Exemple #2
0
        private void ShowProc()
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(dataBuffer, -1); //接收任何数据帧

            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);

                    sb.Length = 0;
                    for (int i = 0; i < frameUnit.FrameLength; i++)
                    {
                        sb.Append(dataBuffer[i].ToString("X2") + " ");
                    }
                    sb.Append("\r\n");

                    ShowResult(sb.ToString());
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #3
0
        /// <summary>
        /// 开入板报警数据
        /// </summary>
        private void ProcKRBWarning()
        {
            byte[]    frameData = new byte[16];
            FrameUnit frameUnit = FrameManager.CreateFrame(frameData, 0x40);

            try
            {
                while (true)
                {
                    if (warningTime < 0)
                    {
                        frameUnit.WaitData(-1);
                    }
                    else
                    {
                        Thread.Sleep(warningTime);
                    }

                    FrameTransmit.Send(boardAddr, 1, 0x40, ChannelData1, DataCount1);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
            }
        }
Exemple #4
0
        /// <summary>
        /// 应答参数设置
        /// </summary>
        private void ProcResponseParam()
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(frameBuffer1, 0x01);

            byte[] data = new byte[4];
            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);
                    data[0] = frameBuffer1[7];
                    data[1] = frameBuffer1[8];
                    data[2] = (byte)(boardType);
                    data[3] = (byte)(paramResponse);
                    Thread.Sleep(100);
                    FrameTransmit.Send(boardAddr, 1, 1, data, 4);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #5
0
        private void btnReadDReg_Click(object sender, EventArgs e)
        {
            Int16         addr;
            StringBuilder sb = new StringBuilder();

            byte[]    rxBuf     = new byte[1000];
            FrameUnit frameUnit = FrameManager.CreateFrame(rxBuf, 0xf0); //接收任何数据帧

            try
            {
                boardAddress1 = byte.Parse(textBoxBoardAddr.Text);
                addr          = Int16.Parse(txtDebugRegAddr.Text, System.Globalization.NumberStyles.HexNumber);
                byte[] buffer = new byte[3];
                buffer[0] = (byte)(addr & 0xff);
                buffer[1] = (byte)(addr >> 8);
                Protocol.FrameTransmit.Send(1, boardAddress1, 0xf0, buffer, 2);
                if (frameUnit.WaitData(3000) == false)
                {
                    MessageBox.Show("收不到数据");
                }
                else
                {
                    ShowText(txtDebugRegVal, (rxBuf[9] + rxBuf[10] * 256).ToString("X2"));
                }
            }
            catch
            {
                MessageBox.Show("数字非法");
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #6
0
        private void ProcStartSend(object obj)
        {
            int       index     = (int)obj;
            FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x03);

            byte[] frameData   = new byte[20];
            int    frameLength = 0;

            try
            {
                SerialManager.Send(new byte[] { 0x18, 0x01 }, 0, 2);
                Thread.Sleep(500);

                SerialManager.Send(new byte[] { 0x03, (byte)(index + 1) }, 0, 2);
                string txt = "";
                if (frameUnit.WaitData(15000))
                {
                    frameLength = frameUnit.ReadTotalData(frameData, frameData.Length);

                    if (frameData[7] == 0x81) //返回成功
                    {
                    }
                }
                ShowSendEnd(txt);
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrameUnit(frameUnit);
            }
        }
Exemple #7
0
        /// <summary>
        /// 应答固件升级
        /// </summary>
        private void ProcResponseFirmware()
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(frameBuffer2, 0x02);

            byte[] data = new byte[4];
            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);
                    data[0] = frameBuffer2[7];
                    data[1] = frameBuffer2[8];
                    data[2] = frameBuffer2[9];// (byte)(boardType);
                    data[3] = (byte)(firmwareResponse);

                    FrameTransmit.Send(boardAddr, 1, 0x02, data, 4);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #8
0
        private void ThreadRdMessage()
        {
            Int16         addr;
            StringBuilder sb = new StringBuilder();

            byte[]    rxBuf     = new byte[1000];
            FrameUnit frameUnit = FrameManager.CreateFrame(rxBuf, 0xf0);

            byte[]   txBuf       = new byte[4];
            bool     isOk        = true;
            Encoding myEencoding = Encoding.GetEncoding(936);

            try
            {
                boardAddress1 = byte.Parse(textBoxBoardAddr.Text);
                addr          = 0x0100;
                for (int i = 0; i < 255; i++)
                {
                    addr     = (Int16)(0x100 + i);
                    txBuf[0] = (byte)(addr & 0xff);
                    txBuf[1] = (byte)(addr >> 0x8);
                    Protocol.FrameTransmit.Send(1, boardAddress1, 0xf0, txBuf, 2);
                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("等待超时");
                        isOk = false;
                        break;
                    }
                    else
                    {
                        ShowProgress(pgbWriteMessage, (int)(i * 100 / 255));
                        if (rxBuf[9] == 0x00)
                        {
                            break;
                        }
                        sb.Append((char)rxBuf[9]);

                        if (rxBuf[10] == 0x00)
                        {
                            break;
                        }
                        sb.Append((char)rxBuf[10]);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (isOk)
                {
                    MessageBox.Show("已读出");
                }
                ShowText(btnRdMessage, "读出");
                ShowText(txtMessage, sb.ToString());
            }
        }
Exemple #9
0
        private void ScanProc()
        {
            StringBuilder sb        = new StringBuilder();
            FrameUnit     frameUnit = FrameManager.CreateFrame(dataBuffer, 0x30);

            try
            {
                byte[] buffer = new byte[1];
                buffer[0] = channelNo;

                while (true)
                {
                    Protocol.FrameTransmit.Send(1, boardAddress, 0x30, buffer, 1);

                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("收不到数据");

                        // byte[] buffer1 = new byte[1];
                        // Protocol.FrameTransmit.Send(1, boardAddress, 6, buffer1, 0);

                        ShowText(btnStartTest, "开始测试");
                        break;
                    }
                    else
                    {
                        sb.Length = 0;

                        for (int i = 8; i < frameUnit.FrameLength - 4; i += 2)
                        {
                            Int16 chVal;
                            chVal = (Int16)(dataBuffer[i] + dataBuffer[i + 1] * 256);
                            sb.Append("通道" + ((i - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");
                            sb.Append("\r\n");
                        }

                        ShowText(textBox_testMessage, sb.ToString());
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #10
0
        private bool WriteReg(int boardAddr, UInt16 regAddr, UInt16 val)
        {
            bool ret;

            byte[]    rxBuf     = new byte[1000];
            FrameUnit frameUnit = FrameManager.CreateFrame(rxBuf, 0xf1);

            try
            {
                byte[] buffer = new byte[4];



                buffer[0] = (byte)(regAddr & 0xff);
                buffer[1] = (byte)(regAddr >> 8);
                buffer[2] = (byte)(val & 0xff);
                buffer[3] = (byte)(val >> 8);
                Protocol.FrameTransmit.Send(1, boardAddr, 0xf1, buffer, 4);

                if (frameUnit.WaitData(3000) == false)
                {
                    ret = false;
                }
                else
                {
                    UInt16 temp;
                    temp = (UInt16)((UInt16)rxBuf[9] + (UInt16)(rxBuf[10] * 256));
                    if (temp == val)
                    {
                        ret = true;
                    }
                    else
                    {
                        ret = false;
                    }
                }
            }
            catch
            {
                ret = false;
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
            return(ret);
        }
        /// <summary>
        /// 开关板采集
        /// </summary>


        private void ProcMR()
        {
            StringBuilder sb        = new StringBuilder();
            FrameUnit     frameUnit = FrameManager.CreateFrame(dataBuffer, 0x30);

            try
            {
                byte[] buffer = new byte[1];
                buffer[0] = MRChannel;

                while (true)
                {
                    Protocol.FrameTransmit.Send(srcAddr, boardAddress1, 0x30, buffer, 1);
                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("收不到数据");
                        ShowText(buttonMR, "开始采集");
                        break;
                    }
                    else
                    {
                        sb.Length = 0;
                        for (int i = 8; i < frameUnit.FrameLength - 4; i += 2)
                        {
                            Int16 chVal;
                            chVal = (Int16)((dataBuffer[i] + dataBuffer[i + 1] * 256) & 0x7fff);
                            sb.Append("通道" + ((i - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");
                            sb.Append("\r\n");
                        }



                        ShowText(txtChVal, sb.ToString());
                    }
                    Thread.Sleep(MRInternal);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #12
0
        private void btnWriteDReg_Click(object sender, EventArgs e)
        {
            UInt16        addr, val;
            StringBuilder sb = new StringBuilder();

            byte[]    rxBuf     = new byte[1000];
            FrameUnit frameUnit = FrameManager.CreateFrame(rxBuf, 0xf1);

            try
            {
                boardAddress1 = byte.Parse(textBoxBoardAddr.Text);
                addr          = UInt16.Parse(txtDebugRegAddr.Text, System.Globalization.NumberStyles.HexNumber);
                val           = UInt16.Parse(txtDebugRegVal.Text, System.Globalization.NumberStyles.HexNumber);
                //   val &= 0xffff;
                byte[] buffer = new byte[4];
                buffer[0] = (byte)(addr & 0xff);
                buffer[1] = (byte)(addr >> 8);
                buffer[2] = (byte)(val & 0xff);
                buffer[3] = (byte)(val >> 8);
                Protocol.FrameTransmit.Send(1, boardAddress1, 0xf1, buffer, 4);
                if (frameUnit.WaitData(3000) == false)
                {
                    MessageBox.Show("收不到数据");
                }
                else
                {
                    UInt16 temp;
                    temp = (UInt16)((UInt16)rxBuf[9] + (UInt16)(rxBuf[10] * 256));
                    if (temp == val)
                    {
                        MessageBox.Show("写入成功");
                    }
                }
            }
            catch
            {
                MessageBox.Show("数字非法");
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #13
0
        private void ProcKRBSwitch()
        {
            byte[]    frameData = new byte[16];
            FrameUnit frameUnit = FrameManager.CreateFrame(frameData, cmdType);

            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);

                    FrameTransmit.Send(boardAddr, 1, cmdType, ChannelDataKRB, DataCountKRB + 1);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
        private bool ReadAnalogCh(byte ch, out Int16 val)
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(dataBuffer, 0x30); //接收任何数据帧
            bool      ret;

            boardAddress1 = byte.Parse(textBoxBoardAddr.Text);
            try
            {
                byte[] buffer = new byte[1];
                buffer[0] = ch;


                Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                if (frameUnit.WaitData(3000) == false)
                {
                    MessageBox.Show("收不到数据");
                    ShowText(buttonMR, "开始采集");
                    val = 0;
                    ret = false;
                }
                else
                {
                    val  = dataBuffer[9];
                    val *= 256;
                    val += dataBuffer[8];
                    ret  = true;
                }
            }
            catch (ThreadAbortException)
            {
                ret = false;
                val = 0;
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
            return(ret);
        }
        private void NewMethod()
        {
            boardTypeDetail = comboBox1.SelectedIndex + 1;
            boardAddress    = byte.Parse(textBoxBoardAddr.Text);
            byte[] buffer = new byte[1];
            buffer[0] = (byte)boardTypeDetail;
            Protocol.FrameTransmit.Send(1, boardAddress, 7, buffer, 1);
            StringBuilder sb = new StringBuilder();

            byte[]    dataBuffer = new byte[40];
            FrameUnit frameUnit  = FrameManager.CreateFrame(dataBuffer, 0x07);

            if (frameUnit.WaitData(2000) == false)
            {
                MessageBox.Show("查询失败");
            }
            else
            {
                MessageBox.Show("版本号:" + dataBuffer[7].ToString() + "." + dataBuffer[8].ToString() + "\r\n"
                                + "版本日期:" + dataBuffer[9].ToString() + "年" + dataBuffer[10].ToString() + "月" + dataBuffer[11].ToString());
            }
        }
Exemple #16
0
        private void ProcMR()
        {
            byte[]        dataBuffer = new byte[2048];
            StringBuilder sb         = new StringBuilder();
            FrameUnit     frameUnit  = FrameManager.CreateFrame(dataBuffer, 0x30);

            try
            {
                while (true)
                {
                    if (frameUnit.WaitData(3000) == false)
                    {
                        ShowText(txtAnalog, "");
                    }
                    else
                    {
                        sb.Length = 0;
                        for (int i = 8; i < frameUnit.FrameLength - 4; i += 2)
                        {
                            Int16 chVal;
                            chVal = (Int16)(dataBuffer[i] + dataBuffer[i + 1] * 256);
                            sb.Append("═ех└" + ((i - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");
                            sb.Append("\r\n");
                        }



                        ShowText(txtAnalog, sb.ToString());
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #17
0
        private void ProcBoardStatus()
        {
            byte[]    frameData = new byte[16];
            FrameUnit frameUnit = FrameManager.CreateFrame(frameData, 0x10);

            byte[] data = new byte[1];
            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);
                    data[0] = (byte)boardStatus;
                    FrameTransmit.Send(boardAddr, 1, 0x10, data, 1);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #18
0
        private void ProcUpdateStatus()
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(frameBuffer3, 0x03);

            byte[] data = new byte[1];
            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);
                    data[0] = (byte)updateStatus;

                    FrameTransmit.Send(boardAddr, 1, 0x03, data, 1);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #19
0
        private void ProcVersion()
        {
            byte[]    frameData = new byte[16];
            FrameUnit frameUnit = FrameManager.CreateFrame(frameData, 0x07);

            byte[] data = new byte[2];
            try
            {
                while (true)
                {
                    frameUnit.WaitData(-1);
                    data[0] = (byte)version1;
                    data[1] = (byte)version2;
                    FrameTransmit.Send(boardAddr, 1, 0x07, data, 2);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
        private void ProcScan()
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sbLog = new StringBuilder();
            StringBuilder sbAll = new StringBuilder();
            FrameUnit     frameUnit = FrameManager.CreateFrame(dataBuffer, 0x30); //接收任何数据帧
            float         maxAmpliVal, minAmpliVal;
            float         maxFreqVal, minFreqVal;
            float         maxModFreqVal, minModFreqVal;



            Lon.IO.Ports.FunGen fGen = new Lon.IO.Ports.FunGen();

            try
            {
                byte[] buffer = new byte[1];
                buffer[0] = MRChannel;
                float tempVal;

                for (int i = 0; i < ((float)(numScanEnd.Value) - (float)(numScanStart.Value) + 0.1f) * 10; i++)
                {
                    while (fGen.SetFmFreq(0, (float)numScanStart.Value + i * 0.1f) == false)
                    {
                        MessageBox.Show("3022未准备好");
                    }

                    sbLog.Length = 0;
                    sbLog.Append("!!!!!!!!!");
                    sbLog.Append(DateTime.Now.ToLongTimeString());
                    sbLog.Append("    3022输出低频:");
                    sbLog.Append(((float)numScanStart.Value + i * 0.1f).ToString());
                    sbLog.Append("//{{{1\r\n");
                    AppendText(txtLog, sbLog.ToString());
                    Thread.Sleep(1000);


                    Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("收不到数据");
                        ShowText(btnLowScan, "开始扫描");
                        break;
                    }
                    else
                    {
                        sb.Length = 0;
                        for (int k = 8; k < frameUnit.FrameLength - 4; k += 2)
                        {
                            float chVal;
                            chVal = dataBuffer[k] + dataBuffer[k + 1] * 256;
                            sb.Append("通道" + ((k - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");

                            sb.Append("\r\n");
                        }
                        ShowText(txtVal, sb.ToString());
                        sbAll.Append(DateTime.Now.ToLongTimeString());
                        sbAll.Append(":\r\n");
                        sbAll.Append(sb.ToString());
                        sbAll.Append(":\r\n");

                        sbLog.Length = 0;
                        sbLog.Append("时间\t电压\t频率\t低频//{{{2\r\n");
                        sbLog.Append(DateTime.Now.ToLongTimeString());
                        sbLog.Append("\t");
                        tempVal     = dataBuffer[8 + (int)numScanCh.Value * 2] + dataBuffer[9 + (int)numScanCh.Value * 2] * 256;
                        maxAmpliVal = tempVal;
                        minAmpliVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\t");
                        tempVal    = dataBuffer[10 + (int)numScanCh.Value * 2] + dataBuffer[11 + (int)numScanCh.Value * 2] * 256;
                        maxFreqVal = tempVal;
                        minFreqVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\t");
                        tempVal       = dataBuffer[12 + (int)numScanCh.Value * 2] + dataBuffer[13 + (int)numScanCh.Value * 2] * 256;
                        maxModFreqVal = tempVal;
                        minModFreqVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\r\n");
                        AppendText(txtLog, sbLog.ToString());
                    }
                    #region 开始采集

                    for (int j = 0; j < (int)(numTstTime.Value * 60); j++)
                    {
                        Thread.Sleep(1000);
                        Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                        if (frameUnit.WaitData(30) == false)
                        {
                            MessageBox.Show("收不到数据");
                            ShowText(btnLowScan, "开始扫描");
                            break;
                        }
                        else
                        {
                            sb.Length = 0;
                            for (int k = 8; k < frameUnit.FrameLength - 4; k += 2)
                            {
                                float chVal;
                                chVal = dataBuffer[k] + dataBuffer[k + 1] * 256;
                                sb.Append("通道" + ((k - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");
                                sb.Append("\r\n");
                            }
                            ShowText(txtVal, sb.ToString());
                            sbAll.Append(DateTime.Now.ToLongTimeString());
                            sbAll.Append(":\r\n");
                            sbAll.Append(sb.ToString());
                            sbAll.Append(":\r\n");

                            sbLog.Length = 0;

                            sbLog.Append(DateTime.Now.ToLongTimeString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[8 + (int)numScanCh.Value * 2] + dataBuffer[9 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxAmpliVal)
                            {
                                maxAmpliVal = tempVal;
                            }
                            if (tempVal < maxAmpliVal)
                            {
                                minAmpliVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[10 + (int)numScanCh.Value * 2] + dataBuffer[11 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxFreqVal)
                            {
                                maxFreqVal = tempVal;
                            }
                            if (tempVal < minFreqVal)
                            {
                                minFreqVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[12 + (int)numScanCh.Value * 2] + dataBuffer[13 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxModFreqVal)
                            {
                                maxModFreqVal = tempVal;
                            }
                            if (tempVal < minModFreqVal)
                            {
                                minModFreqVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\r\n");
                            AppendText(txtLog, sbLog.ToString());
                        }
                    }
                    #endregion

                    sbLog.Length = 0;
                    sbLog.Append("//}}}2\r\n");
                    sbLog.Append("!!!!!!!!!");
                    sbLog.Append(DateTime.Now.ToLongTimeString());
                    sbLog.Append("    3022测试低频结束\r\n");
                    sbLog.Append("!!!!!!!!!幅度最大值:");
                    sbLog.Append(maxAmpliVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!幅度最小值:");
                    sbLog.Append(minAmpliVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!频率最大值:");
                    sbLog.Append(maxFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!频率最小值:");
                    sbLog.Append(minFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!调制频率最大值:");
                    sbLog.Append(maxModFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!调制频率最小值:");
                    sbLog.Append(minModFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append(((float)numScanStart.Value + i * 0.1f).ToString());
                    sbLog.Append("//}}}1\r\n");
                    AppendText(txtLog, sbLog.ToString());
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
        private void ProcUpDate()
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(dataBuffer, 2);

            try
            {
                using (FileStream fs = new FileStream(firmware, FileMode.Open))
                {
                    long   length    = fs.Length;
                    long   totalLeng = length;
                    byte[] buffer    = null;
                    int    limit     = 0;
                    if (boardTypeDetail <= 2)
                    {
                        limit  = 80;
                        buffer = new byte[limit + 7];
                    }
                    else if (boardTypeDetail <= 4)
                    {
                        limit  = 8192;
                        buffer = new byte[limit + 7];
                    }
                    else if (boardTypeDetail == 9)
                    {
                        limit  = 1024;
                        buffer = new byte[limit + 7];
                    }
                    else if (boardTypeDetail == 13)
                    {
                        limit  = 512;
                        buffer = new byte[limit + 7];
                    }
                    else if (boardTypeDetail == 14)
                    {
                        limit  = 512;
                        buffer = new byte[limit + 7];
                    }
                    else if (boardTypeDetail == 16)
                    {
                        limit  = 512;
                        buffer = new byte[limit + 7];
                    }
                    else
                    {
                        limit  = lenTable[boardTypeDetail];
                        buffer = new byte[limit + 7];
                    }
                    int startIndex = 0;
                    while (length > 0)
                    {
                        if (length > limit)
                        {
                            fs.Read(buffer, 5, limit);
                            length   -= limit;
                            buffer[0] = (byte)(startIndex & 0xff);
                            buffer[1] = (byte)((startIndex >> 8) & 0xff);
                            startIndex++;
                            if (isApp)
                            {
                                buffer[2] = (byte)(boardTypeDetail + 0x80);
                            }
                            else
                            {
                                buffer[2] = (byte)(boardTypeDetail);
                            }
                            buffer[3] = majorNum;
                            buffer[4] = minorNum;
                            ushort crc = Helper.CRC16.ComputeCRC16(buffer, 0, limit + 5);
                            buffer[limit + 5] = (byte)(crc & 0xff);
                            buffer[limit + 6] = (byte)((crc >> 8) & 0xff);

                            Protocol.FrameTransmit.Send(srcAddr, boardAddress, 2, buffer, limit + 7);
                            ShowProcess(1 - (length * 1.0f / totalLeng));
                            //Thread.Sleep(50);
                            //等待功能板响应
                            frameUnit.WaitData(-1);
                        }
                        else
                        {
                            int rdLen = fs.Read(buffer, 5, limit);
                            length   -= rdLen;
                            buffer[0] = (byte)(startIndex & 0xff);
                            buffer[1] = (byte)((startIndex >> 8) & 0xff | 0x80);
                            startIndex++;
                            buffer[2] = (byte)boardTypeDetail;
                            buffer[3] = majorNum;
                            buffer[4] = minorNum;
                            ushort crc = Helper.CRC16.ComputeCRC16(buffer, 0, rdLen + 5);
                            buffer[rdLen + 5] = (byte)(crc & 0xff);
                            buffer[rdLen + 6] = (byte)((crc >> 8) & 0xff);

                            Protocol.FrameTransmit.Send(srcAddr, boardAddress, 2, buffer, rdLen + 7);
                            ShowProcess(1 - (length * 1.0f / totalLeng));
                            frameUnit.WaitData(-1);
                        }
                    }
                    fs.Close();
                }
                ShowProcess(-1);
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
        private void ProcSend()
        {
            FrameUnit frameUnit = FrameManager.CreateFrame(dataBuffer, 1);

            try
            {
                if (paramLength > 0)
                {
                    int startIndex = 0;
                    while (paramLength > 0)
                    {
                        if (paramLength > LimitValue)
                        {
                            frameBuffer[0] = (byte)(startIndex & 0xff);
                            frameBuffer[1] = (byte)((startIndex >> 8) & 0xff); //帧序号
                            frameBuffer[2] = paramValue[1];
                            frameBuffer[3] = 0;
                            frameBuffer[4] = 0;
                            for (int i = 0; i < LimitValue; i++)
                            {
                                frameBuffer[5 + i] = paramValue[startIndex * LimitValue + i];
                            }
                            ushort crc = Helper.CRC16.ComputeCRC16(frameBuffer, 0, LimitValue + 5);
                            frameBuffer[LimitValue + 5] = (byte)(crc & 0xff);
                            frameBuffer[LimitValue + 6] = (byte)((crc >> 8) & 0xff);
                            //CPU板地址为1
                            Protocol.FrameTransmit.Send(1, paramValue[0], 0x01, frameBuffer, LimitValue + 7);
                            startIndex++;
                            frameUnit.WaitData(500);
                        }
                        else
                        {
                            frameBuffer[0] = (byte)(startIndex & 0xff);
                            frameBuffer[1] = (byte)(((startIndex >> 8) & 0xff) | 0x80); //帧序号,bit15为1代表最后一帧
                            frameBuffer[2] = paramValue[1];
                            frameBuffer[3] = 0;
                            frameBuffer[4] = 0;
                            for (int i = 0; i < paramLength; i++)
                            {
                                frameBuffer[5 + i] = paramValue[startIndex * LimitValue + i];
                            }
                            ushort crc = Helper.CRC16.ComputeCRC16(frameBuffer, 0, paramLength + 5);
                            frameBuffer[paramLength + 5] = (byte)(crc & 0xff);
                            frameBuffer[paramLength + 6] = (byte)((crc >> 8) & 0xff);
                            //CPU板地址为1
                            Protocol.FrameTransmit.Send(1, paramValue[0], 0x01, frameBuffer, paramLength + 7);
                            //发送完毕
                            startIndex++;
                            frameUnit.WaitData(500);
                        }
                        paramLength -= LimitValue;
                    }
                }
                else
                {
                    frameBuffer[0] = (byte)(0 & 0xff);
                    frameBuffer[1] = (byte)(((0 >> 8) & 0xff) | 0x80); //帧序号,bit15为1代表最后一帧
                    frameBuffer[2] = paramValue[1];
                    frameBuffer[3] = 0;
                    frameBuffer[4] = 0;
                    frameBuffer[5] = paramValue[0];
                    frameBuffer[6] = paramValue[1];
                    ushort crc = Helper.CRC16.ComputeCRC16(frameBuffer, 0, 7);
                    frameBuffer[7] = (byte)(crc & 0xff);
                    frameBuffer[8] = (byte)((crc >> 8) & 0xff);
                    Protocol.FrameTransmit.Send(1, paramValue[0], 0x01, frameBuffer, 9);
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #23
0
        private void ThreadWrMessage()
        {
            Int16         addr;
            StringBuilder sb = new StringBuilder();

            byte[]    rxBuf     = new byte[1000];
            FrameUnit frameUnit = FrameManager.CreateFrame(rxBuf, 0xf1); //接收任何数据帧

            byte[] txBuf = new byte[4];
            bool   isOk  = true;

            try
            {
                boardAddress1 = byte.Parse(textBoxBoardAddr.Text);
                addr          = 0x0100;
                for (int i = 0; i * 2 < (txtMessage.Text.Length + 1) && i < 0x255; i++)
                {
                    addr     = (Int16)(0x100 + i);
                    txBuf[0] = (byte)(addr & 0xff);
                    txBuf[1] = (byte)(addr >> 0x8);

                    if (i * 2 + 1 < txtMessage.Text.Length)
                    {
                        txBuf[2] = (byte)(txtMessage.Text[i * 2]);
                        txBuf[3] = (byte)(txtMessage.Text[i * 2 + 1]);
                    }
                    else
                    {
                        if (i * 2 == txtMessage.Text.Length)
                        {
                            txBuf[2] = (byte)0x00;
                            txBuf[3] = (byte)0x00;
                        }
                        else
                        {
                            txBuf[2] = (byte)(txtMessage.Text[i * 2]);
                            txBuf[3] = (byte)0x00;
                        }
                    }

                    Protocol.FrameTransmit.Send(1, boardAddress1, 0xf1, txBuf, 4);

                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("等待超时");
                        isOk = false;
                        break;
                    }
                    else
                    {
                        ShowProgress(pgbWriteMessage, (int)((i / txtMessage.Text.Length) * 100));
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (isOk)
                {
                    MessageBox.Show("写入完成");
                }
                ShowText(btnWriteMessage, "写入");
            }
        }
Exemple #24
0
        private void ProcWriteParam(object obj)
        {
            int index = (int)obj;

            int[]  fieldVal = new int[13];
            byte[] bitArray = new byte[12 * 8];

            byte[] byteArray = new byte[12];

            byte[]    dataSend  = new byte[3 + 12];
            FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x14);

            byte[] frameData = new byte[100];
            try
            {
                for (int i = 0; i < 3; i++)
                {
                    switch (tablePSD[index].Rows[i]["TrainState"].ToString())
                    {
                    case "L":
                        fieldVal[0] = 0x1c;
                        break;

                    case "G":
                        fieldVal[0] = 0x26;
                        break;

                    case "R":
                        fieldVal[0] = 0x52;
                        break;

                    default:
                        fieldVal[0] = 0x1c;
                        break;
                    }
                    fieldVal[1] = int.Parse(tablePSD[index].Rows[i]["FZK"].ToString());
                    fieldVal[2] = (int)tablePSD[index].Rows[i]["Crew"];
                    int trip = (int)tablePSD[index].Rows[i]["Trip"];

                    fieldVal[3] = trip % 1000;
                    fieldVal[4] = (int)tablePSD[index].Rows[i]["Dst"];
                    fieldVal[5] = trip / 1000;
                    fieldVal[6] = int.Parse(tablePSD[index].Rows[i]["Res"].ToString());
                    switch (tablePSD[index].Rows[i]["Dir"].ToString())
                    {
                    case "A":
                        fieldVal[7] = 1;
                        break;

                    case "B":
                        fieldVal[7] = 2;
                        break;

                    case "AB":
                        fieldVal[7] = 3;
                        break;

                    case "EAB":
                        fieldVal[7] = 0;
                        break;

                    default:
                        fieldVal[7] = 2;
                        break;
                    }
                    fieldVal[8]  = int.Parse(tablePSD[index].Rows[i]["Err"].ToString());
                    fieldVal[9]  = (int)tablePSD[index].Rows[i]["CarID"];
                    fieldVal[10] = (int)tablePSD[index].Rows[i]["ErrInf"];
                    fieldVal[11] = (int)tablePSD[index].Rows[i]["Mil"];
                    fieldVal[12] = int.Parse(tablePSD[index].Rows[i]["TelID"].ToString());

                    Tool.Field2BitArray(bitArray, fieldVal);

                    Tool.BitArray2ByteArray(bitArray, byteArray);

                    byteArray[11] = CRC8.ComputeCRC8(byteArray, 11, CRC8.CRCExpress);


                    dataSend[0] = 0x14;
                    dataSend[1] = (byte)(((index + 1) << 4) + (i + 1));
                    dataSend[2] = 0x60;
                    Array.Copy(byteArray, 0, dataSend, 3, 12);

                    SerialManager.Send(dataSend, 0, dataSend.Length);

                    if (frameUnit.WaitData(1000))
                    {
                    }
                }

                ShowWriteParamDone("");
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
            }
        }
Exemple #25
0
        private void ProcReadParam(object obj)
        {
            int       index     = (int)obj;
            FrameUnit frameUnit = FrameManager.CreateFrameUnit(0x24);

            byte[] frameData   = new byte[50];
            int    frameLength = 0;

            byte[] bitArray = new byte[12 * 8];


            try
            {
                for (int i = 0; i < 3; i++)
                {
                    SerialManager.Send(new byte[] { 0x24, (byte)(((index + 1) << 4) + (i + 1)) }, 0, 2);

                    if (frameUnit.WaitData(2000))
                    {
                        frameLength = frameUnit.ReadTotalData(frameData, frameData.Length);
                        if (frameData[4] == 0x77) //查询成功
                        {
                            //显示数据
                            if (frameData[7] == 0x60) //12*8Bit
                            {
                                Tool.ByteArray2BitArray(bitArray, frameData, 8, 12);

                                int state = Tool.FieldValue(bitArray, 0);
                                switch (state)
                                {
                                case 0x1c:
                                    tablePSD[index].Rows[i]["TrainState"] = "L";
                                    break;

                                case 0x26:
                                    tablePSD[index].Rows[i]["TrainState"] = "G";
                                    break;

                                case 0x52:
                                    tablePSD[index].Rows[i]["TrainState"] = "R";
                                    break;

                                default:
                                    tablePSD[index].Rows[i]["TrainState"] = "--";
                                    break;
                                }

                                int fzk = Tool.FieldValue(bitArray, 1);
                                tablePSD[index].Rows[i]["FZK"] = fzk.ToString();

                                int crew = Tool.FieldValue(bitArray, 2);

                                tablePSD[index].Rows[i]["Crew"] = crew;

                                int trip = Tool.FieldValue(bitArray, 3) + Tool.FieldValue(bitArray, 5) * 1000;
                                tablePSD[index].Rows[i]["Trip"] = trip;

                                int dst = Tool.FieldValue(bitArray, 4);
                                tablePSD[index].Rows[i]["Dst"] = dst;

                                int res = Tool.FieldValue(bitArray, 6);
                                tablePSD[index].Rows[i]["Res"] = res.ToString();

                                int dir = Tool.FieldValue(bitArray, 7);
                                switch (dir)
                                {
                                case 0:
                                    tablePSD[index].Rows[i]["Dir"] = "EAB";
                                    break;

                                case 1:
                                    tablePSD[index].Rows[i]["Dir"] = "A";
                                    break;

                                case 2:
                                    tablePSD[index].Rows[i]["Dir"] = "B";
                                    break;

                                case 3:
                                    tablePSD[index].Rows[i]["Dir"] = "AB";
                                    break;
                                }


                                int err = Tool.FieldValue(bitArray, 8);
                                tablePSD[index].Rows[i]["Err"] = err.ToString();

                                int carId = Tool.FieldValue(bitArray, 9);
                                tablePSD[index].Rows[i]["CarID"] = carId;

                                int inf = Tool.FieldValue(bitArray, 10);
                                tablePSD[index].Rows[i]["ErrInf"] = inf;

                                int mil = Tool.FieldValue(bitArray, 11);
                                tablePSD[index].Rows[i]["Mil"] = mil;

                                int tel = Tool.FieldValue(bitArray, 12);
                                tablePSD[index].Rows[i]["TelID"] = tel.ToString();
                            }
                        }
                    }
                }
                ShowReadParamDone("");
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
            }
        }