20231023_InSituLab_emb/InsituLabProject_MoniBase/BaseStation/Form1.cs
2025-05-07 10:10:07 +08:00

646 lines
40 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Globalization;
using System.IO;
namespace BaseStation
{
public partial class BaseStation : Form
{
private Socket gs_udpSocket;
private Thread gs_udpThread;
private Thread gs_timeSyncThread;
private byte udpInitFlag = 0;
private IPEndPoint gs_recvIPEndPoint;
private IPEndPoint gs_sendIPEndPoint;
private Mutex gs_mutex;
private readonly byte[] restartBuff = {0xAA, 0xBB, 0x01, 0x00, 0x18, 0x41, 0x40, 0x00, 0x02, 0x7F, 0x93, 0x00, 0x10, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x65, 0x7F, 0xEC, 0xEE, 0xFF};
public BaseStation()
{
InitializeComponent();
}
private void Restart_Btn_Click(object sender, EventArgs e)
{
Restart_TXTBOX.Text = BitConverter.ToString(restartBuff).Replace('-', ' ');
}
private void BaseStation_Load(object sender, EventArgs e)
{
gs_mutex = new Mutex(false);
gs_recvIPEndPoint = new IPEndPoint(IPAddress.Any, 20004);
gs_sendIPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.4.230"), 55000);
gs_udpSocket = new Socket(SocketType.Dgram, ProtocolType.Udp);
gs_udpSocket.Bind(gs_recvIPEndPoint);
udpInitFlag = 1;
/* 创建一个UDP */
gs_udpThread = new Thread(UdpToMctrlRecvTask);
gs_udpThread.Start();
/* 创建一个定时任务 */
gs_timeSyncThread = new Thread(UdpToMctrlSyncTime);
gs_timeSyncThread.Start();
}
/* 数据接收函数*/
private void UdpToMctrlRecvTask()
{
byte[] recvBuffer = new byte[1024];
byte[] sendBuffer = new byte[128];
int rt;
UInt32 messageId = 0;
try {
while (true) {
rt = gs_udpSocket.Receive(recvBuffer, 1024, 0);
if (0 >= rt) {
continue;
}
this.Invoke(new MethodInvoker(() =>
{
RecvBox.AppendText(DateTime.Now.ToString() + " : " + BitConverter.ToString(recvBuffer, 0, rt).Replace('-', ' ') + "\r\n");
}));
messageId = BitConverter.ToUInt32(recvBuffer, 5);
if (messageId == 0x03001040) { // 请求FTP传输
sendBuffer[0] = 0xAA;
sendBuffer[1] = 0xBB;
sendBuffer[2] = 0x01;
sendBuffer[3] = 0x00;
sendBuffer[4] = 0x12;
sendBuffer[5] = 0x10;
sendBuffer[6] = 0x40;
sendBuffer[7] = 0x00;
sendBuffer[8] = 0x03;
sendBuffer[9] = BufferXorCheck(sendBuffer, 9); // 校验码
sendBuffer[10] = 0xEE;
sendBuffer[11] = 0xFF;
UdpSendBuf(sendBuffer, 12);
continue;
}
if (messageId == 0x04001040) { // 请求关闭FTP传输
sendBuffer[0] = 0xAA;
sendBuffer[1] = 0xBB;
sendBuffer[2] = 0x01;
sendBuffer[3] = 0x00;
sendBuffer[4] = 0x12;
sendBuffer[5] = 0x10;
sendBuffer[6] = 0x40;
sendBuffer[7] = 0x00;
sendBuffer[8] = 0x04;
sendBuffer[9] = BufferXorCheck(sendBuffer, 9); // 校验码
sendBuffer[10] = 0xEE;
sendBuffer[11] = 0xFF;
UdpSendBuf(sendBuffer, 12);
continue;
}
if (messageId == 0x02001040) {
byte[] Bytetmp = new byte[4];
uint tmp_Uint32;
ushort tmp_Uint16;
int year;
int month;
int day;
int hour;
int minute;
int second;
float V48_V;
float V48_I;
uint masterSta_Leakage1; // 电能板1漏电流状态
uint masterSta_Leakage2; // 电能板2漏电流状态
uint masterSta_Leakage3; // 电能板3漏电流状态
uint masterSta_Leakage4; // 电能板4漏电流状态
uint masterSta_Temp1; // 主控内部温度1状态
uint masterSta_Temp2; // 主控内部温度2状态
uint masterSta_Humi1; // 主控内部湿度1状态
uint masterSta_Humi2; // 主控内部湿度2状态
uint masterSta_LeakWater1; // 主控内部漏水1状态
uint masterSta_LeakWater2; // 主控内部漏水2状态
uint masterSta_InsidePress1; // 主控内部腔体压力1状态
uint masterSta_InsidePress2; // 主控内部腔体压力2状态
uint downTimeSeqSta; // 时序下发状态
uint deviceDate_gcms; // 色质联用仪
uint deviceDate_serialPort1; // 备用串口1
uint deviceDate_serialPort2; // 备用串口2
uint deviceDate_osc; // 光纤,目前接的是基因测序仪
uint deviceDate_adcp; // ADCP
uint deviceDate_ctdo; // CTDO
uint deviceDate_vedio1; // 摄像1
uint deviceDate_ch4; // 甲烷
uint deviceDate_icl; // ICL
uint deviceDate_gc; // 色谱仪
uint deviceDate_co2; // 二氧化碳仪
uint deviceDate_raman; // 显微拉曼仪
uint deviceDate_ms; // 质谱仪
uint deviceDate_vedio2; // 摄像2
uint deviceDate_net; // 备用网口
uint deviceDate_acoustic; // 声学定位
uint breakdown_gcms; // 色质联用仪
uint breakdown_serialPort1; // 备用串口1
uint breakdown_serialPort2; // 备用串口2
uint breakdown_osc; // 光纤,目前接的是基因测序仪
uint breakdown_adcp; // ADCP
uint breakdown_ctdo; // CTDO
uint breakdown_vedio1; // 摄像1
uint breakdown_ch4; // 甲烷
uint breakdown_icl; // ICL
uint breakdown_gc; // 色谱仪
uint breakdown_co2; // 二氧化碳仪
uint breakdown_raman; // 显微拉曼仪
uint breakdown_ms; // 质谱仪
uint breakdown_vedio2; // 摄像2
uint breakdown_net; // 备用网口
uint breakdown_acoustic; // 声学定位
/* 色谱 */
uint cgdeviceTemp; // 设备温度状态
uint cgdeviceHumi; // 设备湿度状态
uint cgdevicePress; // 设备压力状态
uint cgdeviceInsulatio; // 设备故障状态
uint cgC2_concentration; // C2浓度
uint cgC3_concentration; // C3浓度
uint cgC4_concentration; // C4浓度
/* 质谱 */
uint msdeviceTemp; // 设备温度状态
uint msdeviceHumi; // 设备湿度状态
uint msdevicePress; // 设备压力状态
uint msdeviceInsulation; // 设备故障状态
uint msCH4_concentration; // 甲烷
uint msH2O_concentration; // 水
uint msN2_concentration; // N2浓度
uint msO2_concentration; // O2浓度
uint msAR_concentration; // N2浓度
uint msCO2_concentration; // CO2浓度
/* 色质联用仪 */
uint gcmsdeviceTemp; // 设备温度状态
uint gcmsdeviceHumi; // 设备湿度状态
uint gcmsdevicePress; // 设备压力状态
uint gcmsdeviceInsulation; // 设备故障状态
uint gcmsC2_concentration; // C2浓度
uint gcmsC3_concentration; // C3浓度
uint gcmsC4_concentration; // C4浓度
uint gcmsC5_concentration; // C5浓度
uint gcmsC6_concentration; // C6浓度
uint gcmsC7_concentration; // C7浓度
uint gcmsC8_concentration; // C8浓度
uint gcmsC9_concentration; // C9浓度
/* 甲烷 */
uint ch4deviceTemp; // 设备温度状态
uint ch4deviceHumi; // 设备湿度状态
uint ch4devicePress; // 设备压力状态
uint ch4deviceInsulation; // 设备故障状态
float ch4C12_concentration;
float ch4Abundance;
float ch4H2O_concentrations;
/* 二氧化碳 */
uint co2deviceTemp; // 设备温度状态
uint co2deviceHumi; // 设备湿度状态
uint co2devicePress; // 设备压力状态
uint co2deviceInsulation; // 设备故障状态
float co2LuminousIntensity; // 光强
float co2LaserTemperature; // 激光温度
float C12_concentration; // C12浓度
float co2Abundance; // 丰度
/* 拉曼 */
uint ramandeviceTemp; // 设备温度状态
uint ramandeviceHumi; // 设备湿度状态
uint ramandevicePress; // 设备压力状态
uint ramandeviceInsulation; // 设备故障状态
float ramanPM_num; // 颗粒物序号
float ramanPM_X; // 颗粒物横坐标
float ramanPM_Y; // 颗粒物纵坐标
float ramanPM_TYPE;// 颗粒物类型
float ramanPM_S; // 颗粒物面积
/* 基因测序仪 */
uint genedeviceTemp; // 设备温度状态
uint genedeviceHumi; // 设备湿度状态
uint genedevicePress; // 设备压力状态
uint genedeviceInsulation; // 设备故障状态
float geneReagentTemp; // 试剂温度
float geneSampleConcentration; // 样本浓度
byte geneworkflow; // 工作流程
/* 时间 */
year = recvBuffer[9] + 2000;
month = recvBuffer[10];
day = recvBuffer[11];
hour = recvBuffer[12];
minute = recvBuffer[13];
second = recvBuffer[14];
/* 电压电流 */
V48_V = BitConverter.ToSingle(recvBuffer, 21);
V48_I = BitConverter.ToSingle(recvBuffer, 25);
/* 主控状态 */
Bytetmp[0] = recvBuffer[29];
Bytetmp[1] = recvBuffer[30];
Bytetmp[2] = recvBuffer[31];
Bytetmp[3] = recvBuffer[32];
tmp_Uint32 = BitConverter.ToUInt32(Bytetmp, 0);
masterSta_Leakage1 = tmp_Uint32 & 0x3;
masterSta_Leakage2 = (tmp_Uint32 >> 2) & 0x3;
masterSta_Leakage3 = (tmp_Uint32 >> 4) & 0x3;
masterSta_Leakage4 = (tmp_Uint32 >> 6) & 0x3;
masterSta_Temp1 = (tmp_Uint32 >> 8) & 0x3;
masterSta_Temp2 = (tmp_Uint32 >> 10) & 0x3;
masterSta_Humi1 = (tmp_Uint32 >> 12) & 0x3;
masterSta_Humi2 = (tmp_Uint32 >> 14) & 0x3;
masterSta_LeakWater1 = (tmp_Uint32 >> 16) & 0x3;
masterSta_LeakWater2 = (tmp_Uint32 >> 18) & 0x3;
masterSta_InsidePress1 = (tmp_Uint32 >> 20) & 0x3;
masterSta_InsidePress2 = (tmp_Uint32 >> 22) & 0x3;
/* 时序下配状态 */
downTimeSeqSta = recvBuffer[33];
/* 设备输出状态 */
Bytetmp[0] = recvBuffer[34];
Bytetmp[1] = recvBuffer[35];
Bytetmp[2] = recvBuffer[36];
Bytetmp[3] = recvBuffer[37];
tmp_Uint32 = BitConverter.ToUInt32(Bytetmp, 0);
deviceDate_gcms = tmp_Uint32 & 0x1;
deviceDate_serialPort1 = (tmp_Uint32 >> 1) & 0x1;
deviceDate_serialPort2 = (tmp_Uint32 >> 2) & 0x1;
deviceDate_osc = (tmp_Uint32 >> 3) & 0x1;
deviceDate_adcp = (tmp_Uint32 >> 4) & 0x1;
deviceDate_ctdo = (tmp_Uint32 >> 5) & 0x1;
deviceDate_vedio1 = (tmp_Uint32 >> 6) & 0x1;
deviceDate_ch4 = (tmp_Uint32 >> 7) & 0x1;
deviceDate_icl = (tmp_Uint32 >> 8) & 0x1;
deviceDate_gc = (tmp_Uint32 >> 9) & 0x1;
deviceDate_co2 = (tmp_Uint32 >> 10) & 0x1;
deviceDate_raman = (tmp_Uint32 >> 11) & 0x1;
deviceDate_ms = (tmp_Uint32 >> 12) & 0x1;
deviceDate_vedio2 = (tmp_Uint32 >> 13) & 0x1;
deviceDate_net = (tmp_Uint32 >> 14) & 0x1;
deviceDate_acoustic = (tmp_Uint32 >> 15) & 0x1;
/* 设备故障信息 */
Bytetmp[0] = recvBuffer[38];
Bytetmp[1] = recvBuffer[39];
Bytetmp[2] = recvBuffer[40];
Bytetmp[3] = recvBuffer[41];
tmp_Uint32 = BitConverter.ToUInt32(Bytetmp, 0);
breakdown_gcms = tmp_Uint32 & 0x1;
breakdown_serialPort1 = (tmp_Uint32 >> 1) & 0x1;
breakdown_serialPort2 = (tmp_Uint32 >> 2) & 0x1;
breakdown_osc = (tmp_Uint32 >> 3) & 0x1;
breakdown_adcp = (tmp_Uint32 >> 4) & 0x1;
breakdown_ctdo = (tmp_Uint32 >> 5) & 0x1;
breakdown_vedio1 = (tmp_Uint32 >> 6) & 0x1;
breakdown_ch4 = (tmp_Uint32 >> 7) & 0x1;
breakdown_icl = (tmp_Uint32 >> 8) & 0x1;
breakdown_gc = (tmp_Uint32 >> 9) & 0x1;
breakdown_co2 = (tmp_Uint32 >> 10) & 0x1;
breakdown_raman = (tmp_Uint32 >> 11) & 0x1;
breakdown_ms = (tmp_Uint32 >> 12) & 0x1;
breakdown_vedio2 = (tmp_Uint32 >> 13) & 0x1;
breakdown_net = (tmp_Uint32 >> 14) & 0x1;
breakdown_acoustic = (tmp_Uint32 >> 15) & 0x1;
/* 色谱 */
Bytetmp[0] = recvBuffer[48];
Bytetmp[1] = recvBuffer[49];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
cgdeviceTemp = (uint)(tmp_Uint16 & 0x3);
cgdeviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
cgdevicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
cgdeviceInsulatio = (uint)((tmp_Uint16 >> 6) & 0x3);
Bytetmp[0] = recvBuffer[50];
Bytetmp[1] = recvBuffer[51];
cgC2_concentration = BitConverter.ToUInt16(Bytetmp, 0);// C2浓度
Bytetmp[0] = recvBuffer[52];
Bytetmp[1] = recvBuffer[53];
cgC3_concentration = BitConverter.ToUInt16(Bytetmp, 0); ; // C3浓度
Bytetmp[0] = recvBuffer[54];
Bytetmp[1] = recvBuffer[55];
cgC4_concentration = BitConverter.ToUInt16(Bytetmp, 0); ; // C4浓度
/* 质谱 */
Bytetmp[0] = recvBuffer[62];
Bytetmp[1] = recvBuffer[63];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
msdeviceTemp = (uint)(tmp_Uint16 & 0x3);
msdeviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
msdevicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
msdeviceInsulation = (uint)((tmp_Uint16 >> 6) & 0x3);
Bytetmp[0] = recvBuffer[64];
Bytetmp[1] = recvBuffer[65];
msCH4_concentration = BitConverter.ToUInt16(Bytetmp, 0);// 甲烷
Bytetmp[0] = recvBuffer[66];
Bytetmp[1] = recvBuffer[67];
msH2O_concentration = BitConverter.ToUInt16(Bytetmp, 0); ; // 水
Bytetmp[0] = recvBuffer[68];
Bytetmp[1] = recvBuffer[69];
msN2_concentration = BitConverter.ToUInt16(Bytetmp, 0); ; // 氮气
Bytetmp[0] = recvBuffer[70];
Bytetmp[1] = recvBuffer[71];
msO2_concentration = BitConverter.ToUInt16(Bytetmp, 0);// 氧气
Bytetmp[0] = recvBuffer[72];
Bytetmp[1] = recvBuffer[73];
msAR_concentration = BitConverter.ToUInt16(Bytetmp, 0); ; // 氩气
Bytetmp[0] = recvBuffer[74];
Bytetmp[1] = recvBuffer[75];
msCO2_concentration = BitConverter.ToUInt16(Bytetmp, 0); ; // 二氧化碳
/* 色质联用仪 */
Bytetmp[0] = recvBuffer[82];
Bytetmp[1] = recvBuffer[83];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
gcmsdeviceTemp = (uint)(tmp_Uint16 & 0x3);
gcmsdeviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
gcmsdevicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
gcmsdeviceInsulation = (uint)((tmp_Uint16 >> 6) & 0x3);
Bytetmp[0] = recvBuffer[84];
Bytetmp[1] = recvBuffer[85];
gcmsC2_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[86];
Bytetmp[1] = recvBuffer[87];
gcmsC3_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[88];
Bytetmp[1] = recvBuffer[89];
gcmsC4_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[90];
Bytetmp[1] = recvBuffer[91];
gcmsC5_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[92];
Bytetmp[1] = recvBuffer[93];
gcmsC6_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[94];
Bytetmp[1] = recvBuffer[95];
gcmsC7_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[96];
Bytetmp[1] = recvBuffer[97];
gcmsC8_concentration = BitConverter.ToUInt16(Bytetmp, 0);
Bytetmp[0] = recvBuffer[98];
Bytetmp[1] = recvBuffer[99];
gcmsC9_concentration = BitConverter.ToUInt16(Bytetmp, 0);
/* 甲烷 */
Bytetmp[0] = recvBuffer[106];
Bytetmp[1] = recvBuffer[107];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
ch4deviceTemp = (uint)(tmp_Uint16 & 0x3);
ch4deviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
ch4devicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
ch4deviceInsulation = (uint)((tmp_Uint16 >> 6) & 0x3);
ch4C12_concentration = BitConverter.ToSingle(recvBuffer, 108);
ch4Abundance = BitConverter.ToSingle(recvBuffer, 112);
ch4H2O_concentrations = BitConverter.ToSingle(recvBuffer, 116);
/* 二氧化碳 */
Bytetmp[0] = recvBuffer[126];
Bytetmp[1] = recvBuffer[127];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
co2deviceTemp = (uint)(tmp_Uint16 & 0x3);
co2deviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
co2devicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
co2deviceInsulation = (uint)((tmp_Uint16 >> 6) & 0x3);
co2LuminousIntensity = BitConverter.ToSingle(recvBuffer, 128); // 光强
co2LaserTemperature = BitConverter.ToSingle(recvBuffer, 132); // 激光温度
C12_concentration = BitConverter.ToSingle(recvBuffer, 136); // C12浓度
co2Abundance = BitConverter.ToSingle(recvBuffer, 140); // 丰度
/* 颗粒物分析物 */
Bytetmp[0] = recvBuffer[150];
Bytetmp[1] = recvBuffer[151];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
ramandeviceTemp = (uint)(tmp_Uint16 & 0x3);
ramandeviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
ramandevicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
ramandeviceInsulation = (uint)((tmp_Uint16 >> 6) & 0x3);
ramanPM_num = BitConverter.ToSingle(recvBuffer, 152); // 颗粒物序号
ramanPM_X = BitConverter.ToSingle(recvBuffer, 156); // 颗粒物横坐标
ramanPM_Y = BitConverter.ToSingle(recvBuffer, 160); // 颗粒物纵坐标
ramanPM_TYPE = BitConverter.ToSingle(recvBuffer, 164); // 颗粒物类型
ramanPM_S = BitConverter.ToSingle(recvBuffer, 168); // 颗粒物面积
/* 基因测序仪 */
Bytetmp[0] = recvBuffer[178];
Bytetmp[1] = recvBuffer[179];
tmp_Uint16 = BitConverter.ToUInt16(Bytetmp, 0);
genedeviceTemp = (uint)(tmp_Uint16 & 0x3);
genedeviceHumi = (uint)((tmp_Uint16 >> 2) & 0x3);
genedevicePress = (uint)((tmp_Uint16 >> 4) & 0x3);
genedeviceInsulation = (uint)((tmp_Uint16 >> 6) & 0x3);
geneReagentTemp = BitConverter.ToSingle(recvBuffer, 180); // 试剂温度
geneSampleConcentration = BitConverter.ToSingle(recvBuffer, 184); // 样本浓度
geneworkflow = recvBuffer[188]; // 工作流程
/* 拼成一个string包 */
string data_display = "********************一条数据*************\r\n" +
"time: " + year.ToString()+"年" + month.ToString()+"月" + day.ToString()+"日" + hour.ToString()+"时" + minute.ToString()+"分" + second.ToString()+"秒" + "\r\n" +
"V48_V: " + (V48_V*21/1000).ToString() + "\r\n" +
"V48_I: " + (V48_I/1000).ToString() + "\r\n" +
"/**** 主控状态 ***/\r\n" +
"masterSta_Leakage1: " + masterSta_Leakage1.ToString() + "\r\n" +
"masterSta_Leakage2: " + masterSta_Leakage2.ToString() + "\r\n" +
"masterSta_Leakage3: " + masterSta_Leakage3.ToString() + "\r\n" +
"masterSta_Leakage4: " + masterSta_Leakage4.ToString() + "\r\n" +
"masterSta_Temp1: " + masterSta_Temp1.ToString() + "\r\n" +
"masterSta_Temp2: " + masterSta_Temp2.ToString() + "\r\n" +
"masterSta_Humi1: " + masterSta_Humi1.ToString() + "\r\n" +
"masterSta_Humi2: " + masterSta_Humi2.ToString() + "\r\n" +
"masterSta_LeakWater1: " + masterSta_LeakWater1.ToString() + "\r\n" +
"masterSta_LeakWater2: " + masterSta_LeakWater2.ToString() + "\r\n" +
"masterSta_InsidePress1: " + masterSta_InsidePress1.ToString() + "\r\n" +
"masterSta_InsidePress2: " + masterSta_InsidePress2.ToString() + "\r\n" +
"/**** 远程时序下发状态 ***/\r\n" +
"downTimeSeqSta: " + downTimeSeqSta.ToString() + "\r\n" +
"/**** 主控的输出状态 ***/\r\n" +
"deviceDate_gcms: " + deviceDate_gcms.ToString() + "\r\n" +
"deviceDate_serialPort1: " + deviceDate_serialPort1.ToString() + "\r\n" +
"deviceDate_serialPort2: " + deviceDate_serialPort2.ToString() + "\r\n" +
"deviceDate_osc: " + deviceDate_osc.ToString() + "\r\n" +
"deviceDate_adcp: " + deviceDate_adcp.ToString() + "\r\n" +
"deviceDate_ctdo: " + deviceDate_ctdo.ToString() + "\r\n" +
"deviceDate_vedio1: " + deviceDate_vedio1.ToString() + "\r\n" +
"deviceDate_ch4: " + deviceDate_ch4.ToString() + "\r\n" +
"deviceDate_icl: " + deviceDate_icl.ToString() + "\r\n" +
"deviceDate_gc: " + deviceDate_gc.ToString() + "\r\n" +
"deviceDate_co2: " + deviceDate_co2.ToString() + "\r\n" +
"deviceDate_raman: " + deviceDate_raman.ToString() + "\r\n" +
"deviceDate_ms: " + deviceDate_ms.ToString() + "\r\n" +
"deviceDate_vedio2: " + deviceDate_vedio2.ToString() + "\r\n" +
"deviceDate_net: " + deviceDate_net.ToString() + "\r\n" +
"deviceDate_acoustic: " + deviceDate_acoustic.ToString() + "\r\n" +
"/**** 主控的设备预警状态 ***/\r\n" +
"breakdown_gcms: " + breakdown_gcms.ToString() + "\r\n" +
"breakdown_serialPort1: " + breakdown_serialPort1.ToString() + "\r\n" +
"breakdown_serialPort2: " + breakdown_serialPort2.ToString() + "\r\n" +
"breakdown_osc: " + breakdown_osc.ToString() + "\r\n" +
"breakdown_adcp: " + breakdown_adcp.ToString() + "\r\n" +
"breakdown_ctdo: " + breakdown_ctdo.ToString() + "\r\n" +
"breakdown_vedio1: " + breakdown_vedio1.ToString() + "\r\n" +
"breakdown_ch4: " + breakdown_ch4.ToString() + "\r\n" +
"breakdown_icl: " + breakdown_icl.ToString() + "\r\n" +
"breakdown_gc: " + breakdown_gc.ToString() + "\r\n" +
"breakdown_co2: " + breakdown_co2.ToString() + "\r\n" +
"breakdown_raman: " + breakdown_raman.ToString() + "\r\n" +
"breakdown_ms: " + breakdown_ms.ToString() + "\r\n" +
"breakdown_vedio2: " + breakdown_vedio2.ToString() + "\r\n" +
"breakdown_net: " + masterSta_Leakage1.ToString() + "\r\n" +
"breakdown_acoustic: " + breakdown_acoustic.ToString() + "\r\n" +
"/**** 色谱 ***/\r\n" +
"cgdeviceTemp: " + cgdeviceTemp.ToString() + "\r\n" +
"cgdeviceHumi: " + cgdeviceHumi.ToString() + "\r\n" +
"cgdevicePress: " + cgdevicePress.ToString() + "\r\n" +
"cgdeviceInsulatio: " + cgdeviceInsulatio.ToString() + "\r\n" +
"cgC2_concentration: " + cgC2_concentration.ToString() + "\r\n" +
"cgC3_concentration: " + cgC3_concentration.ToString() + "\r\n" +
"cgC4_concentration: " + cgC4_concentration.ToString() + "\r\n" +
"/**** 质谱 ***/\r\n" +
"msdeviceTemp: " + msdeviceTemp.ToString() + "\r\n" +
"msdeviceHumi: " + msdeviceHumi.ToString() + "\r\n" +
"msdevicePress: " + msdevicePress.ToString() + "\r\n" +
"msdeviceInsulation: " + msdeviceInsulation.ToString() + "\r\n" +
"msCH4_concentration: " + msCH4_concentration.ToString() + "\r\n" +
"msH2O_concentration: " + msH2O_concentration.ToString() + "\r\n" +
"msN2_concentration: " + msN2_concentration.ToString() + "\r\n" +
"msO2_concentration: " + msO2_concentration.ToString() + "\r\n" +
"msAR_concentration: " + msAR_concentration.ToString() + "\r\n" +
"msCO2_concentration: " + msCO2_concentration.ToString() + "\r\n" +
"/**** 色质 ***/\r\n" +
"gcmsdeviceTemp: " + gcmsdeviceTemp.ToString() + "\r\n" +
"gcmsdeviceHumi: " + gcmsdeviceHumi.ToString() + "\r\n" +
"gcmsdevicePress: " + gcmsdevicePress.ToString() + "\r\n" +
"gcmsdeviceInsulation: " + gcmsdeviceInsulation.ToString() + "\r\n" +
"gcmsC2_concentration: " + gcmsC2_concentration.ToString() + "\r\n" +
"gcmsC3_concentration: " + gcmsC3_concentration.ToString() + "\r\n" +
"gcmsC4_concentration: " + gcmsC4_concentration.ToString() + "\r\n" +
"gcmsC5_concentration: " + gcmsC5_concentration.ToString() + "\r\n" +
"gcmsC6_concentration: " + gcmsC6_concentration.ToString() + "\r\n" +
"gcmsC7_concentration: " + gcmsC7_concentration.ToString() + "\r\n" +
"gcmsC8_concentration: " + gcmsC8_concentration.ToString() + "\r\n" +
"gcmsC9_concentration: " + gcmsC9_concentration.ToString() + "\r\n" +
"/**** 甲烷 ***/\r\n" +
"ch4deviceTemp: " + ch4deviceTemp.ToString() + "\r\n" +
"ch4deviceHumi: " + ch4deviceHumi.ToString() + "\r\n" +
"ch4devicePress: " + ch4devicePress.ToString() + "\r\n" +
"ch4deviceInsulation: " + ch4deviceInsulation.ToString() + "\r\n" +
"ch4C12_concentration: " + ch4C12_concentration.ToString() + "\r\n" +
"ch4Abundance: " + ch4Abundance.ToString() + "\r\n" +
"ch4H2O_concentrations: " + ch4H2O_concentrations.ToString() + "\r\n" +
"/**** 二氧化碳 ***/\r\n" +
"co2deviceTemp: " + co2deviceTemp.ToString() + "\r\n" +
"co2deviceHumi: " + co2deviceHumi.ToString() + "\r\n" +
"co2devicePress: " + co2devicePress.ToString() + "\r\n" +
"co2deviceInsulation: " + co2deviceInsulation.ToString() + "\r\n" +
"co2LuminousIntensity: " + co2LuminousIntensity.ToString() + "\r\n" +
"co2LaserTemperature: " + co2LaserTemperature.ToString() + "\r\n" +
"C12_concentration: " + C12_concentration.ToString() + "\r\n" +
"co2Abundance: " + co2Abundance.ToString() + "\r\n" +
"/**** 拉曼 ***/\r\n" +
"ramandeviceTemp: " + ramandeviceTemp.ToString() + "\r\n" +
"ramandeviceHumi: " + ramandeviceHumi.ToString() + "\r\n" +
"ramandevicePress: " + ramandevicePress.ToString() + "\r\n" +
"ramandeviceInsulation: " + ramandeviceInsulation.ToString() + "\r\n" +
"ramanPM_num: " + ramanPM_num.ToString() + "\r\n" +
"ramanPM_X: " + ramanPM_X.ToString() + "\r\n" +
"ramanPM_Y: " + ramanPM_Y.ToString() + "\r\n" +
"ramanPM_TYPE: " + ramanPM_TYPE.ToString() + "\r\n" +
"ramanPM_S: " + ramanPM_S.ToString() + "\r\n" +
"/**** 基因测序仪 ***/\r\n" +
"genedeviceTemp: " + genedeviceTemp.ToString() + "\r\n" +
"genedeviceHumi: " + genedeviceHumi.ToString() + "\r\n" +
"genedevicePress: " + genedevicePress.ToString() + "\r\n" +
"genedeviceInsulation: " + genedeviceInsulation.ToString() + "\r\n" +
"geneReagentTemp: " + geneReagentTemp.ToString() + "\r\n" +
"geneSampleConcentration: " + geneSampleConcentration.ToString() + "\r\n" +
"geneworkflow: " + geneworkflow.ToString() + "\r\n";
this.Invoke(new MethodInvoker(() =>
{
DataRichTxt.AppendText(data_display);
}));
/* 创建文件 */
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string DirName = "basedata_145";
string fileName = year.ToString() + "年" + month.ToString() + "月" + day.ToString() + "日" + hour.ToString() + "时" + minute.ToString() + "分" + second.ToString() + "秒" + ".txt";
string filepath = Path.Combine(desktopPath, DirName, fileName);
File.WriteAllText(filepath, data_display);
}
}
}
catch (Exception e) {
Console.WriteLine("UDP Recv异常" + e.Message);
}
}
/* 时钟同步函数 */
private void UdpToMctrlSyncTime()
{
byte[] syncBytes = new byte[18];
while (true) {
Thread.Sleep(5);
/* 获取系统时间 */
DateTime localTime = DateTime.Now;
syncBytes[0] = 0xAA;
syncBytes[1] = 0xBB;
syncBytes[2] = 0x01;
syncBytes[3] = 0x00;
syncBytes[4] = 0x12;
syncBytes[5] = 0x10;
syncBytes[6] = 0x40;
syncBytes[7] = 0x00;
syncBytes[8] = 0x01;
syncBytes[9] = (byte)(localTime.Year - 2000); // 年
syncBytes[10] = (byte)(localTime.Month); // 月
syncBytes[11] = (byte)(localTime.Day); // 日
syncBytes[12] = (byte)(localTime.Hour); // 时
syncBytes[13] = (byte)(localTime.Minute); // 分
syncBytes[14] = (byte)(localTime.Second); // 秒
syncBytes[15] = BufferXorCheck(syncBytes, 15); // 校验码
syncBytes[16] = 0xEE;
syncBytes[17] = 0xFF;
UdpSendBuf(syncBytes, syncBytes.Length);
}
}
/* 发送数据 */
private void UdpSendBuf(byte[] Buff, int BufferLen)
{
if (udpInitFlag == 1)
{
gs_mutex.WaitOne();
gs_udpSocket.SendTo(Buff, BufferLen, 0, gs_sendIPEndPoint);
/* 发送时间+发送报文 */
this.Invoke(new MethodInvoker(() =>
{
SendBox.AppendText(DateTime.Now.ToString() + " : " + BitConverter.ToString(Buff, 0, BufferLen).Replace('-', ' ') + "\r\n");
}));
gs_mutex.ReleaseMutex();
}
}
private void SendRestartBtn_Click(object sender, EventArgs e)
{
Restart_TXTBOX.Text = BitConverter.ToString(restartBuff).Replace('-', ' ');
UdpSendBuf(restartBuff, restartBuff.Length);
}
/* 异或校验 */
private byte BufferXorCheck(byte[] buffer, int bufferLen)
{
byte xor = 0;
for (int i = 0; i < bufferLen; i++) {
xor ^= buffer[i];
}
return xor;
}
private void BaseStation_FormClosing(object sender, FormClosingEventArgs e)
{
gs_udpThread.Abort();
gs_timeSyncThread.Abort();
gs_udpSocket.Close();
}
private void clearBtn_Click(object sender, EventArgs e)
{
DataRichTxt.Clear();
}
}
}