1904 lines
91 KiB
C#
1904 lines
91 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Globalization;
|
||
using System.IO;
|
||
using System.IO.Ports;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using 垂直剖面浮标临时测试软件.Model;
|
||
|
||
namespace 垂直剖面浮标临时测试软件
|
||
{
|
||
public partial class Form1 : Form
|
||
{
|
||
//实例化
|
||
Buoy_sensor_adcpModel buoy_Sensor_AdcpModel = new Buoy_sensor_adcpModel();
|
||
Buoy_sensor_attitudeModel buoy_Sensor_AttitudeModel = new Buoy_sensor_attitudeModel();
|
||
Buoy_sensor_othModel buoy_Sensor_OthModel = new Buoy_sensor_othModel();
|
||
Conbox_sensor_adcpModel conbox_Sensor_AdcpModel = new Conbox_sensor_adcpModel();
|
||
Conbox_sensor_othModel conbox_Sensor_OthModel = new Conbox_sensor_othModel();
|
||
Lattarget_sensor_adcp300Model lattarget_Sensor_Adcp300Model = new Lattarget_sensor_adcp300Model();
|
||
Switch_Model switch_Model = new Switch_Model();
|
||
Enviroment_Model enviroment_Model = new Enviroment_Model();
|
||
Lattarget_sensor_othModel lattarget_Sensor_Oth = new Lattarget_sensor_othModel();
|
||
|
||
|
||
//单线程
|
||
private System.Threading.Timer _flash_page;
|
||
|
||
public Form1()
|
||
{
|
||
InitializeComponent();
|
||
//波特率
|
||
string[] btl = new string[] { "110", "300", "600", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "56000", "57600", "115200", "128000", "256000" };
|
||
for (int i = 0; i < btl.Length; i++)
|
||
{
|
||
comboBox1.Items.Add(btl[i]);
|
||
}
|
||
comboBox1.Text = "19200";
|
||
|
||
//刷新界面的线程
|
||
_flash_page = new System.Threading.Timer(new System.Threading.TimerCallback(WritetoPage), null, 2000, 1000);
|
||
|
||
|
||
//设置当前界面上串口未打开时 控件无法使用
|
||
groupBox3.Enabled = false;
|
||
groupBox15.Enabled = false;
|
||
groupBox12.Enabled = false;
|
||
groupBox11.Enabled = false;
|
||
groupBox2.Enabled = false;
|
||
groupBox23.Enabled = false;
|
||
groupBox22.Enabled = false;
|
||
groupbox24.Enabled = false;
|
||
groupBox9.Enabled = false;
|
||
groupBox10.Enabled = false;
|
||
groupBox13.Enabled = false;
|
||
groupBox27.Enabled = false;
|
||
groupBox28.Enabled = false;
|
||
groupBox29.Enabled = false;
|
||
textBox7.Text = @"D:\垂直剖面浮标文件\";
|
||
|
||
tools._start_time = System.DateTime.Now;
|
||
}
|
||
private void comboBox2_DropDown(object sender, EventArgs e)
|
||
{
|
||
comboBox2.Items.Clear();
|
||
//获取当前设备所有的串口号
|
||
string[] portsname = tools.GetSerialPort();
|
||
for (int i = 0; i < portsname.Length; i++)
|
||
{
|
||
comboBox2.Items.Add(portsname[i]);
|
||
}
|
||
}
|
||
|
||
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
//将两秒没接收的数据作为1组
|
||
System.Threading.Thread.Sleep(2000);
|
||
//将缓冲区内字节数大小设置为数组大小
|
||
byte[] byteRead = new byte[serialPort1.BytesToRead];
|
||
//将缓冲区内数据写入字节数组中
|
||
serialPort1.Read(byteRead, 0, byteRead.Length);
|
||
//清除串口缓冲区
|
||
serialPort1.DiscardInBuffer();
|
||
if (byteRead.Length == 0)
|
||
return;
|
||
string rec_16 = null;
|
||
for (int i = 0; i < byteRead.Length; i++)
|
||
{
|
||
rec_16 += byteRead[i].ToString("X2"); //16进制显示
|
||
}
|
||
Console.WriteLine("接收到的16进制数据为:" + rec_16);
|
||
string _message = tools.HexStringToString(rec_16, Encoding.Default).Replace("\r\n","");
|
||
wirte_textbox(_message);
|
||
if (_message.Contains("CSQ"))
|
||
{
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
label144.Text = _message.Trim().Replace(" ", "");
|
||
}));
|
||
}
|
||
else if (_message.Contains("CONNECT"))
|
||
{
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
label145.Text = _message.Trim().Replace(" ", "");
|
||
}));
|
||
}
|
||
|
||
tools.HexStringToString(rec_16, Encoding.Default);
|
||
wirte_textbox(rec_16);
|
||
//数据解析
|
||
ParsingData(new List<byte>(byteRead));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine(ex.Message);
|
||
}
|
||
}
|
||
|
||
|
||
bool _set_para = false; //参数设置
|
||
bool _set_time = false; //时间设置
|
||
bool _isConnected = false; //是否登录
|
||
string _file_request = ""; //文件请求状态'
|
||
string _start_hour = "", _start_min = "", _timer = "", _time = "", _ADCPJD = "";
|
||
int _adcp_num = 0;//记录ADCP的序号
|
||
//解析
|
||
private void ParsingData(List<byte> byteList)
|
||
{
|
||
//显示报文
|
||
string message = "下位机回复 ";
|
||
|
||
//获取当前系统时间
|
||
DateTime time_DataBase = DateTime.Now;
|
||
|
||
//帧头
|
||
byte[] _header = new byte[] { 0xEF, 0xFE, 0xFE, 0xEF };
|
||
//帧尾
|
||
byte _end = 0x16;
|
||
//长度校验
|
||
int _len = 0;
|
||
//校验
|
||
int _check = 0;
|
||
//功能码
|
||
byte _fun_code = 0;
|
||
//类型
|
||
byte _kind = 0;
|
||
//数据类型
|
||
byte _data_type = 0;
|
||
|
||
//校验当前List是否为空或者长度
|
||
if (byteList == null || byteList.Count == 0)
|
||
return;
|
||
|
||
|
||
//校验帧头
|
||
if (byteList[0] != _header[0] && byteList[0] != _header[2])
|
||
return;
|
||
if (byteList[1] != _header[1] && byteList[1] != _header[3])
|
||
return;
|
||
//校验帧尾
|
||
if (byteList[byteList.Count - 1] != _end)
|
||
return;
|
||
|
||
//获取检验长度
|
||
_len = Convert.ToInt32(byteList[2].ToString("X2") + byteList[3].ToString("X2"), 16);
|
||
|
||
//获取检验的校验和
|
||
for (int i = 0; i < byteList.Count - 2; i++)
|
||
{
|
||
_check += byteList[i];
|
||
}
|
||
_check = _check & 0xFF;
|
||
|
||
//长度 及 累加和校验
|
||
if (_len != byteList.Count - 4 || byteList[byteList.Count - 2] != _check)
|
||
return;
|
||
|
||
|
||
_len = 0;
|
||
_check = 0;
|
||
|
||
//功能码
|
||
_fun_code = byteList[5];
|
||
//类型
|
||
_kind = byteList[6];
|
||
|
||
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
|
||
DateTime dt = new DateTime();
|
||
switch (_fun_code)
|
||
{
|
||
//数据解析
|
||
case 0x02:
|
||
message += "数据解析 ";
|
||
//ADCP压力
|
||
string pre = "";
|
||
//ADCP
|
||
string adcp = "";
|
||
double x, y, _x, _y;
|
||
switch (_kind)
|
||
{
|
||
//接驳盒端ADCP
|
||
case 31:
|
||
message += "接驳盒ADCP";
|
||
if ((int)byteList[8] == 0 && (int)byteList[9] == 0 && (int)byteList[10] == 0)
|
||
{
|
||
conbox_Sensor_AdcpModel.datetime_Sensor = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
conbox_Sensor_AdcpModel.datetime_Sensor = Convert.ToDateTime((int)byteList[8] + "-" + (int)byteList[9] + "-" + (int)byteList[10] + " " + (int)byteList[11] + ":" + (int)byteList[12] + ":" + (int)byteList[13]);
|
||
}
|
||
//压力
|
||
conbox_Sensor_AdcpModel.Adcp_Pre = tools.bytetoint(byteList, 14, 4);
|
||
//压缩比
|
||
conbox_Sensor_AdcpModel.Adcp_Ysb = (int)byteList[18];
|
||
for (int i = 0; i < byteList.Count; i++)
|
||
{
|
||
//27层ADCP数据
|
||
if (i > 18 && i < byteList.Count - 2)
|
||
{
|
||
adcp += (int)byteList[i] + ",";
|
||
}
|
||
}
|
||
//27层ADCP
|
||
conbox_Sensor_AdcpModel.Adcp_VD = adcp.Substring(0, adcp.Length - 1);
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
_adcp_num = 4;
|
||
Mysql.write_ob(conbox_Sensor_AdcpModel, "conbox_sensor_adcpmodel");
|
||
tools.Count_rate(5);
|
||
break;
|
||
//接驳盒端其他传感器集合
|
||
case 30:
|
||
message += "接驳盒端其他传感器集合";
|
||
if ((int)byteList[8] == 0 && (int)byteList[9] == 0 && (int)byteList[10] == 0 && (int)byteList[11] == 0)
|
||
{
|
||
dt = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
//UTC时间
|
||
dt = startTime.AddSeconds(Convert.ToInt32(byteList[8].ToString("X2") + byteList[9].ToString("X2") + byteList[10].ToString("X2") + byteList[11].ToString("X2"), 16));
|
||
}
|
||
conbox_Sensor_OthModel.datetime_Sensor = dt;
|
||
conbox_Sensor_OthModel.CH4_Pre = tools.bytetofloat(byteList, 12);
|
||
conbox_Sensor_OthModel.CH4_Con = tools.bytetofloat(byteList, 16);
|
||
conbox_Sensor_OthModel.CO2_Pre = tools.bytetofloat(byteList, 20);
|
||
conbox_Sensor_OthModel.CO2_Con = tools.bytetofloat(byteList, 24);
|
||
if (tools.bytetoint(byteList, 28, 4) == 0 && tools.bytetoint(byteList, 32, 4) == 0)
|
||
{
|
||
conbox_Sensor_OthModel.METS_Meth = 0;
|
||
conbox_Sensor_OthModel.METS_Tem = 0;
|
||
}
|
||
else
|
||
{
|
||
x = (double)tools.bytetoint(byteList, 28, 4) * 5 / 4096;
|
||
y = (double)tools.bytetoint(byteList, 32, 4) * 5 / 4096;
|
||
_x = 1 / x - (1 / (0 - 4.042 + 10.482 * Math.Exp(-y / 1.876)));
|
||
_y = 0.475 + 0.461 * Math.Exp(-y / 0.418);
|
||
|
||
conbox_Sensor_OthModel.METS_Meth = double.IsNaN(Math.Exp(2.433 * Math.Log10(_x * _y))) ? 0f : (float)Math.Exp(2.433 * Math.Log10(_x * _y));
|
||
conbox_Sensor_OthModel.METS_Tem = (float)(22.65 * y - 4.71);
|
||
}
|
||
conbox_Sensor_OthModel.CTD_Tem = tools.bytetofloat(byteList, 36);
|
||
conbox_Sensor_OthModel.CTD_Con = tools.bytetofloat(byteList, 40);
|
||
conbox_Sensor_OthModel.CTD_Pre = tools.bytetofloat(byteList, 44);
|
||
conbox_Sensor_OthModel.Angle_sensor_x = (float)tools.ByteToInt16(byteList, 48, 2) / 32767 * 2000;
|
||
conbox_Sensor_OthModel.Angle_sensor_y = (float)tools.ByteToInt16(byteList, 50, 2) / 32767 * 2000;
|
||
conbox_Sensor_OthModel.Angle_sensor_z = (float)tools.ByteToInt16(byteList, 52, 2) / 32767 * 2000;
|
||
float CTD_YLS_Vol = (float)tools.bytetofloat(byteList, 54);
|
||
float CTD_ZD_Vol = (float)tools.bytetofloat(byteList, 58);
|
||
float CTD_Rjy_Pim = (float)tools.bytetofloat(byteList, 62);
|
||
float CTD_Rjy_Vol = (float)tools.bytetofloat(byteList, 66);
|
||
float sal = 0.035f;//盐度
|
||
float ts = (float)Math.Log((298.15 - conbox_Sensor_OthModel.CTD_Tem) / (273.15 + conbox_Sensor_OthModel.CTD_Tem));
|
||
conbox_Sensor_OthModel.CTD_YLS = 6 * (CTD_YLS_Vol - 0.07f);
|
||
conbox_Sensor_OthModel.CTD_ZD = 25 * (CTD_ZD_Vol - 0.01f);
|
||
conbox_Sensor_OthModel.CTD_Rjy = (float)((((1.0513 - 0.0015 * conbox_Sensor_OthModel.CTD_Tem + 0.3536259 * Math.Pow(CTD_Rjy_Pim * 39.457071, 2)) / (-0.2086977 + 1.562443 * CTD_Rjy_Pim * 39.457071) - 1) / (0.1074392 + 0.004513420 * conbox_Sensor_OthModel.CTD_Tem + 0.00005769378 * Math.Pow(conbox_Sensor_OthModel.CTD_Tem, 2))) * Math.Exp(sal * (-6.24523 * Math.Pow(10, -3) + -7.37614 * Math.Pow(10, -3) * ts + -1.03410 * Math.Pow(10, -2) * Math.Pow(ts, 2) + -8.17083 * Math.Pow(10, -3) * Math.Pow(ts, 3)) + -4.88682 * Math.Pow(10, -7) * Math.Pow(sal, 2)) * 1.1 * Math.Pow(10, -2)) * 1.42903f;
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
Mysql.write_ob(conbox_Sensor_OthModel, "conbox_sensor_othmodel");
|
||
tools.Count_rate(4);
|
||
break;
|
||
//潜标端ADCP-WSH-300
|
||
case 21:
|
||
message += "潜标端ADCP-WSH-300";
|
||
if ((int)byteList[8] == 0 && (int)byteList[9] == 0 && (int)byteList[10] == 0)
|
||
{
|
||
lattarget_Sensor_Adcp300Model.datetime_Sensor = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
lattarget_Sensor_Adcp300Model.datetime_Sensor = Convert.ToDateTime((int)byteList[8] + "-" + (int)byteList[9] + "-" + (int)byteList[10] + " " + (int)byteList[11] + ":" + (int)byteList[12] + ":" + (int)byteList[13]);
|
||
}
|
||
//压力
|
||
lattarget_Sensor_Adcp300Model.Adcp_Pre = tools.bytetoint(byteList, 14, 4);
|
||
//压缩比
|
||
lattarget_Sensor_Adcp300Model.Adcp_Ysb = (int)byteList[18];
|
||
for (int i = 0; i < byteList.Count; i++)
|
||
{
|
||
//27层ADCP数据
|
||
if (i > 18 && i < byteList.Count - 2)
|
||
{
|
||
adcp += (int)byteList[i] + ",";
|
||
}
|
||
}
|
||
//27层ADCP
|
||
lattarget_Sensor_Adcp300Model.Adcp_VD = adcp.Substring(0, adcp.Length - 1);
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
_adcp_num = 3;
|
||
Mysql.write_ob(lattarget_Sensor_Adcp300Model, "lattarget_sensor_adcp300model");
|
||
tools.Count_rate(2);
|
||
break;
|
||
//潜标端其他传感器
|
||
case 25:
|
||
message += "潜标其他传感器集合";
|
||
if ((int)byteList[8] == 0 && (int)byteList[9] == 0 && (int)byteList[10] == 0 && (int)byteList[11] == 0)
|
||
{
|
||
dt = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
//UTC时间
|
||
dt = startTime.AddSeconds(Convert.ToInt32(byteList[8].ToString("X2") + byteList[9].ToString("X2") + byteList[10].ToString("X2") + byteList[11].ToString("X2"), 16));
|
||
}
|
||
lattarget_Sensor_Oth.datetime_Sensor = dt;
|
||
//lattarget_Sensor_Oth.CH4_Pre = tools.bytetofloat(byteList, 12);
|
||
//lattarget_Sensor_Oth.CH4_Con = tools.bytetofloat(byteList, 16);
|
||
lattarget_Sensor_Oth.CO2_Pre = tools.bytetofloat(byteList, 20);
|
||
lattarget_Sensor_Oth.CO2_Con = tools.bytetofloat(byteList, 24);
|
||
if (tools.bytetoint(byteList, 28, 4) == 0 && tools.bytetoint(byteList, 32, 4) == 0)
|
||
{
|
||
lattarget_Sensor_Oth.METS_Meth = 0;
|
||
lattarget_Sensor_Oth.METS_Tem = 0;
|
||
}
|
||
else
|
||
{
|
||
x = (double)tools.bytetoint(byteList, 28, 4) * 5 / 4096;
|
||
y = (double)tools.bytetoint(byteList, 32, 4) * 5 / 4096;
|
||
_x = 1 / x - (1 / (0 - 4.042 + 10.482 * Math.Exp(-y / 1.876)));
|
||
_y = 0.475 + 0.461 * Math.Exp(-y / 0.418);
|
||
lattarget_Sensor_Oth.METS_Meth = double.IsNaN(Math.Exp(2.433 * Math.Log10(_x * _y))) ? 0f : (float)Math.Exp(2.433 * Math.Log10(_x * _y));
|
||
lattarget_Sensor_Oth.METS_Tem = (float)(22.65 * y - 4.71);
|
||
}
|
||
lattarget_Sensor_Oth.CTD_Tem = tools.bytetofloat(byteList, 36);
|
||
lattarget_Sensor_Oth.CTD_Con = tools.bytetofloat(byteList, 40);
|
||
lattarget_Sensor_Oth.CTD_Pre = tools.bytetofloat(byteList, 44);
|
||
lattarget_Sensor_Oth.Angle_sensor_x = (float)tools.ByteToInt16(byteList, 48, 2) / 32767 * 2000;
|
||
lattarget_Sensor_Oth.Angle_sensor_y = (float)tools.ByteToInt16(byteList, 50, 2) / 32767 * 2000;
|
||
lattarget_Sensor_Oth.Angle_sensor_z = (float)tools.ByteToInt16(byteList, 52, 2) / 32767 * 2000;
|
||
CTD_YLS_Vol = (float)tools.bytetofloat(byteList, 54);
|
||
CTD_ZD_Vol = (float)tools.bytetofloat(byteList, 58);
|
||
CTD_Rjy_Pim = (float)tools.bytetofloat(byteList, 62);
|
||
CTD_Rjy_Vol = (float)tools.bytetofloat(byteList, 66);
|
||
sal = 0.035f;//盐度
|
||
ts = (float)Math.Log((298.15 - lattarget_Sensor_Oth.CTD_Tem) / (273.15 + lattarget_Sensor_Oth.CTD_Tem));
|
||
lattarget_Sensor_Oth.CTD_YLS = 6 * (CTD_YLS_Vol - 0.07f);
|
||
lattarget_Sensor_Oth.CTD_ZD = 25 * (CTD_ZD_Vol - 0.01f);
|
||
lattarget_Sensor_Oth.CTD_Rjy = (float)((((1.0513 - 0.0015 * lattarget_Sensor_Oth.CTD_Tem + 0.3536259 * Math.Pow(CTD_Rjy_Pim * 39.457071, 2)) / (-0.2086977 + 1.562443 * CTD_Rjy_Pim * 39.457071) - 1) / (0.1074392 + 0.004513420 * lattarget_Sensor_Oth.CTD_Tem + 0.00005769378 * Math.Pow(lattarget_Sensor_Oth.CTD_Tem, 2))) * Math.Exp(sal * (-6.24523 * Math.Pow(10, -3) + -7.37614 * Math.Pow(10, -3) * ts + -1.03410 * Math.Pow(10, -2) * Math.Pow(ts, 2) + -8.17083 * Math.Pow(10, -3) * Math.Pow(ts, 3)) + -4.88682 * Math.Pow(10, -7) * Math.Pow(sal, 2)) * 1.1 * Math.Pow(10, -2)) * 1.42903f;
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
Mysql.write_ob(lattarget_Sensor_Oth, "lattarget_sensor_othmodel");
|
||
tools.Count_rate(3);
|
||
break;
|
||
//浮标端其他传感器数据
|
||
case 10:
|
||
message += "浮标端其他传感器数据";
|
||
if ((int)byteList[8] == 0 && (int)byteList[9] == 0 && (int)byteList[10] == 0 && (int)byteList[11] == 0)
|
||
{
|
||
dt = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
dt = startTime.AddSeconds(Convert.ToInt32(byteList[8].ToString("X2") + byteList[9].ToString("X2") + byteList[10].ToString("X2") + byteList[11].ToString("X2"), 16));
|
||
}
|
||
buoy_Sensor_OthModel.datetime_Sensor = dt;
|
||
buoy_Sensor_OthModel.CH4_Pre = tools.bytetofloat(byteList, 12);
|
||
buoy_Sensor_OthModel.CH4_Con = tools.bytetofloat(byteList, 16);
|
||
buoy_Sensor_OthModel.CO2_Pre = tools.bytetofloat(byteList, 20);
|
||
buoy_Sensor_OthModel.CO2_Con = tools.bytetofloat(byteList, 24);
|
||
if (tools.bytetoint(byteList, 28, 4) == 0 && tools.bytetoint(byteList, 32, 4) == 0)
|
||
{
|
||
buoy_Sensor_OthModel.METS_Meth = 0;
|
||
buoy_Sensor_OthModel.METS_Tem = 0;
|
||
}
|
||
else
|
||
{
|
||
x = (double)tools.bytetoint(byteList, 28, 4) * 5 / 4096;
|
||
y = (double)tools.bytetoint(byteList, 32, 4) * 5 / 4096;
|
||
_x = 1 / x - (1 / (0 - 4.042 + 10.482 * Math.Exp(-y / 1.876)));
|
||
_y = 0.475 + 0.461 * Math.Exp(-y / 0.418);
|
||
buoy_Sensor_OthModel.METS_Meth = double.IsNaN(Math.Exp(2.433 * Math.Log10(_x * _y))) ? 0f : (float)Math.Exp(2.433 * Math.Log10(_x * _y));
|
||
buoy_Sensor_OthModel.METS_Tem = (float)(22.65 * y - 4.71);
|
||
}
|
||
buoy_Sensor_OthModel.Air_Tem = tools.bytetofloat(byteList, 36);
|
||
buoy_Sensor_OthModel.Air_Hum = tools.bytetofloat(byteList, 40);
|
||
buoy_Sensor_OthModel.Air_Pre = tools.bytetofloat(byteList, 44);
|
||
buoy_Sensor_OthModel.Wind_Dir = tools.bytetofloat(byteList, 48);
|
||
buoy_Sensor_OthModel.Wind_Speed = tools.bytetofloat(byteList, 52);
|
||
buoy_Sensor_OthModel.Wind_Speed_Max = tools.bytetofloat(byteList, 56);
|
||
buoy_Sensor_OthModel.Fzd = tools.bytetofloat(byteList, 60);
|
||
buoy_Sensor_OthModel.RainFall = tools.bytetofloat(byteList, 64);
|
||
buoy_Sensor_OthModel.Go_sailing_CH4_Dry = tools.bytetofloat(byteList, 68);
|
||
buoy_Sensor_OthModel.Go_sailing_CH4_H2O = tools.bytetofloat(byteList, 72);
|
||
buoy_Sensor_OthModel.Go_sailing_CH4_C2H6 = tools.bytetofloat(byteList, 76);
|
||
buoy_Sensor_OthModel.Tem = (float)tools.ByteToInt16(byteList, 80, 2) / 1000 * 100;
|
||
buoy_Sensor_OthModel.Hum = (float)tools.ByteToInt16(byteList, 82, 2) / 1000 * 100 / 3;
|
||
buoy_Sensor_OthModel.Vol_24_in = (float)(tools.ByteToInt16(byteList, 84, 2) / 1000 * 11.02);
|
||
buoy_Sensor_OthModel.Cur_24_in = (float)(tools.ByteToInt16(byteList, 86, 2) * 1.35 / 1000);
|
||
buoy_Sensor_OthModel.Vol_48_out = (float)(tools.ByteToInt16(byteList, 88, 2) * 21.02 / 1000);
|
||
buoy_Sensor_OthModel.Vol_95_out = (float)(tools.ByteToInt16(byteList, 90, 2) * 47.78 / 1000);
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
Mysql.write_ob(buoy_Sensor_OthModel, "buoy_sensor_othmodel");
|
||
tools.Count_rate(1);
|
||
break;
|
||
//浮标端ADCP-WSH300
|
||
case 11:
|
||
message += "浮标端ADCP-WSH300";
|
||
if ((int)byteList[8] == 0 && (int)byteList[9] == 0 && (int)byteList[10] == 0)
|
||
{
|
||
buoy_Sensor_AdcpModel.datetime_Sensor = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
buoy_Sensor_AdcpModel.datetime_Sensor = Convert.ToDateTime((int)byteList[8] + "-" + (int)byteList[9] + "-" + (int)byteList[10] + " " + (int)byteList[11] + ":" + (int)byteList[12] + ":" + (int)byteList[13]);
|
||
}
|
||
//压力
|
||
buoy_Sensor_AdcpModel.Adcp_Pre = tools.bytetoint(byteList, 14, 4);
|
||
//压缩比
|
||
buoy_Sensor_AdcpModel.Adcp_Ysb = (int)byteList[18];
|
||
for (int i = 0; i < byteList.Count; i++)
|
||
{
|
||
//27层ADCP数据
|
||
if (18 < i && i < byteList.Count - 1)
|
||
{
|
||
adcp += (int)byteList[i] + ",";
|
||
}
|
||
}
|
||
//27层ADCP
|
||
buoy_Sensor_AdcpModel.Adcp_VD = adcp.Substring(0, adcp.Length - 1);
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
_adcp_num = 1;
|
||
Mysql.write_ob(buoy_Sensor_AdcpModel, "buoy_sensor_adcpmodel");
|
||
tools.Count_rate(0);
|
||
break;
|
||
//浮标端浮标姿态传感器数据
|
||
case 13:
|
||
message += "浮标端浮标姿态传感器数据";
|
||
buoy_Sensor_AttitudeModel.Attitude_sensor = Encoding.Default.GetString(byteList.ToArray());
|
||
//返回解析成功指令
|
||
send_port(_kind.ToString("X2"), "01");
|
||
Mysql.write_ob(buoy_Sensor_AttitudeModel, "buoy_sensor_attitudemodel");
|
||
tools.Count_rate(6);
|
||
break;
|
||
default:
|
||
Console.WriteLine("未能识别类型!");
|
||
break;
|
||
}
|
||
break;
|
||
//远程控制
|
||
case 0x03:
|
||
message += "远程控制 ";
|
||
if (byteList[6] == 0x01)
|
||
{
|
||
int KIND_INT = (int)byteList[7];
|
||
int ID_INT = (int)byteList[8];
|
||
bool _bool = false;
|
||
switch (byteList[9])
|
||
{
|
||
case 0x00:
|
||
_bool = false;//关闭
|
||
break;
|
||
case 0x01:
|
||
_bool = true;//开启
|
||
break;
|
||
case 0x02:
|
||
wirte_textbox("远程控制失败!");
|
||
return;
|
||
default:
|
||
break;
|
||
}
|
||
bool kind = false;
|
||
switch (byteList[10])
|
||
{
|
||
case 0x00:
|
||
kind = false;//电源
|
||
break;
|
||
case 0x01:
|
||
kind = true;//数据回传
|
||
break;
|
||
case 0x02:
|
||
wirte_textbox("远程控制失败!");
|
||
return;
|
||
default:
|
||
break;
|
||
}
|
||
message += kind ? "数据" : "电源" + _bool;
|
||
if (true)
|
||
|
||
if (KIND_INT == 31)
|
||
{
|
||
message += "接驳盒ADCP ";
|
||
if (kind) switch_Model.JBH_Adcp_Data = _bool;
|
||
if (!kind) switch_Model.JBH_Adcp_Power = _bool;
|
||
}
|
||
else if (KIND_INT == 30)
|
||
{
|
||
message += "接驳盒其他传感器集合 ";
|
||
if (ID_INT == 1)
|
||
{
|
||
message += "CH4";
|
||
if (kind) switch_Model.JBH_CH4_Data = _bool;
|
||
if (!kind) switch_Model.JBH_CH4_Power = _bool;
|
||
}
|
||
else if (ID_INT == 2)
|
||
{
|
||
message += "CO2";
|
||
if (kind) switch_Model.JBH_CO2_Data = _bool;
|
||
if (!kind) switch_Model.JBH_CO2_Power = _bool;
|
||
}
|
||
else if (ID_INT == 3)
|
||
{
|
||
message += "METS";
|
||
if (kind) switch_Model.JBH_METS_Data = _bool;
|
||
if (!kind) switch_Model.JBH_METS_Power = _bool;
|
||
}
|
||
else if (ID_INT == 4)
|
||
{
|
||
message += "CTD";
|
||
if (kind) switch_Model.JBH_CTD_Data = _bool;
|
||
if (!kind) switch_Model.JBH_CTD_Power = _bool;
|
||
}
|
||
else if (ID_INT == 5)
|
||
{
|
||
message += "倾角";
|
||
if (kind) switch_Model.JBH_Attitude_Data = _bool;
|
||
if (!kind) switch_Model.JBH_Attitude_Power = _bool;
|
||
}
|
||
}
|
||
else if (KIND_INT == 21)
|
||
{
|
||
message += "潜标端ADCP-WSH300";
|
||
if (kind) switch_Model.QB_Adcp300_Data = _bool;
|
||
if (!kind) switch_Model.QB_Adcp300_Power = _bool;
|
||
}
|
||
else if (KIND_INT == 10)
|
||
{
|
||
message += "浮标端其他传感器数据";
|
||
if (ID_INT == 1)
|
||
{
|
||
message += "CH4";
|
||
if (kind) switch_Model.FB_CH4_Data = _bool;
|
||
if (!kind) switch_Model.FB_CH4_Power = _bool;
|
||
}
|
||
else if (ID_INT == 2)
|
||
{
|
||
message += "CO2";
|
||
if (kind) switch_Model.FB_CO2_Data = _bool;
|
||
if (!kind) switch_Model.FB_CO2_Power = _bool;
|
||
}
|
||
else if (ID_INT == 3)
|
||
{
|
||
message += "METS";
|
||
if (kind) switch_Model.FB_METS_Data = _bool;
|
||
if (!kind) switch_Model.FB_METS_Power = _bool;
|
||
}
|
||
else if (ID_INT == 4)
|
||
{
|
||
message += "CTD";
|
||
if (kind) switch_Model.FB_CTD_Data = _bool;
|
||
if (!kind) switch_Model.FB_CTD_Power = _bool;
|
||
}
|
||
else if (ID_INT == 6)
|
||
{
|
||
message += "走航甲烷";
|
||
if (kind)
|
||
switch_Model.FB_Sailing_CH4_Data = _bool;
|
||
if (!kind)
|
||
switch_Model.FB_Sailing_CH4_Power = _bool;
|
||
}
|
||
else if (ID_INT == 7)
|
||
{
|
||
message += "气象";
|
||
if (kind) switch_Model.FB_Air_Data = _bool;
|
||
if (!kind) switch_Model.FB_Air_Power = _bool;
|
||
}
|
||
}
|
||
else if (KIND_INT == 11)
|
||
{
|
||
message += "浮标端ADCP-WSH300";
|
||
if (kind) switch_Model.FB_Adcp_Data = _bool;
|
||
if (!kind) switch_Model.FB_Adcp_Power = _bool;
|
||
}
|
||
else if (KIND_INT == 13)
|
||
{
|
||
message += "浮标端浮标姿态传感器数据";
|
||
if (kind) switch_Model.FB_Attitude_Data = _bool;
|
||
if (!kind) switch_Model.FB_Attitude_Power = _bool;
|
||
}
|
||
else if (KIND_INT == 25)
|
||
{
|
||
message += "潜标其他传感器";
|
||
if (ID_INT == 1)
|
||
{
|
||
|
||
}
|
||
else if (ID_INT == 2)
|
||
{
|
||
message += "CO2";
|
||
if (kind) switch_Model.QB_CO2_Data = _bool;
|
||
if (!kind) switch_Model.QB_CO2_Power = _bool;
|
||
}
|
||
else if (ID_INT == 3)
|
||
{
|
||
message += "METS";
|
||
if (kind) switch_Model.QB_METS_Data = _bool;
|
||
if (!kind) switch_Model.QB_METS_Power = _bool;
|
||
}
|
||
else if (ID_INT == 4)
|
||
{
|
||
message += "CTD";
|
||
if (kind) switch_Model.QB_CTD_Data = _bool;
|
||
if (!kind) switch_Model.QB_CTD_Power = _bool;
|
||
}
|
||
else if (ID_INT == 10)
|
||
{
|
||
message += "水声通信机";
|
||
if (!kind) switch_Model.QB_SSTX_Power = _bool;
|
||
}
|
||
}
|
||
}
|
||
else if (byteList[6] == 0x00)
|
||
{
|
||
message += "读取状态";
|
||
string ctl = byteList[7].ToString("X2") + byteList[8].ToString("X2") + byteList[9].ToString("X2") + byteList[10].ToString("X2");
|
||
string ctl_2 = null;
|
||
for (int i = 0; i < ctl.Length; i++)
|
||
{
|
||
ctl_2 += tools.HexString2BinString(ctl.Substring(i, 1));
|
||
}
|
||
ctl_2 = ctl_2.Replace(" ", "");
|
||
if (ctl_2.Length == 32)
|
||
{
|
||
switch_Model.JBH_METS_Data = O_C(ctl_2.Substring(2, 1));
|
||
switch_Model.JBH_METS_Power = O_C(ctl_2.Substring(3, 1));
|
||
switch_Model.JBH_Attitude_Data = O_C(ctl_2.Substring(4, 1));
|
||
switch_Model.JBH_Attitude_Power = O_C(ctl_2.Substring(5, 1));
|
||
switch_Model.JBH_CTD_Data = O_C(ctl_2.Substring(6, 1));
|
||
switch_Model.JBH_CTD_Power = O_C(ctl_2.Substring(7, 1));
|
||
switch_Model.JBH_CO2_Data = O_C(ctl_2.Substring(8, 1));
|
||
switch_Model.JBH_CO2_Power = O_C(ctl_2.Substring(9, 1));
|
||
switch_Model.JBH_CH4_Data = O_C(ctl_2.Substring(10, 1));
|
||
switch_Model.JBH_CH4_Power = O_C(ctl_2.Substring(11, 1));
|
||
switch_Model.JBH_Adcp_Data = O_C(ctl_2.Substring(12, 1));
|
||
switch_Model.JBH_Adcp_Power = O_C(ctl_2.Substring(13, 1));
|
||
//switch_Model.QB_Adcp150_Data = O_C(ctl_2.Substring(14, 1));
|
||
//switch_Model.QB_Adcp150_Power = O_C(ctl_2.Substring(15, 1));
|
||
switch_Model.QB_Adcp300_Data = O_C(ctl_2.Substring(16, 1));
|
||
switch_Model.QB_Adcp300_Power = O_C(ctl_2.Substring(17, 1));
|
||
switch_Model.FB_Attitude_Data = O_C(ctl_2.Substring(18, 1));
|
||
switch_Model.FB_Attitude_Power = O_C(ctl_2.Substring(19, 1));
|
||
switch_Model.FB_Air_Data = O_C(ctl_2.Substring(20, 1));
|
||
switch_Model.FB_Air_Power = O_C(ctl_2.Substring(21, 1));
|
||
switch_Model.FB_Sailing_CH4_Data = O_C(ctl_2.Substring(22, 1));
|
||
switch_Model.FB_Sailing_CH4_Power = O_C(ctl_2.Substring(23, 1));
|
||
switch_Model.FB_METS_Data = O_C(ctl_2.Substring(24, 1));
|
||
switch_Model.FB_METS_Power = O_C(ctl_2.Substring(25, 1));
|
||
switch_Model.FB_CO2_Data = O_C(ctl_2.Substring(26, 1));
|
||
switch_Model.FB_CO2_Power = O_C(ctl_2.Substring(27, 1));
|
||
switch_Model.FB_CH4_Data = O_C(ctl_2.Substring(28, 1));
|
||
switch_Model.FB_CH4_Power = O_C(ctl_2.Substring(29, 1));
|
||
switch_Model.FB_Adcp_Data = O_C(ctl_2.Substring(30, 1));
|
||
switch_Model.FB_Adcp_Power = O_C(ctl_2.Substring(31, 1));
|
||
}
|
||
ctl = byteList[11].ToString("X2") + byteList[12].ToString("X2") + byteList[13].ToString("X2") + byteList[14].ToString("X2");
|
||
ctl_2 = "";
|
||
for (int i = 0; i < ctl.Length; i++)
|
||
{
|
||
ctl_2 += tools.HexString2BinString(ctl.Substring(i, 1));
|
||
}
|
||
ctl_2 = ctl_2.Replace(" ", "");
|
||
if (ctl_2.Length == 32)
|
||
{
|
||
switch_Model.QB_SSTX_Power = O_C(ctl_2.Substring(25, 1));
|
||
switch_Model.QB_CO2_Data = O_C(ctl_2.Substring(26, 1));
|
||
switch_Model.QB_CO2_Power = O_C(ctl_2.Substring(27, 1));
|
||
switch_Model.QB_METS_Data = O_C(ctl_2.Substring(28, 1));
|
||
switch_Model.QB_METS_Power = O_C(ctl_2.Substring(29, 1));
|
||
switch_Model.QB_CTD_Data = O_C(ctl_2.Substring(30, 1));
|
||
switch_Model.QB_CTD_Power = O_C(ctl_2.Substring(31, 1));
|
||
}
|
||
enviroment_Model.FB_Tem = (float)Convert.ToInt16(byteList[15].ToString("X2") + byteList[16].ToString("X2"), 16) / 1000 * 100;
|
||
enviroment_Model.FB_Hum = (float)Convert.ToInt16(byteList[17].ToString("X2") + byteList[18].ToString("X2"), 16) / 1000 * 100 / 3;
|
||
enviroment_Model.FB_Vol_24_in = (float)Convert.ToInt16(byteList[19].ToString("X2") + byteList[20].ToString("X2"), 16) / 1000 * (float)11.02;
|
||
enviroment_Model.FB_Cur_24_in = (float)Convert.ToInt16(byteList[21].ToString("X2") + byteList[22].ToString("X2"), 16) / 1000 * (float)1.35;
|
||
enviroment_Model.FB_Vol_48_out = (float)Convert.ToInt16(byteList[23].ToString("X2") + byteList[24].ToString("X2"), 16) / 1000 * 21.07f;
|
||
enviroment_Model.FB_Vol_95_out = (float)Convert.ToInt16(byteList[25].ToString("X2") + byteList[26].ToString("X2"), 16) / 1000 * 47.78f;
|
||
enviroment_Model.QB_Tem1 = (float)Convert.ToInt16(byteList[27].ToString("X2") + byteList[28].ToString("X2"), 16) / 1000 * 100;
|
||
enviroment_Model.QB_Tem2 = (float)Convert.ToInt16(byteList[29].ToString("X2") + byteList[30].ToString("X2"), 16) / 1000 * 100;
|
||
enviroment_Model.QB_Hum = (float)Convert.ToInt16(byteList[31].ToString("X2") + byteList[32].ToString("X2"), 16) / 1000 * 100 / 3;
|
||
enviroment_Model.QB_Leak = (float)Convert.ToInt16(byteList[33].ToString("X2") + byteList[34].ToString("X2"), 16);
|
||
enviroment_Model.JBH_Tem1 = (float)Convert.ToInt16(byteList[35].ToString("X2") + byteList[36].ToString("X2"), 16) / 1000 * 100;
|
||
enviroment_Model.JBH_Tem2 = (float)Convert.ToInt16(byteList[37].ToString("X2") + byteList[38].ToString("X2"), 16) / 1000 * 100;
|
||
enviroment_Model.JBH_Hum = (float)Convert.ToInt16(byteList[39].ToString("X2") + byteList[40].ToString("X2"), 16) / 1000 * 100 / 3;
|
||
enviroment_Model.JBH_Leak = (float)Convert.ToInt16(byteList[41].ToString("X2") + byteList[42].ToString("X2"), 16);
|
||
enviroment_Model.JBH_Vol_24V_out = (float)Convert.ToInt16(byteList[43].ToString("X2") + byteList[44].ToString("X2"), 16) / 1000 * (float)11.01;
|
||
enviroment_Model.JBH_Cur_24V_out = (float)Convert.ToInt16(byteList[45].ToString("X2") + byteList[46].ToString("X2"), 16) / 1000 * (float)0.98;
|
||
}
|
||
Mysql.write_ob(enviroment_Model, "enviroment_model");
|
||
tools.Count_rate(7);
|
||
break;
|
||
//传输格式设置
|
||
case 0x05:
|
||
message = "传输格式设置成功";
|
||
if (byteList[6] == Convert.ToInt32(textBox2.Text) && byteList[7] == Convert.ToInt32(textBox3.Text) && byteList[8] == Convert.ToInt32(textBox4.Text) && byteList[9] == Convert.ToInt32(textBox5.Text) && byteList[10] == Convert.ToInt32(textBox6.Text))
|
||
{
|
||
_set_para = true;
|
||
}
|
||
else
|
||
{
|
||
_set_para = false;
|
||
}
|
||
break;
|
||
case 0x0F:
|
||
_start_hour = ((int)byteList[6]).ToString();
|
||
_start_min = ((int)byteList[7]).ToString();
|
||
_timer = ((int)byteList[8]).ToString();
|
||
_time = ((int)byteList[9]).ToString();
|
||
_ADCPJD = ((int)byteList[10]).ToString();
|
||
|
||
_adcp_num = 5;
|
||
break;
|
||
//校时
|
||
case 0x06:
|
||
//UTC时间
|
||
dt = startTime.AddSeconds(Convert.ToInt32(byteList[6].ToString("X2") + byteList[7].ToString("X2") + byteList[8].ToString("X2") + byteList[9].ToString("X2"), 16));
|
||
if ((time_DataBase - dt).TotalMinutes > 60)
|
||
{
|
||
_set_time = true;
|
||
}
|
||
else
|
||
{
|
||
_set_time = false;
|
||
}
|
||
message += "校时成功!";
|
||
break;
|
||
//登录
|
||
case 0x00:
|
||
message += "登录成功!";
|
||
_isConnected = true;
|
||
string send_mes = "EFFE00040100F216";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
break;
|
||
case 0x64:
|
||
switch (byteList[6])
|
||
{
|
||
case 0x00:
|
||
file_request();
|
||
_file_request = "文件请求成功!";
|
||
break;
|
||
case 0x01:
|
||
_file_request = "文件请求失败!";
|
||
break;
|
||
case 0x02:
|
||
_file_request = "当前设备在忙!";
|
||
break;
|
||
case 0x03:
|
||
_file_request = "文件读取越界!";
|
||
break;
|
||
case 0x04:
|
||
_file_request = "没有该文件!";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
message += _file_request;
|
||
break;
|
||
case 0x66:
|
||
//if (byteList[11] != 0xFF)
|
||
//{
|
||
// for (int i = 14; i < byteList.Count - 14; i++)
|
||
// {
|
||
// get_mes += byteList[i].ToString("X2");
|
||
// }
|
||
// get_mes = get_mes.Substring(0, get_mes.Length - 4);
|
||
// Thread.Sleep(2000);
|
||
// file_request();
|
||
// message += "文件请求未完成,继续请求!";
|
||
//}
|
||
//else
|
||
//{
|
||
// for (int i = 14; i < byteList.Count - 14; i++)
|
||
// {
|
||
// get_mes += byteList[i].ToString("X2");
|
||
// }
|
||
// get_mes = get_mes.Substring(0, get_mes.Length - 4);
|
||
// count = 0;
|
||
// Console.WriteLine(get_mes.Length);
|
||
// Console.WriteLine(get_mes);
|
||
// Console.WriteLine(tools.HexStringToString(get_mes, Encoding.UTF8));
|
||
// Invoke((EventHandler)(delegate
|
||
// {
|
||
// tools.AddLgoToTXT(comboBox3.Text, @"D:\文件\", tools.HexStringToString(get_mes, Encoding.UTF8));
|
||
// }));
|
||
|
||
// _file_request = "文件保存成功!";
|
||
// message += "文件请求完成且保存成功!";
|
||
//}
|
||
for (int i = 0; i < byteList.Count - 16; i++)
|
||
{
|
||
get_mes += byteList[i + 14].ToString("X2");
|
||
}
|
||
string aa = tools.HexStringToString(get_mes, Encoding.Default);
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
tools.AddLgoToTXT(comboBox3.Text + dateTimePicker1.Value.ToString("yyyyMMdd") + ".csv", textBox7.Text + dateTimePicker1.Value.ToString("yyyy-MM-dd") + @"\", tools.HexStringToString(get_mes, Encoding.UTF8));
|
||
}));
|
||
get_mes = "";
|
||
if (byteList[11] != 0xFF)
|
||
{
|
||
Thread.Sleep(2000);
|
||
file_request();
|
||
message += "文件请求未完成,继续请求!";
|
||
}
|
||
else
|
||
{
|
||
count = 0;
|
||
_file_request = "文件保存成功!";
|
||
message += "文件请求完成且保存成功!";
|
||
}
|
||
|
||
|
||
break;
|
||
default:
|
||
Console.WriteLine("未能识别功能码!");
|
||
break;
|
||
}
|
||
wirte_textbox(message);
|
||
}
|
||
|
||
//数据写入界面
|
||
private void WritetoPage(object sender)
|
||
{
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
label141.Text = System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
|
||
//获取当前系统时间
|
||
DateTime time_DataBase = DateTime.Now;
|
||
if ((time_DataBase - buoy_Sensor_OthModel.datetime_Sensor).TotalDays < 365)
|
||
groupBox3.Text = "浮标其他传感器 " + buoy_Sensor_OthModel.datetime_Sensor.ToString();
|
||
label28.Text = buoy_Sensor_OthModel.CH4_Pre.ToString("0.00") + "μatm";
|
||
label29.Text = buoy_Sensor_OthModel.CH4_Con.ToString("0.00") + "ppm";
|
||
label31.Text = buoy_Sensor_OthModel.CO2_Pre.ToString("0.00") + "μatm";
|
||
label30.Text = buoy_Sensor_OthModel.CO2_Con.ToString("0.00") + "ppm";
|
||
//label35.Text = buoy_Sensor_OthModel.METS_Meth.ToString("0.00") + "μatm";
|
||
//label34.Text = buoy_Sensor_OthModel.METS_Tem.ToString("0.00") + "℃";
|
||
label55.Text = buoy_Sensor_OthModel.Go_sailing_CH4_Dry.ToString("0.00") + "ppm";
|
||
label54.Text = buoy_Sensor_OthModel.Go_sailing_CH4_C2H6.ToString("0.00") + "ppb";
|
||
label5.Text = buoy_Sensor_OthModel.Go_sailing_CH4_H2O.ToString("0.00") + "ppm";
|
||
label39.Text = buoy_Sensor_OthModel.Air_Tem.ToString("0.00") + "℃";
|
||
label38.Text = buoy_Sensor_OthModel.Air_Hum.ToString("0.00") + "%";
|
||
label42.Text = buoy_Sensor_OthModel.Air_Pre.ToString("0.00") + "Pa";
|
||
label44.Text = buoy_Sensor_OthModel.Wind_Dir.ToString("0.00") + "°";
|
||
label51.Text = buoy_Sensor_OthModel.Wind_Speed.ToString("0.00") + "m/s";
|
||
label50.Text = buoy_Sensor_OthModel.Wind_Speed_Max.ToString("0.00") + "m/s";
|
||
label48.Text = buoy_Sensor_OthModel.Fzd.ToString("0.00") + ""; //辐照度单位
|
||
label46.Text = buoy_Sensor_OthModel.RainFall.ToString("0.00") + "inches";
|
||
label67.Text = buoy_Sensor_OthModel.Tem.ToString("0.00") + "℃";
|
||
label66.Text = buoy_Sensor_OthModel.Hum.ToString("0.00") + "%";
|
||
label64.Text = buoy_Sensor_OthModel.Vol_24_in.ToString("0.00") + "V";
|
||
label61.Text = buoy_Sensor_OthModel.Cur_24_in.ToString("0.00") + "A";
|
||
label60.Text = buoy_Sensor_OthModel.Vol_48_out.ToString("0.00") + "V";
|
||
label58.Text = buoy_Sensor_OthModel.Vol_95_out.ToString("0.00") + "V";
|
||
|
||
label89.Text = enviroment_Model.FB_Tem.ToString("0.00") + "℃";
|
||
label90.Text = enviroment_Model.FB_Hum.ToString("0.00") + "%";
|
||
label91.Text = enviroment_Model.FB_Vol_24_in.ToString("0.00") + "V";
|
||
label92.Text = enviroment_Model.FB_Cur_24_in.ToString("0.00") + "A";
|
||
label93.Text = enviroment_Model.FB_Vol_48_out.ToString("0.00") + "V";
|
||
label94.Text = enviroment_Model.FB_Vol_95_out.ToString("0.00") + "V";
|
||
label95.Text = enviroment_Model.JBH_Tem1.ToString("0.00") + "℃";
|
||
label96.Text = enviroment_Model.JBH_Tem2.ToString("0.00") + "℃";
|
||
label97.Text = enviroment_Model.JBH_Vol_24V_out.ToString("0.00") + "V";
|
||
label104.Text = enviroment_Model.JBH_Hum.ToString("0.00") + "%";
|
||
label103.Text = enviroment_Model.JBH_Leak.ToString("0.00") + "V";
|
||
label102.Text = enviroment_Model.JBH_Cur_24V_out.ToString("0.00") + "A";
|
||
label108.Text = enviroment_Model.QB_Tem1.ToString("0.00") + "℃";
|
||
label107.Text = enviroment_Model.QB_Tem2.ToString("0.00") + "℃";
|
||
label105.Text = enviroment_Model.QB_Hum.ToString("0.00") + "%";
|
||
label106.Text = enviroment_Model.QB_Leak.ToString("0.00") + "V";
|
||
if ((time_DataBase - conbox_Sensor_OthModel.datetime_Sensor).TotalDays < 365)
|
||
groupBox15.Text = "接驳盒其他传感器 " + conbox_Sensor_OthModel.datetime_Sensor.ToString();
|
||
label127.Text = conbox_Sensor_OthModel.CH4_Pre.ToString("0.00") + "μatm";
|
||
label126.Text = conbox_Sensor_OthModel.CH4_Con.ToString("0.00") + "ppm";
|
||
label123.Text = conbox_Sensor_OthModel.CO2_Pre.ToString("0.00") + "μatm";
|
||
label122.Text = conbox_Sensor_OthModel.CO2_Con.ToString("0.00") + "ppm";
|
||
label119.Text = conbox_Sensor_OthModel.METS_Meth.ToString("0.00") + "μatm";
|
||
label118.Text = conbox_Sensor_OthModel.METS_Tem.ToString("0.00") + "℃";
|
||
label99.Text = conbox_Sensor_OthModel.Angle_sensor_x.ToString("0.00") + "°";
|
||
label98.Text = conbox_Sensor_OthModel.Angle_sensor_y.ToString("0.00") + "°";
|
||
label2.Text = conbox_Sensor_OthModel.Angle_sensor_z.ToString("0.00") + "°";
|
||
label115.Text = conbox_Sensor_OthModel.CTD_Tem.ToString("0.00") + "℃";
|
||
label114.Text = conbox_Sensor_OthModel.CTD_Con.ToString("0.00") + "s/m";
|
||
label112.Text = conbox_Sensor_OthModel.CTD_Pre.ToString("0.00") + "dbar";
|
||
label130.Text = conbox_Sensor_OthModel.CTD_YLS.ToString("0.00") + "mg/L";
|
||
label132.Text = conbox_Sensor_OthModel.CTD_ZD.ToString("0.00") + "ppt";
|
||
label134.Text = conbox_Sensor_OthModel.CTD_Rjy.ToString("0.00") + "mg/L";
|
||
|
||
|
||
//浮标姿态
|
||
if (!string.IsNullOrEmpty(buoy_Sensor_AttitudeModel.Attitude_sensor))
|
||
textBox8.AppendText(time_DataBase + "\r\n" + (buoy_Sensor_AttitudeModel.Attitude_sensor.Contains("$") ? buoy_Sensor_AttitudeModel.Attitude_sensor.Split('$')[1] : buoy_Sensor_AttitudeModel.Attitude_sensor) + "\r\n");
|
||
//浮标ADCP-WSH300
|
||
|
||
label71.Text = buoy_Sensor_AdcpModel.Adcp_Pre.ToString() + "μatm";
|
||
label70.Text = buoy_Sensor_AdcpModel.Adcp_Ysb.ToString() + "%";
|
||
if (_adcp_num == 1)
|
||
{
|
||
if (!string.IsNullOrEmpty(buoy_Sensor_AdcpModel.Adcp_VD.ToString()))
|
||
textBox9.AppendText(buoy_Sensor_AdcpModel.datetime_Sensor + "\r\n" + buoy_Sensor_AdcpModel.Adcp_VD.ToString() + "\r\n");
|
||
_adcp_num = 0;
|
||
}
|
||
|
||
//潜标ADCP-WSH300
|
||
label83.Text = lattarget_Sensor_Adcp300Model.Adcp_Pre.ToString() + "μatm";
|
||
label82.Text = lattarget_Sensor_Adcp300Model.Adcp_Ysb.ToString() + "%";
|
||
if (_adcp_num == 3)
|
||
{
|
||
if (!string.IsNullOrEmpty(lattarget_Sensor_Adcp300Model.Adcp_VD.ToString()))
|
||
textBox12.AppendText(lattarget_Sensor_Adcp300Model.datetime_Sensor + "\r\n" + lattarget_Sensor_Adcp300Model.Adcp_VD.ToString() + "\r\n");
|
||
_adcp_num = 0;
|
||
}
|
||
|
||
//潜标其他传感器
|
||
label79.Text = lattarget_Sensor_Oth.CO2_Pre.ToString("0.00") + "μatm";
|
||
label78.Text = lattarget_Sensor_Oth.CO2_Con.ToString("0.00") + "ppm";
|
||
label137.Text = lattarget_Sensor_Oth.METS_Meth.ToString("0.00") + "μatm";
|
||
label136.Text = lattarget_Sensor_Oth.METS_Tem.ToString("0.00") + "℃";
|
||
label157.Text = lattarget_Sensor_Oth.CTD_Tem.ToString("0.00") + "℃";
|
||
label156.Text = lattarget_Sensor_Oth.CTD_Con.ToString("0.00") + "s/m";
|
||
label154.Text = lattarget_Sensor_Oth.CTD_Pre.ToString("0.00") + "dbar";
|
||
label152.Text = lattarget_Sensor_Oth.CTD_YLS.ToString("0.00") + "mg/L";
|
||
label150.Text = lattarget_Sensor_Oth.CTD_ZD.ToString("0.00") + "ppt";
|
||
label148.Text = lattarget_Sensor_Oth.CTD_Rjy.ToString("0.00") + "mg/L";
|
||
label34.Text = lattarget_Sensor_Oth.Angle_sensor_x.ToString("0.00") + "°";
|
||
label35.Text = lattarget_Sensor_Oth.Angle_sensor_y.ToString("0.00") + "°";
|
||
label36.Text = lattarget_Sensor_Oth.Angle_sensor_z.ToString("0.00") + "°";
|
||
|
||
//接驳盒ADCP-WSH300
|
||
label75.Text = conbox_Sensor_AdcpModel.Adcp_Pre.ToString() + "μatm";
|
||
label74.Text = conbox_Sensor_AdcpModel.Adcp_Ysb.ToString() + "%";
|
||
if (_adcp_num == 4)
|
||
{
|
||
if (!string.IsNullOrEmpty(conbox_Sensor_AdcpModel.Adcp_VD.ToString()))
|
||
textBox10.AppendText(conbox_Sensor_AdcpModel.datetime_Sensor + "\r\n" + conbox_Sensor_AdcpModel.Adcp_VD.ToString() + "\r\n");
|
||
_adcp_num = 0;
|
||
}
|
||
|
||
if (_adcp_num == 5)
|
||
{
|
||
textBox2.Text = _start_hour;
|
||
textBox3.Text = _start_min;
|
||
textBox4.Text = _timer;
|
||
textBox5.Text = _time;
|
||
textBox6.Text = _ADCPJD;
|
||
|
||
_adcp_num = 0;
|
||
}
|
||
|
||
//开关量
|
||
button10.Text = O_C_Power(switch_Model.FB_CH4_Power); button10.BackColor = O_C_Color(switch_Model.FB_CH4_Power);
|
||
button33.Text = O_C_Data(switch_Model.FB_CH4_Data); button33.BackColor = O_C_Color(switch_Model.FB_CH4_Data);
|
||
button11.Text = O_C_Power(switch_Model.FB_CO2_Power); button11.BackColor = O_C_Color(switch_Model.FB_CO2_Power);
|
||
button32.Text = O_C_Data(switch_Model.FB_CO2_Data); button32.BackColor = O_C_Color(switch_Model.FB_CO2_Data);
|
||
//button13.Text = O_C_Power(switch_Model.FB_METS_Power); button13.BackColor = O_C_Color(switch_Model.FB_METS_Power);
|
||
//button30.Text = O_C_Data(switch_Model.FB_METS_Data); button30.BackColor = O_C_Color(switch_Model.FB_METS_Data);
|
||
button14.Text = O_C_Power(switch_Model.FB_Sailing_CH4_Power); button14.BackColor = O_C_Color(switch_Model.FB_Sailing_CH4_Power);
|
||
button29.Text = O_C_Data(switch_Model.FB_Sailing_CH4_Data); button29.BackColor = O_C_Color(switch_Model.FB_Sailing_CH4_Data);
|
||
//button15.Text = O_C_Power(switch_Model.FB_Air_Power); button15.BackColor = O_C_Color(switch_Model.FB_Air_Power);
|
||
//button28.Text = O_C_Data(switch_Model.FB_Air_Data); button28.BackColor = O_C_Color(switch_Model.FB_Air_Data);
|
||
button12.Text = O_C_Power(switch_Model.FB_CTD_Power); button12.BackColor = O_C_Color(switch_Model.FB_CTD_Power);
|
||
button31.Text = O_C_Data(switch_Model.FB_CTD_Data); button31.BackColor = O_C_Color(switch_Model.FB_CTD_Data);
|
||
button17.Text = O_C_Power(switch_Model.FB_Attitude_Power); button17.BackColor = O_C_Color(switch_Model.FB_Attitude_Power);
|
||
button24.Text = O_C_Data(switch_Model.FB_Attitude_Data); button24.BackColor = O_C_Color(switch_Model.FB_Attitude_Data);
|
||
button16.Text = O_C_Power(switch_Model.FB_Adcp_Power); button16.BackColor = O_C_Color(switch_Model.FB_Adcp_Power);
|
||
button25.Text = O_C_Data(switch_Model.FB_Adcp_Data); button25.BackColor = O_C_Color(switch_Model.FB_Adcp_Data);
|
||
button3.Text = O_C_Power(switch_Model.JBH_CH4_Power); button3.BackColor = O_C_Color(switch_Model.JBH_CH4_Power);
|
||
button22.Text = O_C_Data(switch_Model.JBH_CH4_Data); button22.BackColor = O_C_Color(switch_Model.JBH_CH4_Data);
|
||
button4.Text = O_C_Power(switch_Model.JBH_CO2_Power); button4.BackColor = O_C_Color(switch_Model.JBH_CO2_Power);
|
||
button21.Text = O_C_Data(switch_Model.JBH_CO2_Data); button21.BackColor = O_C_Color(switch_Model.JBH_CO2_Data);
|
||
button5.Text = O_C_Power(switch_Model.JBH_METS_Power); button5.BackColor = O_C_Color(switch_Model.JBH_METS_Power);
|
||
button20.Text = O_C_Data(switch_Model.JBH_METS_Data); button20.BackColor = O_C_Color(switch_Model.JBH_METS_Data);
|
||
button7.Text = O_C_Power(switch_Model.JBH_Attitude_Power); button7.BackColor = O_C_Color(switch_Model.JBH_Attitude_Power);
|
||
button18.Text = O_C_Data(switch_Model.JBH_Attitude_Data); button18.BackColor = O_C_Color(switch_Model.JBH_Attitude_Data);
|
||
button6.Text = O_C_Power(switch_Model.JBH_CTD_Power); button6.BackColor = O_C_Color(switch_Model.JBH_CTD_Power);
|
||
button19.Text = O_C_Data(switch_Model.JBH_CTD_Data); button19.BackColor = O_C_Color(switch_Model.JBH_CTD_Data);
|
||
button2.Text = O_C_Power(switch_Model.JBH_Adcp_Power); button2.BackColor = O_C_Color(switch_Model.JBH_Adcp_Power);
|
||
button23.Text = O_C_Data(switch_Model.JBH_Adcp_Data); button23.BackColor = O_C_Color(switch_Model.JBH_Adcp_Data);
|
||
button8.Text = O_C_Power(switch_Model.QB_Adcp300_Power); button8.BackColor = O_C_Color(switch_Model.QB_Adcp300_Power);
|
||
button27.Text = O_C_Data(switch_Model.QB_Adcp300_Data); button27.BackColor = O_C_Color(switch_Model.QB_Adcp300_Data);
|
||
button26.Text = O_C_Power(switch_Model.QB_CO2_Power); button26.BackColor = O_C_Color(switch_Model.QB_CO2_Power);
|
||
button9.Text = O_C_Data(switch_Model.QB_CO2_Data); button9.BackColor = O_C_Color(switch_Model.QB_CO2_Data);
|
||
button48.Text = O_C_Power(switch_Model.QB_METS_Power); button48.BackColor = O_C_Color(switch_Model.QB_METS_Power);
|
||
button37.Text = O_C_Data(switch_Model.QB_METS_Data); button37.BackColor = O_C_Color(switch_Model.QB_METS_Data);
|
||
button50.Text = O_C_Power(switch_Model.QB_CTD_Power); button50.BackColor = O_C_Color(switch_Model.QB_CTD_Power);
|
||
button49.Text = O_C_Data(switch_Model.QB_CTD_Data); button49.BackColor = O_C_Color(switch_Model.QB_CTD_Data);
|
||
button52.Text = O_C_Power(switch_Model.QB_SSTX_Power); button52.BackColor = O_C_Color(switch_Model.QB_SSTX_Power);
|
||
|
||
if (_set_para)
|
||
label6.Text = "设置成功!";
|
||
if (_set_time) { label110.Text = "时间同步成功!"; }
|
||
else
|
||
{
|
||
label110.Text = "时间未同步!";
|
||
}
|
||
//文件同步状态
|
||
label109.Text = _file_request;
|
||
}));
|
||
}
|
||
string get_mes = null;
|
||
int count = 0;
|
||
//读取的长度
|
||
int len = 512;
|
||
//文件请求
|
||
public void file_request()
|
||
{
|
||
//读取的起始位
|
||
int start = 0 + count * len;
|
||
count++;
|
||
string str = "FEEF000A0066" + start.ToString("X2").PadLeft(8, '0') + len.ToString("X2").PadLeft(4, '0');
|
||
string[] array = new string[12];
|
||
for (int i = 0; i < str.Length; i += 2)
|
||
{
|
||
array[i / 2] = str.Substring(i, 2);
|
||
}
|
||
int sum = 0;
|
||
foreach (string arrayElement in array)
|
||
{
|
||
sum += int.Parse(arrayElement, System.Globalization.NumberStyles.HexNumber);
|
||
}
|
||
sum = sum & 0xFF;
|
||
str = "FEEF000A0066" + start.ToString("X2").PadLeft(8, '0') + len.ToString("X2").PadLeft(4, '0') + sum.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(str);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
|
||
//打开串口
|
||
public void open_port()
|
||
{
|
||
if (string.IsNullOrEmpty(comboBox2.Text))
|
||
{
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
MessageBox.Show("请检查串口名称!!!");
|
||
}));
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(comboBox1.Text))
|
||
{
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
MessageBox.Show("请检查波特率!!!");
|
||
}));
|
||
return;
|
||
}
|
||
serialPort1.PortName = comboBox2.Text;
|
||
serialPort1.BaudRate = int.Parse(comboBox1.Text);
|
||
serialPort1.Parity = Parity.None;
|
||
serialPort1.DataBits = 8;
|
||
serialPort1.StopBits = StopBits.One;
|
||
serialPort1.ReceivedBytesThreshold = 1;
|
||
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
|
||
try
|
||
{
|
||
serialPort1.Open();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
MessageBox.Show("串口打开失败!请检查串口配置!");
|
||
}));
|
||
return;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
public void wirte_textbox(string rec_16)
|
||
{
|
||
//获取当前系统时间
|
||
DateTime time_DataBase = DateTime.Now;
|
||
Invoke((EventHandler)(delegate
|
||
{
|
||
textBox1.AppendText(time_DataBase + ":" + rec_16 + "\r\n" + "\r\n");
|
||
}));
|
||
}
|
||
/// <summary>
|
||
/// 串口数据发送
|
||
/// </summary>
|
||
/// <param name="kind">数据类型</param>
|
||
/// <param name="ack">bool类型 00/01</param>
|
||
public void send_port(string kind, string ack)
|
||
{
|
||
string send_mes = "EFFE00060002" + kind + ack + "0816";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开关按钮
|
||
/// </summary>
|
||
/// <param name="kind"></param>
|
||
/// <param name="id">传感器id</param>
|
||
/// <param name="btn">开还是关 01 00</param>
|
||
public void send_port_btn(int kind, int id, int btn, int act)
|
||
{
|
||
int a = 0xFE + 0xEF + 0x00 + 0x09 + 0x00 + 0x03 + 0x01 + kind + id + btn + act;
|
||
//取十六进制最低两位
|
||
a = a & 0xFF;
|
||
string send_mes = "FEEF0009000301" + kind.ToString("X2") + id.ToString("X2") + btn.ToString("X2") + act.ToString("X2") + a.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 串口数据发送 手动开关量
|
||
/// </summary>
|
||
/// <param name="kind"></param>
|
||
/// <param name="id"></param>
|
||
/// <param name="btn"></param>
|
||
public void send_port_hand(int kind)
|
||
{
|
||
int a = 0xFE + 0xEF + 0x00 + 0x06 + 0x00 + 0x02 + kind + 0xFF;
|
||
//取十六进制最低两位
|
||
a = a & 0xFF;
|
||
string send_mes = "FEEF00060002" + kind.ToString("X2") + "FF" + a.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
/// <summary>
|
||
/// 参数设置
|
||
/// </summary>
|
||
/// <param name="len"></param>
|
||
/// <param name="data"></param>
|
||
/// <param name="data_int"></param>
|
||
public void send_port_set(int len, string data, List<int> data_int, int function)
|
||
{
|
||
int a = 0xFE + 0xEF + 4 + len / 2 + 0x00 + function;
|
||
if (data_int != null)
|
||
{
|
||
for (int i = 0; i < data_int.Count; i++)
|
||
{
|
||
a += data_int[i];
|
||
}
|
||
}
|
||
|
||
//取十六进制最低两位
|
||
a = a & 0xFF;
|
||
string send_mes = "FEEF00" + (4 + len / 2).ToString("X2") + "00" + function.ToString("X2") + data + a.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
/// <summary>
|
||
/// 参数查询
|
||
/// </summary>
|
||
/// <param name="len"></param>
|
||
/// <param name="data"></param>
|
||
/// <param name="data_int"></param>
|
||
public void select_port_set(int len, string data, List<int> data_int)
|
||
{
|
||
int a = 0xFE + 0xEF + 4 + len / 2 + 0x00 + 0x05;
|
||
for (int i = 0; i < data_int.Count; i++)
|
||
{
|
||
a += data_int[i];
|
||
}
|
||
//取十六进制最低两位
|
||
a = a & 0xFF;
|
||
string send_mes = "FEEF00" + (4 + len / 2).ToString("X2") + "0005" + data + a.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
public void send_port_time(string time)
|
||
{
|
||
byte[] time_byte = tools.ConvertHexStringToBytes(time);
|
||
int a = 0xFE + 0xEF + 0x00 + 0x08 + 0x00 + 0x06;
|
||
for (int i = 0; i < time_byte.Length; i++)
|
||
{
|
||
a += time_byte[i];
|
||
}
|
||
//取十六进制最低两位
|
||
a = a & 0xFF;
|
||
string send_mes = "FEEF00080006" + time + a.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(send_mes);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
}
|
||
private bool O_C_Byte(byte O_C_Byte)
|
||
{
|
||
if (O_C_Byte == 0x00)
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
private bool O_C(string o_c)
|
||
{
|
||
if (o_c.Equals("0"))
|
||
{
|
||
return false;
|
||
}
|
||
else if (o_c.Equals("1"))
|
||
{
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
private string O_C_Power(bool O_C_Power)
|
||
{
|
||
if (O_C_Power)
|
||
{
|
||
return "电源关";
|
||
}
|
||
return "电源开";
|
||
}
|
||
private string O_C_Data(bool O_C_Data)
|
||
{
|
||
if (O_C_Data)
|
||
{
|
||
return "数据关";
|
||
}
|
||
return "数据开";
|
||
}
|
||
private Color O_C_Color(bool O_C_Color)
|
||
{
|
||
if (O_C_Color)
|
||
{
|
||
return Color.Green;
|
||
}
|
||
return Color.Gray;
|
||
}
|
||
|
||
//串口打开关闭
|
||
private void button1_Click(object sender, EventArgs e)
|
||
{
|
||
if (button1.Text == "打开串口")
|
||
{
|
||
open_port();
|
||
if (serialPort1.IsOpen == true)
|
||
{
|
||
button1.Text = "关闭串口";
|
||
groupBox3.Enabled = true;
|
||
groupBox15.Enabled = true;
|
||
groupBox12.Enabled = true;
|
||
groupBox11.Enabled = true;
|
||
groupBox2.Enabled = true;
|
||
groupBox23.Enabled = true;
|
||
groupBox22.Enabled = true;
|
||
groupbox24.Enabled = true;
|
||
groupBox9.Enabled = true;
|
||
groupBox10.Enabled = true;
|
||
groupBox13.Enabled = true;
|
||
groupBox27.Enabled = true;
|
||
groupBox28.Enabled = true;
|
||
groupBox29.Enabled = true;
|
||
comboBox1.Enabled = false;
|
||
this.comboBox2.Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("串口未打开,请检查串口是否已被占用!");
|
||
return;
|
||
}
|
||
wirte_textbox("打开串口!");
|
||
}
|
||
else
|
||
{
|
||
serialPort1.Close();
|
||
if (serialPort1.IsOpen == false)
|
||
{
|
||
button1.Text = "打开串口";
|
||
groupBox3.Enabled = false;
|
||
groupBox15.Enabled = false;
|
||
groupBox12.Enabled = false;
|
||
groupBox11.Enabled = false;
|
||
groupBox2.Enabled = false;
|
||
groupBox23.Enabled = false;
|
||
groupBox22.Enabled = false;
|
||
groupbox24.Enabled = false;
|
||
groupBox13.Enabled = false;
|
||
groupBox27.Enabled = false;
|
||
groupBox28.Enabled = false;
|
||
groupBox29.Enabled = false;
|
||
comboBox1.Enabled = true;
|
||
this.comboBox2.Enabled = true;
|
||
}
|
||
else
|
||
{
|
||
serialPort1.Dispose();
|
||
MessageBox.Show("串口未正常关闭,已释放串口的所有资源!");
|
||
return;
|
||
}
|
||
wirte_textbox("关闭串口!");
|
||
}
|
||
}
|
||
|
||
|
||
//设置按钮
|
||
private void button41_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBox2.Text) || string.IsNullOrEmpty(textBox3.Text) || string.IsNullOrEmpty(textBox4.Text) || string.IsNullOrEmpty(textBox5.Text) || string.IsNullOrEmpty(textBox6.Text))
|
||
{
|
||
MessageBox.Show("请检查输入框!");
|
||
return;
|
||
}
|
||
string set = int.Parse(textBox2.Text).ToString("X2") + int.Parse(textBox3.Text).ToString("X2") + int.Parse(textBox4.Text).ToString("X2") + int.Parse(textBox5.Text).ToString("X2") + int.Parse(textBox6.Text).ToString("X2");
|
||
List<int> set_int = new List<int>();
|
||
set_int.Add(int.Parse(textBox2.Text));
|
||
set_int.Add(int.Parse(textBox3.Text));
|
||
set_int.Add(int.Parse(textBox4.Text));
|
||
set_int.Add(int.Parse(textBox5.Text));
|
||
set_int.Add(int.Parse(textBox6.Text));
|
||
send_port_set(set.Length, set, set_int, 5);
|
||
wirte_textbox("设置了系统时间!");
|
||
}
|
||
private void button43_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_set(0, "", null, 15);
|
||
wirte_textbox("读取系统时间!");
|
||
}
|
||
//同步时间
|
||
private void button42_Click(object sender, EventArgs e)
|
||
{
|
||
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||
send_port_time(Convert.ToInt64(ts.TotalSeconds).ToString("X2"));
|
||
wirte_textbox("同步了系统时间!");
|
||
}
|
||
|
||
private void button44_Click(object sender, EventArgs e)
|
||
{
|
||
if (!System.IO.Directory.Exists(textBox7.Text + dateTimePicker1.Value.ToString("yyyy-MM-dd") + @"\"))
|
||
{
|
||
Directory.CreateDirectory(textBox7.Text + dateTimePicker1.Value.ToString("yyyy-MM-dd") + @"\");
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(comboBox3.Text))
|
||
{
|
||
MessageBox.Show("请先选择文件名称!");
|
||
return;
|
||
}
|
||
string str = comboBox3.Text + dateTimePicker1.Value.ToString("yyyyMMdd") + ".csv";
|
||
byte[] bytetest = System.Text.Encoding.Default.GetBytes(str.ToString());
|
||
byte[] time_byte = tools.ConvertHexStringToBytes(tools.byteToHexStr(bytetest));
|
||
int a = 0xFE + 0xEF + 0x00 + 0x04 + tools.byteToHexStr(bytetest).Length / 2 + 0x00 + 0x64;
|
||
for (int i = 0; i < time_byte.Length; i++)
|
||
{
|
||
a += time_byte[i];
|
||
}
|
||
//取十六进制最低两位
|
||
a = a & 0xFF;
|
||
str = "FEEF00160064" + tools.byteToHexStr(bytetest) + a.ToString("X2") + "16";
|
||
byte[] bytea = tools.ConvertHexStringToBytes(str);
|
||
serialPort1.Write(bytea, 0, bytea.Length);
|
||
wirte_textbox("发送了一次" + comboBox3.Text + dateTimePicker1.Value.ToString("yyyyMMdd") + ".csv" + "文件请求!");
|
||
}
|
||
|
||
private void button45_Click(object sender, EventArgs e)
|
||
{
|
||
byte[] bytes = BitConverter.GetBytes(Convert.ToInt32("3FB5C28F", 16));
|
||
float b = BitConverter.ToSingle(bytes, 0);
|
||
//AT+CSQ\r\n
|
||
//41 54 2B 43 53 51 0D 0A
|
||
byte[] a = tools.ConvertHexStringToBytes("41 54 2B 43 53 51 0D 0A");
|
||
serialPort1.Write(a, 0, a.Length);
|
||
}
|
||
|
||
private void button46_Click(object sender, EventArgs e)
|
||
{
|
||
//ATD00881693818244\r\n
|
||
byte[] a = tools.ConvertHexStringToBytes("41 54 44 30 30 38 38 31 36 39 33 38 31 38 32 34 34 0D 0A");
|
||
serialPort1.Write(a, 0, a.Length);
|
||
}
|
||
//断开连接
|
||
private void button13_Click(object sender, EventArgs e)
|
||
{
|
||
byte[] a = System.Text.Encoding.ASCII.GetBytes("+++");
|
||
serialPort1.Write(a, 0, a.Length);
|
||
}
|
||
|
||
private void button2_Click(object sender, EventArgs e)
|
||
{
|
||
if (button2.Text == "电源开")
|
||
{
|
||
send_port_btn(31, 00, 01, 00);
|
||
wirte_textbox("接驳盒ADCP300电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(31, 00, 00, 00);
|
||
wirte_textbox("接驳盒ADCP300电源关!");
|
||
}
|
||
private void button23_Click(object sender, EventArgs e)
|
||
{
|
||
if (button23.Text == "数据开")
|
||
{
|
||
send_port_btn(31, 00, 01, 01);
|
||
wirte_textbox("接驳盒ADCP300数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(31, 00, 00, 01);
|
||
wirte_textbox("接驳盒ADCP300数据关!");
|
||
}
|
||
|
||
private void button3_Click(object sender, EventArgs e)
|
||
{
|
||
if (button3.Text == "电源开")
|
||
{
|
||
send_port_btn(30, 01, 01, 00);
|
||
wirte_textbox("接驳盒甲烷电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 01, 00, 00);
|
||
wirte_textbox("接驳盒甲烷电源关!");
|
||
}
|
||
|
||
private void button22_Click(object sender, EventArgs e)
|
||
{
|
||
if (button22.Text == "数据开")
|
||
{
|
||
send_port_btn(30, 01, 01, 01);
|
||
wirte_textbox("接驳盒甲烷数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 01, 00, 01);
|
||
wirte_textbox("接驳盒甲烷数据关!");
|
||
}
|
||
|
||
private void button4_Click(object sender, EventArgs e)
|
||
{
|
||
if (button4.Text == "电源开")
|
||
{
|
||
send_port_btn(30, 02, 01, 00);
|
||
wirte_textbox("接驳盒二氧化碳电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 02, 00, 00);
|
||
wirte_textbox("接驳盒二氧化碳电源关!");
|
||
}
|
||
|
||
private void button21_Click(object sender, EventArgs e)
|
||
{
|
||
if (button21.Text == "数据开")
|
||
{
|
||
send_port_btn(30, 02, 01, 01);
|
||
wirte_textbox("接驳盒二氧化碳数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 02, 00, 01);
|
||
wirte_textbox("接驳盒二氧化碳数据关!");
|
||
}
|
||
|
||
private void button5_Click(object sender, EventArgs e)
|
||
{
|
||
if (button5.Text == "电源开")
|
||
{
|
||
send_port_btn(30, 03, 01, 00);
|
||
wirte_textbox("接驳盒METS电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 03, 00, 00);
|
||
wirte_textbox("接驳盒METS电源关!");
|
||
}
|
||
|
||
private void button20_Click(object sender, EventArgs e)
|
||
{
|
||
if (button20.Text == "数据开")
|
||
{
|
||
send_port_btn(30, 03, 01, 01);
|
||
wirte_textbox("接驳盒METS数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 03, 00, 01);
|
||
wirte_textbox("接驳盒METS数据关!");
|
||
}
|
||
|
||
private void button6_Click(object sender, EventArgs e)
|
||
{
|
||
if (button6.Text == "电源开")
|
||
{
|
||
send_port_btn(30, 04, 01, 00);
|
||
wirte_textbox("接驳盒CTD电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 04, 00, 00);
|
||
wirte_textbox("接驳盒CTD电源关!");
|
||
}
|
||
|
||
private void button19_Click(object sender, EventArgs e)
|
||
{
|
||
if (button19.Text == "数据开")
|
||
{
|
||
send_port_btn(30, 04, 01, 01);
|
||
wirte_textbox("接驳盒CTD数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 04, 00, 01);
|
||
wirte_textbox("接驳盒CTD数据关!");
|
||
}
|
||
|
||
private void button7_Click(object sender, EventArgs e)
|
||
{
|
||
if (button7.Text == "电源开")
|
||
{
|
||
send_port_btn(30, 05, 01, 00);
|
||
wirte_textbox("接驳盒倾角电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 05, 00, 00);
|
||
wirte_textbox("接驳盒倾角电源关!");
|
||
}
|
||
|
||
private void button18_Click(object sender, EventArgs e)
|
||
{
|
||
if (button18.Text == "数据开")
|
||
{
|
||
send_port_btn(30, 05, 01, 01);
|
||
wirte_textbox("接驳盒倾角数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(30, 05, 00, 01);
|
||
wirte_textbox("接驳盒倾角数据关!");
|
||
}
|
||
|
||
private void button8_Click(object sender, EventArgs e)
|
||
{
|
||
if (button8.Text == "电源开")
|
||
{
|
||
send_port_btn(21, 00, 01, 00);
|
||
wirte_textbox("潜标ADCP300电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(21, 00, 00, 00);
|
||
wirte_textbox("潜标ADCP300电源关!");
|
||
}
|
||
|
||
private void button27_Click(object sender, EventArgs e)
|
||
{
|
||
if (button27.Text == "数据开")
|
||
{
|
||
send_port_btn(21, 00, 01, 01);
|
||
wirte_textbox("潜标ADCP300数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(21, 00, 00, 01);
|
||
wirte_textbox("潜标ADCP300数据关!");
|
||
}
|
||
|
||
private void button9_Click(object sender, EventArgs e)
|
||
{
|
||
if (button9.Text == "电源开")
|
||
{
|
||
send_port_btn(23, 01, 01, 00);
|
||
wirte_textbox("潜标ADCP150电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(23, 01, 00, 00);
|
||
wirte_textbox("潜标ADCP150电源关!");
|
||
}
|
||
|
||
private void button26_Click(object sender, EventArgs e)
|
||
{
|
||
if (button26.Text == "数据开")
|
||
{
|
||
send_port_btn(23, 01, 01, 01);
|
||
wirte_textbox("潜标ADCP150数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(23, 01, 00, 01);
|
||
wirte_textbox("潜标ADCP150数据关!");
|
||
}
|
||
|
||
private void button10_Click(object sender, EventArgs e)
|
||
{
|
||
if (button10.Text == "电源开")
|
||
{
|
||
send_port_btn(10, 01, 01, 00);
|
||
wirte_textbox("浮标甲烷电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 01, 00, 00);
|
||
wirte_textbox("浮标甲烷电源关!");
|
||
}
|
||
|
||
private void button33_Click(object sender, EventArgs e)
|
||
{
|
||
if (button33.Text == "数据开")
|
||
{
|
||
send_port_btn(10, 01, 01, 01);
|
||
wirte_textbox("浮标甲烷数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 01, 00, 01);
|
||
wirte_textbox("浮标甲烷数据关!");
|
||
}
|
||
|
||
private void button11_Click(object sender, EventArgs e)
|
||
{
|
||
if (button11.Text == "电源开")
|
||
{
|
||
send_port_btn(10, 02, 01, 00);
|
||
wirte_textbox("浮标二氧化碳电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 02, 00, 00);
|
||
wirte_textbox("浮标二氧化碳电源关!");
|
||
}
|
||
|
||
private void button32_Click(object sender, EventArgs e)
|
||
{
|
||
if (button32.Text == "数据开")
|
||
{
|
||
send_port_btn(10, 02, 01, 01);
|
||
wirte_textbox("浮标CO2数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 02, 00, 01);
|
||
wirte_textbox("浮标CO2数据关!");
|
||
}
|
||
|
||
|
||
|
||
private void button12_Click(object sender, EventArgs e)
|
||
{
|
||
if (button12.Text == "电源开")
|
||
{
|
||
send_port_btn(10, 04, 01, 00);
|
||
wirte_textbox("浮标CTD电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 04, 00, 00);
|
||
wirte_textbox("浮标CTD电源关!");
|
||
}
|
||
|
||
private void button31_Click(object sender, EventArgs e)
|
||
{
|
||
if (button31.Text == "数据开")
|
||
{
|
||
send_port_btn(10, 04, 01, 01);
|
||
wirte_textbox("浮标CTD数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 04, 00, 01);
|
||
wirte_textbox("浮标CTD数据关!");
|
||
}
|
||
|
||
private void button14_Click(object sender, EventArgs e)
|
||
{
|
||
if (button14.Text == "电源开")
|
||
{
|
||
send_port_btn(10, 06, 01, 00);
|
||
wirte_textbox("浮标走航甲烷电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 06, 00, 00);
|
||
wirte_textbox("浮标走航甲烷电源关!");
|
||
}
|
||
|
||
private void button29_Click(object sender, EventArgs e)
|
||
{
|
||
if (button29.Text == "数据开")
|
||
{
|
||
send_port_btn(10, 06, 01, 01);
|
||
wirte_textbox("浮标走航甲烷数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(10, 06, 00, 01);
|
||
wirte_textbox("浮标走航甲烷数据关!");
|
||
}
|
||
|
||
|
||
private void button16_Click(object sender, EventArgs e)
|
||
{
|
||
if (button16.Text == "电源开")
|
||
{
|
||
send_port_btn(11, 00, 01, 00);
|
||
wirte_textbox("浮标ADCP300电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(11, 00, 00, 00);
|
||
wirte_textbox("浮标ADCP300电源关!");
|
||
}
|
||
|
||
private void button25_Click(object sender, EventArgs e)
|
||
{
|
||
if (button25.Text == "数据开")
|
||
{
|
||
send_port_btn(11, 00, 01, 01);
|
||
wirte_textbox("潜标ADCP300数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(11, 00, 00, 01);
|
||
wirte_textbox("潜标ADCP300数据关!");
|
||
}
|
||
|
||
private void button17_Click(object sender, EventArgs e)
|
||
{
|
||
if (button17.Text == "电源开")
|
||
{
|
||
send_port_btn(13, 08, 01, 00);
|
||
wirte_textbox("浮标倾角电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(13, 08, 00, 00);
|
||
wirte_textbox("浮标倾角电源关!");
|
||
}
|
||
|
||
private void button24_Click(object sender, EventArgs e)
|
||
{
|
||
if (button24.Text == "数据开")
|
||
{
|
||
send_port_btn(13, 08, 01, 01);
|
||
wirte_textbox("浮标倾角数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(13, 08, 00, 01);
|
||
wirte_textbox("浮标倾角数据关!");
|
||
}
|
||
|
||
private void button34_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(31);
|
||
wirte_textbox("手动读取接驳盒ADCP300数据!");
|
||
}
|
||
|
||
private void button35_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(30);
|
||
wirte_textbox("手动读取接驳盒CTD数据!");
|
||
}
|
||
|
||
private void button36_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(21);
|
||
wirte_textbox("手动读取潜标ADCP300数据!");
|
||
}
|
||
|
||
//下拉框下拉时发生的事件
|
||
private void comboBox3_DropDown(object sender, EventArgs e)
|
||
{
|
||
comboBox3.Items.Clear();
|
||
string[] _file_name = new string[] { "JADCPL", "JOTHR-", "QADCPL", "QADCP-", "FOTHR-", "FADCPL", "FBEIDA" };
|
||
for (int i = 0; i < _file_name.Length; i++)
|
||
{
|
||
comboBox3.Items.Add(_file_name[i]);
|
||
}
|
||
}
|
||
|
||
private void button47_Click(object sender, EventArgs e)
|
||
{
|
||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||
{
|
||
Console.WriteLine(dialog.SelectedPath);
|
||
textBox7.Text = dialog.SelectedPath + @"\垂直剖面浮标文件\";
|
||
}
|
||
}
|
||
|
||
private void button26_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (button26.Text == "电源开")
|
||
{
|
||
send_port_btn(25, 02, 01, 00);
|
||
wirte_textbox("潜标二氧化碳电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 02, 00, 00);
|
||
wirte_textbox("潜标二氧化碳电源关!");
|
||
}
|
||
|
||
private void button9_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (button9.Text == "数据开")
|
||
{
|
||
send_port_btn(25, 02, 01, 01);
|
||
wirte_textbox("潜标二氧化碳数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 02, 00, 01);
|
||
wirte_textbox("潜标二氧化碳数据关!");
|
||
}
|
||
|
||
private void button48_Click(object sender, EventArgs e)
|
||
{
|
||
if (button48.Text == "电源开")
|
||
{
|
||
send_port_btn(25, 03, 01, 00);
|
||
wirte_textbox("潜标METS电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 03, 00, 00);
|
||
wirte_textbox("潜标METS电源关!");
|
||
}
|
||
|
||
private void button37_Click_1(object sender, EventArgs e)
|
||
{
|
||
if (button37.Text == "数据开")
|
||
{
|
||
send_port_btn(25, 03, 01, 01);
|
||
wirte_textbox("潜标METS数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 03, 00, 01);
|
||
wirte_textbox("潜标METS数据关!");
|
||
}
|
||
|
||
private void button50_Click(object sender, EventArgs e)
|
||
{
|
||
if (button50.Text == "电源开")
|
||
{
|
||
send_port_btn(25, 04, 01, 00);
|
||
wirte_textbox("潜标CTD电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 04, 00, 00);
|
||
wirte_textbox("潜标CTD电源关!");
|
||
}
|
||
|
||
private void button49_Click(object sender, EventArgs e)
|
||
{
|
||
if (button49.Text == "数据开")
|
||
{
|
||
send_port_btn(25, 04, 01, 01);
|
||
wirte_textbox("潜标CTD数据开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 04, 00, 01);
|
||
wirte_textbox("潜标CTD数据关!");
|
||
}
|
||
|
||
private void button51_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(25);
|
||
wirte_textbox("手动读取潜标其他传感器数据!");
|
||
}
|
||
|
||
private void button52_Click(object sender, EventArgs e)
|
||
{
|
||
if (button52.Text == "电源开")
|
||
{
|
||
send_port_btn(25, 10, 01, 00);
|
||
wirte_textbox("潜标水声通信机电源开!");
|
||
return;
|
||
}
|
||
send_port_btn(25, 10, 00, 00);
|
||
wirte_textbox("潜标水声通信机电源关!");
|
||
}
|
||
|
||
private void button15_Click(object sender, EventArgs e)
|
||
{
|
||
Console.WriteLine(Convert.ToInt16(textBox11.Text.Trim(), 16));
|
||
}
|
||
|
||
private void button37_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(23);
|
||
wirte_textbox("手动读取潜标ADCP150数据!");
|
||
}
|
||
|
||
private void button38_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(10);
|
||
wirte_textbox("手动读取浮标数据!");
|
||
}
|
||
|
||
private void button39_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(11);
|
||
wirte_textbox("手动读取浮标ADCP300数据!");
|
||
}
|
||
|
||
private void button40_Click(object sender, EventArgs e)
|
||
{
|
||
send_port_hand(13);
|
||
wirte_textbox("手动读取浮标姿态传感器数据!");
|
||
}
|
||
|
||
|
||
}
|
||
}
|