/// <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); } }
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); } }
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); } }
/// <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); } }
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); } }
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); } }
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); } }
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 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); } }
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 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); } }
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); } }
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 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 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 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); } }