1892 lines
72 KiB
C#
1892 lines
72 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
using System.Net;
|
|||
|
|
using System.Net.Sockets;
|
|||
|
|
using System.Threading;
|
|||
|
|
using System.IO.Ports;
|
|||
|
|
using System.IO;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace Nanji_Island
|
|||
|
|
{
|
|||
|
|
public partial class Form1 : Form
|
|||
|
|
{
|
|||
|
|
UIControl_HBGK uiControl_HBGK1;
|
|||
|
|
UIControl_HBGK uiControl_HBGK2;
|
|||
|
|
|
|||
|
|
//本机Ip
|
|||
|
|
String LocalIp;
|
|||
|
|
//端口号
|
|||
|
|
String port;
|
|||
|
|
|
|||
|
|
/*************************视频变量及常量设置****************************/
|
|||
|
|
//视频变量
|
|||
|
|
IntPtr libvlc_instance_Camer;
|
|||
|
|
IntPtr libvlc_media_player_Camer;
|
|||
|
|
IntPtr libvlc_instance_Sonar;
|
|||
|
|
IntPtr libvlc_media_player_Sonar;
|
|||
|
|
//视频线程
|
|||
|
|
private System.Threading.Timer timer_Video;
|
|||
|
|
private System.Threading.Timer timer_Video_CZ;
|
|||
|
|
private System.Threading.Timer timer_Video_CZ_stop;
|
|||
|
|
//摄像及网络路径
|
|||
|
|
string network_pass_Camera = "rtsp://192.168.1.123:554/really";
|
|||
|
|
string network_pass_Sonar = "rtsp://192.168.1.168/0";
|
|||
|
|
//摄像及声呐ip
|
|||
|
|
string ip_Camera = "192.168.1.131";
|
|||
|
|
string ip_Sonar = "192.168.1.168";
|
|||
|
|
//录制文件保存路径及录制状态
|
|||
|
|
bool isREC_Camera = false;
|
|||
|
|
bool isREC_Sonar = false;
|
|||
|
|
|
|||
|
|
string pass_Camera = @"G:\Video\Camera\";
|
|||
|
|
string pass_Sonar = @"I:\Video\Sonar\";
|
|||
|
|
|
|||
|
|
static double[] data_send;
|
|||
|
|
|
|||
|
|
private TcpClient tclient = new TcpClient();
|
|||
|
|
private NetworkStream ns1;
|
|||
|
|
private NetworkStream ns2;
|
|||
|
|
|
|||
|
|
public static SerialPort sp1 = new SerialPort();
|
|||
|
|
public static SerialPort sp2 = new SerialPort();
|
|||
|
|
public static SerialPort sp3 = new SerialPort();
|
|||
|
|
public static SerialPort sp4 = new SerialPort();
|
|||
|
|
public static SerialPort sp5 = new SerialPort();
|
|||
|
|
/*************************视频变量及常量设置****************************/
|
|||
|
|
|
|||
|
|
private IPEndPoint myserver;
|
|||
|
|
//tcp/ip
|
|||
|
|
private Socket Soc;
|
|||
|
|
//private IPEndPoint myserver;
|
|||
|
|
private IPHostEntry MyHost;
|
|||
|
|
private static ManualResetEvent connectReset = new ManualResetEvent(false);
|
|||
|
|
private static ManualResetEvent sendReset = new ManualResetEvent(false);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
public Form1()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
private void Form1_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
comboBox1.Items.Add("打开声呐");
|
|||
|
|
comboBox1.Items.Add("打开摄像1");
|
|||
|
|
comboBox1.Items.Add("第三路打开");
|
|||
|
|
comboBox1.Items.Add("打开摄像2");
|
|||
|
|
|
|||
|
|
comboBox2.Items.Add("关闭声呐");
|
|||
|
|
comboBox2.Items.Add("关闭摄像1");
|
|||
|
|
comboBox2.Items.Add("第三路关闭");
|
|||
|
|
comboBox2.Items.Add("关闭摄像2");
|
|||
|
|
|
|||
|
|
//使最大化窗口失效
|
|||
|
|
//this.MaximizeBox = false;
|
|||
|
|
//禁用对窗口大小进行拖拽
|
|||
|
|
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
|||
|
|
//从服务端界面取出设定好的IP及端口号
|
|||
|
|
LocalIp = Form2.LocalIp; port = Form2.port;
|
|||
|
|
ipAdress.Text = LocalIp; _port.Text = port;
|
|||
|
|
|
|||
|
|
//开启服务端监听线程
|
|||
|
|
Server.open_server(LocalIp, port);
|
|||
|
|
|
|||
|
|
//视频及声呐初始化
|
|||
|
|
//Initialization_Camera();
|
|||
|
|
Initialization_Sonar();
|
|||
|
|
//每隔1秒对视频通讯进行校验 延迟1秒开始视频播放
|
|||
|
|
timer_Video = new System.Threading.Timer(new System.Threading.TimerCallback(Video), null, 1000 ,30000);
|
|||
|
|
timer_Video_CZ = new System.Threading.Timer(new System.Threading.TimerCallback(Video_CZ), null, 10000, 60000);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//检查是否含有串口
|
|||
|
|
string[] str = SerialPort.GetPortNames();
|
|||
|
|
if (str == null)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("本机没有串口!", "Error");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//添加串口项目
|
|||
|
|
foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
|
|||
|
|
{//获取有多少个COM口
|
|||
|
|
//System.Diagnostics.Debug.WriteLine(s);
|
|||
|
|
cbSerial.Items.Add(s);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//sp2.Open();
|
|||
|
|
//sp3.Open();
|
|||
|
|
//sp4.Open();
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
/*****************************视频播放及录制***************************/
|
|||
|
|
private void Camera_Show(bool video)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
if (video == true)
|
|||
|
|
{
|
|||
|
|
//视频初始化
|
|||
|
|
Initialization_Camera();
|
|||
|
|
//开始播放
|
|||
|
|
MediaPlayer.NetWork_Media_Play(libvlc_instance_Camer, libvlc_media_player_Camer, network_pass_Camera);
|
|||
|
|
//获取当前时间设置为文件名称
|
|||
|
|
System.DateTime currentTime = new System.DateTime();
|
|||
|
|
currentTime = System.DateTime.Now;
|
|||
|
|
string Time_LJ = currentTime.ToString("yyyyMMdd");
|
|||
|
|
//开始录制
|
|||
|
|
string url_carmer_1 = pass_Camera + Time_LJ + "\\";
|
|||
|
|
if (!Directory.Exists(url_carmer_1))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(url_carmer_1);
|
|||
|
|
}
|
|||
|
|
string url_carmer = pass_Camera + Time_LJ + "\\" + currentTime.ToString();
|
|||
|
|
MediaPlayer.Save_MediaPlayer(libvlc_media_player_Camer, url_carmer);
|
|||
|
|
isREC_Camera = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//结束录制
|
|||
|
|
MediaPlayer.UnSave_MediaPlayer(libvlc_media_player_Camer);
|
|||
|
|
//释放播放器资源
|
|||
|
|
MediaPlayer.Release_MediaPlayer(libvlc_media_player_Camer);
|
|||
|
|
isREC_Camera = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
private void Sonar_Show(bool video)
|
|||
|
|
{
|
|||
|
|
if (video == true)
|
|||
|
|
{
|
|||
|
|
//声呐初始化
|
|||
|
|
// Initialization_Sonar();
|
|||
|
|
MediaPlayer.NetWork_Media_Play(libvlc_instance_Sonar, libvlc_media_player_Sonar, network_pass_Sonar);
|
|||
|
|
//获取当前时间设置为文件名称
|
|||
|
|
System.DateTime currentTime = new System.DateTime();
|
|||
|
|
currentTime = System.DateTime.Now;
|
|||
|
|
string Time_LJ = currentTime.ToString("yyyyMMdd");
|
|||
|
|
//开始录制
|
|||
|
|
string url_sonar_1 = pass_Sonar + Time_LJ + "\\";
|
|||
|
|
if (!Directory.Exists(url_sonar_1))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(url_sonar_1);
|
|||
|
|
}
|
|||
|
|
string url_sonar = pass_Sonar + Time_LJ + "\\" + currentTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|||
|
|
MediaPlayer.Save_MediaPlayer(libvlc_media_player_Sonar, url_sonar);
|
|||
|
|
isREC_Sonar = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
////结束录制
|
|||
|
|
//MediaPlayer.UnSave_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
//释放播放器资源
|
|||
|
|
MediaPlayer.Release_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
isREC_Sonar = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Sonar_CZ(bool video)
|
|||
|
|
{
|
|||
|
|
if (video == true)
|
|||
|
|
{
|
|||
|
|
//声呐初始化
|
|||
|
|
Initialization_Sonar();
|
|||
|
|
//MediaPlayer.NetWork_Media_Play(libvlc_instance_Sonar, libvlc_media_player_Sonar, network_pass_Sonar);
|
|||
|
|
//获取当前时间设置为文件名称
|
|||
|
|
System.DateTime currentTime = new System.DateTime();
|
|||
|
|
currentTime = System.DateTime.Now;
|
|||
|
|
string Time_LJ = currentTime.ToString("yyyyMMdd");
|
|||
|
|
//开始录制
|
|||
|
|
string url_sonar_1 = pass_Sonar + Time_LJ + "\\";
|
|||
|
|
if (!Directory.Exists(url_sonar_1))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(url_sonar_1);
|
|||
|
|
}
|
|||
|
|
string url_sonar = pass_Sonar + Time_LJ + "\\" + currentTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|||
|
|
MediaPlayer.Save_MediaPlayer(libvlc_media_player_Sonar, url_sonar);
|
|||
|
|
isREC_Sonar = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//结束录制
|
|||
|
|
MediaPlayer.UnSave_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
//释放播放器资源
|
|||
|
|
MediaPlayer.Release_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
isREC_Sonar = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//视频初始化
|
|||
|
|
private void Initialization_Camera()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
libvlc_instance_Camer = MediaPlayer.Create_Media_Instance();
|
|||
|
|
Invoke((EventHandler)(delegate
|
|||
|
|
{
|
|||
|
|
libvlc_media_player_Camer = MediaPlayer.Create_MediaPlayer(libvlc_instance_Camer, panel1.Handle);
|
|||
|
|
}));
|
|||
|
|
}
|
|||
|
|
catch (Exception err)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(err.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//声呐初始化
|
|||
|
|
private void Initialization_Sonar()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
libvlc_instance_Sonar = MediaPlayer.Create_Media_Instance();
|
|||
|
|
Invoke((EventHandler)(delegate
|
|||
|
|
{
|
|||
|
|
libvlc_media_player_Sonar = MediaPlayer.Create_MediaPlayer(libvlc_instance_Sonar, panel2.Handle);
|
|||
|
|
}));
|
|||
|
|
}
|
|||
|
|
catch (Exception err)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(err.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//计数用
|
|||
|
|
int count_Camera = 0;
|
|||
|
|
int count_Sonar = 0;
|
|||
|
|
|
|||
|
|
//校验timer 用于校验当前视频及声呐通讯是否正常
|
|||
|
|
private void Video(object sender)
|
|||
|
|
{
|
|||
|
|
//如果没有存储路径就创建存储路径
|
|||
|
|
if (false == System.IO.Directory.Exists(pass_Camera)){Directory.CreateDirectory(pass_Camera);}
|
|||
|
|
if (false == System.IO.Directory.Exists(pass_Sonar)) { Directory.CreateDirectory(pass_Sonar); }
|
|||
|
|
|
|||
|
|
List<FileInfo> lst_Camera = new List<FileInfo>();
|
|||
|
|
List<FileInfo> lstFiles_Camera = tool.getFile(pass_Camera, ".avi", lst_Camera);
|
|||
|
|
List<FileInfo> lst_Sonar = new List<FileInfo>();
|
|||
|
|
List<FileInfo> lstFiles_Sonar = tool.getFile(pass_Sonar, ".avi", lst_Sonar);
|
|||
|
|
bool play_Camera = MediaPlayer.MediaPlayer_IsPlaying(libvlc_media_player_Camer);
|
|||
|
|
|
|||
|
|
bool play_Sonar = MediaPlayer.MediaPlayer_IsPlaying(libvlc_media_player_Sonar);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
//如果通,且不在录制则开始播放并录制
|
|||
|
|
if (tool.PingIp(ip_Camera) == true && isREC_Camera == false)
|
|||
|
|
{
|
|||
|
|
Thread.Sleep(10000);
|
|||
|
|
//释放播放器资源
|
|||
|
|
MediaPlayer.MediaPlayer_Stop(libvlc_media_player_Camer);
|
|||
|
|
Camera_Show(true);
|
|||
|
|
}
|
|||
|
|
//如果不通且在录制,则停止录制并保存
|
|||
|
|
else if
|
|||
|
|
(tool.PingIp(ip_Camera) == false && isREC_Camera == true)
|
|||
|
|
{ Camera_Show(false); }
|
|||
|
|
//如果通且在录制或不同且不在录制,则不需要操作
|
|||
|
|
else if (tool.PingIp(ip_Camera) == true && isREC_Camera == true) { }
|
|||
|
|
else if (tool.PingIp(ip_Camera) == false && isREC_Camera == false && play_Camera == false)
|
|||
|
|
//else if (tool.PingIp(ip_Camera) == false && isREC_Camera == false )
|
|||
|
|
{
|
|||
|
|
if (lstFiles_Camera.Count != 0)
|
|||
|
|
{
|
|||
|
|
MediaPlayer.LocationPath_Media_Play(libvlc_instance_Camer, libvlc_media_player_Camer, lstFiles_Camera[count_Camera].FullName);
|
|||
|
|
if (lstFiles_Camera.Count != count_Camera + 1)
|
|||
|
|
{
|
|||
|
|
count_Camera = count_Camera + 1;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
count_Camera = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (tool.PingIp(ip_Sonar) == true && isREC_Sonar == false)
|
|||
|
|
{//释放播放器资源
|
|||
|
|
Thread.Sleep(1000);
|
|||
|
|
MediaPlayer.MediaPlayer_Stop(libvlc_media_player_Sonar);
|
|||
|
|
Sonar_Show(true);
|
|||
|
|
//播放流后将频率变成100毫秒
|
|||
|
|
timer_Video.Dispose();
|
|||
|
|
timer_Video = new System.Threading.Timer(new System.Threading.TimerCallback(Video), null, 2000, 1000);
|
|||
|
|
Console.WriteLine("开始录制应该");
|
|||
|
|
}
|
|||
|
|
//如果不通且在录制,则停止录制并保存
|
|||
|
|
else if (tool.PingIp(ip_Sonar) == false && isREC_Sonar == true) {
|
|||
|
|
Sonar_Show(false); Sonar_CZ(false);
|
|||
|
|
}
|
|||
|
|
//如果通且在录制,则不需要操作,或不同且不在录制不在播放则随机播放本地视频
|
|||
|
|
else if (tool.PingIp(ip_Sonar) == true && isREC_Sonar == true) {
|
|||
|
|
Console.WriteLine("正在播放在线视频");
|
|||
|
|
//DateTime _time = System.DateTime.Now;
|
|||
|
|
//while ((System.DateTime.Now - _time).TotalSeconds < 1800) { Thread.Sleep(1); }
|
|||
|
|
//MediaPlayer.MediaPlayer_Stop(libvlc_media_player_Sonar);
|
|||
|
|
//Thread.Sleep(60000);
|
|||
|
|
//MediaPlayer.UnSave_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
//Thread.Sleep(2000);
|
|||
|
|
//////释放播放器资源
|
|||
|
|
////MediaPlayer.MediaPlayer_Stop(libvlc_media_player_Sonar);
|
|||
|
|
////MediaPlayer.Release_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
//isREC_Sonar = false;
|
|||
|
|
////Sonar_Show(false);
|
|||
|
|
//timer_Video.Dispose();
|
|||
|
|
//timer_Video = new System.Threading.Timer(new System.Threading.TimerCallback(Video), null, 0, 10000);
|
|||
|
|
}
|
|||
|
|
else if (tool.PingIp(ip_Sonar) == false && isREC_Sonar == false && play_Sonar == false)
|
|||
|
|
{
|
|||
|
|
if (lstFiles_Sonar.Count != 0)
|
|||
|
|
{
|
|||
|
|
MediaPlayer.LocationPath_Media_Play(libvlc_instance_Sonar, libvlc_media_player_Sonar, lstFiles_Sonar[count_Sonar].FullName);
|
|||
|
|
if (lstFiles_Sonar.Count != count_Sonar + 1)
|
|||
|
|
{
|
|||
|
|
count_Sonar = count_Sonar + 1;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
count_Sonar = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//播放本地视频后将频率改回10秒
|
|||
|
|
//播放流后将频率变成100毫秒
|
|||
|
|
timer_Video.Dispose();
|
|||
|
|
timer_Video = new System.Threading.Timer(new System.Threading.TimerCallback(Video), null, 0, 10000);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Video_CZ(object sender)
|
|||
|
|
{
|
|||
|
|
if (tool.PingIp(ip_Sonar) == true && isREC_Sonar == true)
|
|||
|
|
{
|
|||
|
|
//结束录制
|
|||
|
|
MediaPlayer.UnSave_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
////释放播放器资源
|
|||
|
|
//MediaPlayer.Release_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
isREC_Sonar = false;
|
|||
|
|
Thread.Sleep(2000);
|
|||
|
|
Console.WriteLine("结束存储");
|
|||
|
|
Thread.Sleep(2000);
|
|||
|
|
timer_Video.Dispose();
|
|||
|
|
timer_Video = new System.Threading.Timer(new System.Threading.TimerCallback(Video), null, 0, 1000);
|
|||
|
|
Console.WriteLine("创建新timer");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Video_CZ_Stop(object sender)
|
|||
|
|
{
|
|||
|
|
// Sonar_Show(false);
|
|||
|
|
////结束录制
|
|||
|
|
//MediaPlayer.UnSave_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
//////释放播放器资源
|
|||
|
|
////MediaPlayer.Release_MediaPlayer(libvlc_media_player_Sonar);
|
|||
|
|
//isREC_Sonar = false;
|
|||
|
|
//Thread.Sleep(10000);
|
|||
|
|
//Console.WriteLine("结束存储");
|
|||
|
|
//timer_Video_CZ_stop.Dispose();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*****************************视频播放及录制***************************/
|
|||
|
|
|
|||
|
|
|
|||
|
|
//关闭
|
|||
|
|
/**private void button2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
//socket关闭
|
|||
|
|
serverSocket.Close();
|
|||
|
|
//线程关闭
|
|||
|
|
listenThread.Abort();
|
|||
|
|
threadReceive.Abort();
|
|||
|
|
}**/
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**********************设定窗口关闭时触发的事件*************************/
|
|||
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|||
|
|
{
|
|||
|
|
//关闭所有线程关闭
|
|||
|
|
Server.close_server();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/******************************测试****************************/
|
|||
|
|
//发送
|
|||
|
|
private void button1_Click_1(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Server.send_server("GET");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Server.send_server("#ZTTHY- 1,Server,data_trans,MANY_PARAM,2020-10- 9 14:33:14, 10,0123456789,End");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//手动模式切换
|
|||
|
|
private void button3_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button4_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void panel2_Paint(object sender, PaintEventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnopen_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (tclient.Connected == false)
|
|||
|
|
{
|
|||
|
|
tclient.Connect(tbIP.Text, Convert.ToInt32(tbPort.Text));
|
|||
|
|
if (tclient.Connected == true)
|
|||
|
|
btnopen.Text = "关闭";
|
|||
|
|
|
|||
|
|
ns1 = tclient.GetStream();
|
|||
|
|
ns2 = tclient.GetStream();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
tclient.Close();
|
|||
|
|
tclient = new TcpClient();
|
|||
|
|
btnopen.Text = "打开";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
tclient.Close();
|
|||
|
|
tclient = new TcpClient();
|
|||
|
|
MessageBox.Show(ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void btnDO1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Button btn = (sender as Button);
|
|||
|
|
bool isopen = (btn.ImageIndex == 0) ? false : true;
|
|||
|
|
|
|||
|
|
int io = Convert.ToInt32(btn.Tag);
|
|||
|
|
|
|||
|
|
btn.ImageIndex = (isopen) ? 0 : 1;
|
|||
|
|
|
|||
|
|
byte[] info = CModbusDll.WriteDO(Convert.ToInt16(txtaddr.Text), io - 1, !isopen);
|
|||
|
|
byte[] rst = sendinfo(info);
|
|||
|
|
if (rst != null)
|
|||
|
|
{
|
|||
|
|
btn.ImageIndex = (rst[0] == 0) ? 0 : 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private byte[] sendinfo(byte[] info)
|
|||
|
|
{
|
|||
|
|
if (tclient.Connected == false) return null;
|
|||
|
|
tclient.SendTimeout = 1000;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
ns1.Write(info, 0, info.Length);
|
|||
|
|
DebugInfo("发送", info);
|
|||
|
|
|
|||
|
|
byte[] data = new byte[2048];
|
|||
|
|
ns2.ReadTimeout = 2000;
|
|||
|
|
int len = ns2.Read(data, 0, 2048);
|
|||
|
|
|
|||
|
|
DebugInfo("接收", data, len);
|
|||
|
|
|
|||
|
|
return analysisRcv(data, len);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
tclient.Close();
|
|||
|
|
tclient = new TcpClient();
|
|||
|
|
btnopen.Text = "打开";
|
|||
|
|
MessageBox.Show(ex.Message);
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
private void DebugInfo(string infotxt, byte[] info, int len = 0)
|
|||
|
|
{
|
|||
|
|
string debuginfo;
|
|||
|
|
StringBuilder builder = new StringBuilder();
|
|||
|
|
if (info != null)
|
|||
|
|
{
|
|||
|
|
if (len == 0) len = info.Length;
|
|||
|
|
//判断是否是显示为16禁止
|
|||
|
|
//依次的拼接出16进制字符串
|
|||
|
|
for (int i = 0; i < len; i++)
|
|||
|
|
{
|
|||
|
|
builder.Append(info[i].ToString("X2") + " ");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
debuginfo = string.Format("{0}:{1}\r\n", infotxt, builder.ToString());
|
|||
|
|
builder.Clear();
|
|||
|
|
//因为要访问ui资源,所以需要使用invoke方式同步ui。
|
|||
|
|
this.Invoke((EventHandler)(delegate
|
|||
|
|
{
|
|||
|
|
//追加的形式添加到文本框末端,并滚动到最后。
|
|||
|
|
txtRecv.AppendText(debuginfo);
|
|||
|
|
}));
|
|||
|
|
}
|
|||
|
|
private byte[] analysisRcv(byte[] src, int len)
|
|||
|
|
{
|
|||
|
|
if (len < 6) return null;
|
|||
|
|
if (src[0] != Convert.ToInt16(txtaddr.Text)) return null;
|
|||
|
|
|
|||
|
|
switch (src[1])
|
|||
|
|
{
|
|||
|
|
case 0x01:
|
|||
|
|
if (CMBRTU.CalculateCrc(src, 6) == 0x00)
|
|||
|
|
{
|
|||
|
|
byte[] dst = new byte[1];
|
|||
|
|
dst[0] = src[3];
|
|||
|
|
return dst;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 0x02:
|
|||
|
|
if (CMBRTU.CalculateCrc(src, src[2] + 5) == 0x00)
|
|||
|
|
{
|
|||
|
|
byte[] dst = new byte[src[2]];
|
|||
|
|
for (int i = 0; i < src[2]; i++)
|
|||
|
|
dst[i] = src[3 + i];
|
|||
|
|
return dst;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 0x05:
|
|||
|
|
if (CMBRTU.CalculateCrc(src, 8) == 0x00)
|
|||
|
|
{
|
|||
|
|
byte[] dst = new byte[1];
|
|||
|
|
dst[0] = src[4];
|
|||
|
|
return dst;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case 0x0f:
|
|||
|
|
if (CMBRTU.CalculateCrc(src, 8) == 0x00)
|
|||
|
|
{
|
|||
|
|
byte[] dst = new byte[1];
|
|||
|
|
dst[0] = 1;
|
|||
|
|
return dst;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnSwitch_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Form1.sp1.PortName = "COM4";
|
|||
|
|
Form1.sp1.BaudRate = 9600;
|
|||
|
|
Form1.sp1.Parity = Parity.None;
|
|||
|
|
Form1.sp1.DataBits = 8;
|
|||
|
|
Form1.sp1.StopBits = StopBits.One;
|
|||
|
|
Form1.sp1.ReceivedBytesThreshold = 1;
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp1.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
btnSwitch.Enabled = false;
|
|||
|
|
//btnSwitch.Enabled = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button8_Click(object sender, EventArgs e)//串口继电器
|
|||
|
|
{
|
|||
|
|
if (comboBox1.SelectedItem.Equals("第一路打开"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 10 FF 00 8D FF";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
else if (comboBox1.SelectedItem.Equals("第二路打开"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 11 FF 00 DC 3F";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
else if (comboBox1.SelectedItem.Equals("第三路打开"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 12 FF 00 2C 3F";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
else if (comboBox1.SelectedItem.Equals("第四路打开"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 13 FF 00 7D FF";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button5_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (comboBox2.SelectedItem.Equals("第一路关闭"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 10 00 00 CC 0F";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else if (comboBox2.SelectedItem.Equals("第二路关闭"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 11 00 00 9D CF";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else if (comboBox2.SelectedItem.Equals("第三路关闭"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 12 00 00 6D CF";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else if (comboBox2.SelectedItem.Equals("第四路关闭"))
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 05 00 13 00 00 3C 0F";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp1.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnDO1_Click_1(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Button btn = (sender as Button);
|
|||
|
|
bool isopen = (btn.ImageIndex == 0) ? false : true;
|
|||
|
|
|
|||
|
|
int io = Convert.ToInt32(btn.Tag);
|
|||
|
|
|
|||
|
|
btn.ImageIndex = (isopen) ? 0 : 1;
|
|||
|
|
|
|||
|
|
byte[] info = CModbusDll.WriteDO(Convert.ToInt16(txtaddr.Text), io - 1, !isopen);
|
|||
|
|
byte[] rst = sendinfo(info);
|
|||
|
|
if (rst != null)
|
|||
|
|
{
|
|||
|
|
btn.ImageIndex = (rst[0] == 0) ? 0 : 1;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void button6_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Sonar_Show(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnDO2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/////////////温湿度控制//////////////
|
|||
|
|
private void button7_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Form1.sp2.PortName = "COM9";
|
|||
|
|
Form1.sp2.BaudRate = 4800;
|
|||
|
|
Form1.sp2.Parity = Parity.None;
|
|||
|
|
Form1.sp2.DataBits = 8;
|
|||
|
|
Form1.sp2.StopBits = StopBits.One;
|
|||
|
|
Form1.sp2.ReceivedBytesThreshold = 1;
|
|||
|
|
Form1.sp2.DataReceived += new SerialDataReceivedEventHandler(serialPort_wenshidu_DataReceived);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp2.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
button7.Enabled = false;
|
|||
|
|
}
|
|||
|
|
private void serialPort_wenshidu_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
|||
|
|
{
|
|||
|
|
try{
|
|||
|
|
Thread.Sleep(1000);
|
|||
|
|
string Time = DateTime.Now.ToString();
|
|||
|
|
string Time_CZ = DateTime.Now.ToString("yyyyMMdd");
|
|||
|
|
byte[] byteRead = new byte[Form1.sp2.BytesToRead]; //BytesToRead:sp1接收的字符个数
|
|||
|
|
Form1.sp2.Read(byteRead, 0, byteRead.Length);
|
|||
|
|
sp2.DiscardInBuffer();
|
|||
|
|
string strRcv = null;
|
|||
|
|
//int decNum = 0;//存储十进制
|
|||
|
|
for (int i = 0; i < byteRead.Length; i++) //窗体显示
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
strRcv += byteRead[i].ToString("X2"); //16进制显示
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
Invoke((EventHandler)(delegate
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
label39.Text = (Convert.ToInt64(strRcv.Substring(6, 4), 16) / 10.00).ToString(); //湿度
|
|||
|
|
label14.Text = (Convert.ToInt64(strRcv.Substring(10, 4), 16) / 10.00).ToString(); ; //温度
|
|||
|
|
label16.Text = Time;
|
|||
|
|
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + " ");
|
|||
|
|
string path_wsd2 = @"D:\环境参数记录" + "\\" + Time_CZ + "\\";
|
|||
|
|
if (!Directory.Exists(path_wsd2))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(path_wsd2);
|
|||
|
|
}
|
|||
|
|
System.IO.File.AppendAllText(path_wsd2+"温湿度2.txt", "时间:" + label16.Text + " " + "湿度:" + label39.Text + " " + "温度:" + label14.Text + "\r\n");
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}));
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 电压电流监测
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void button9_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Form1.sp4.PortName = "COM8";
|
|||
|
|
Form1.sp4.BaudRate = 9600;
|
|||
|
|
Form1.sp4.Parity = Parity.None;
|
|||
|
|
Form1.sp4.DataBits = 8;
|
|||
|
|
Form1.sp4.StopBits = StopBits.Two;
|
|||
|
|
Form1.sp4.ReceivedBytesThreshold = 1;
|
|||
|
|
Form1.sp4.DataReceived += new SerialDataReceivedEventHandler(serialPort_dianyadianliu_DataReceived);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp4.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
button9.Enabled = false;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
private void serialPort_dianyadianliu_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
|||
|
|
{
|
|||
|
|
Thread.Sleep(1000);
|
|||
|
|
string Time = DateTime.Now.ToString(); string Time_CZ = DateTime.Now.ToString("yyyyMMdd");
|
|||
|
|
byte[] byteRead = new byte[Form1.sp4.BytesToRead]; //BytesToRead:sp1接收的字符个数
|
|||
|
|
Form1.sp4.Read(byteRead, 0, byteRead.Length);
|
|||
|
|
sp4.DiscardInBuffer();
|
|||
|
|
string strRcv = null;
|
|||
|
|
//int decNum = 0;//存储十进制
|
|||
|
|
for (int i = 0; i < byteRead.Length; i++) //窗体显示
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
strRcv += byteRead[i].ToString("X2"); //16进制显示
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
Invoke((EventHandler)(delegate
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
label31.Text = (Convert.ToInt64(strRcv.Substring(6, 4), 16) / 100.00).ToString(); //电压
|
|||
|
|
label32.Text = (Convert.ToInt64(strRcv.Substring(10, 4), 16) / 100.00).ToString(); ; //电流
|
|||
|
|
label9.Text = Time;
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + " ");
|
|||
|
|
string path_dydl = @"D:\环境参数记录"+"\\" + Time_CZ + "\\";
|
|||
|
|
if (!Directory.Exists(path_dydl))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(path_dydl);
|
|||
|
|
}
|
|||
|
|
System.IO.File.AppendAllText(path_dydl+"电压电流.txt", "时间:" + label9.Text + " " + "电压:" + label31.Text + " " + "电流:" + label32.Text + "\r\n");
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void groupBox2_Enter(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button10_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (panel1.Controls.Count > 0)
|
|||
|
|
{
|
|||
|
|
UIControl_HBGK uiControl = (UIControl_HBGK)panel1.Controls[0];
|
|||
|
|
uiControl.ReleaseResources("1");
|
|||
|
|
}
|
|||
|
|
panel1.Controls.Clear();
|
|||
|
|
init1();
|
|||
|
|
uiControl_HBGK1.Dock = DockStyle.Fill;
|
|||
|
|
panel1.Controls.Add(uiControl_HBGK1);
|
|||
|
|
}
|
|||
|
|
private void init1()
|
|||
|
|
{
|
|||
|
|
ChannelInfo ch = new ChannelInfo();
|
|||
|
|
ch.ChlID = "1";
|
|||
|
|
ch.nDeviceType = 1;//2表示NVR,1表示IPC
|
|||
|
|
ch.RemoteChannle = "1";
|
|||
|
|
ch.RemoteIP = "192.168.1.123";
|
|||
|
|
ch.RemotePort = 554;
|
|||
|
|
ch.RemoteUser = "admin";
|
|||
|
|
ch.RemotePwd = "123456";
|
|||
|
|
ch.nPlayPort = 2;
|
|||
|
|
ch.PtzPort = 8091;
|
|||
|
|
uiControl_HBGK1 = new UIControl_HBGK(ch);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button11_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (panel3.Controls.Count > 0)
|
|||
|
|
{
|
|||
|
|
UIControl_HBGK uiControl = (UIControl_HBGK)panel1.Controls[0];
|
|||
|
|
uiControl.ReleaseResources("1");
|
|||
|
|
}
|
|||
|
|
panel3.Controls.Clear();
|
|||
|
|
init2();
|
|||
|
|
uiControl_HBGK2.Dock = DockStyle.Fill;
|
|||
|
|
panel3.Controls.Add(uiControl_HBGK2);
|
|||
|
|
}
|
|||
|
|
private void init2()
|
|||
|
|
{
|
|||
|
|
ChannelInfo ch = new ChannelInfo();
|
|||
|
|
ch.ChlID = "1";
|
|||
|
|
ch.nDeviceType = 1;//2表示NVR,1表示IPC
|
|||
|
|
ch.RemoteChannle = "1";
|
|||
|
|
ch.RemoteIP = "192.168.1.124";
|
|||
|
|
ch.RemotePort = 554;
|
|||
|
|
ch.RemoteUser = "admin";
|
|||
|
|
ch.RemotePwd = "123456";
|
|||
|
|
ch.nPlayPort = 1;
|
|||
|
|
ch.PtzPort = 8091;
|
|||
|
|
uiControl_HBGK2 = new UIControl_HBGK(ch);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button12_Click(object sender, EventArgs e)//请求温湿度数据
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
string strSecond = "01 03 00 00 00 02 C4 0B";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp2.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 03 00 00 00 02 C4 0B";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp2.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button13_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 03 00 00 00 02 C4 0B";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp3.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer2_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 03 00 00 00 02 C4 0B";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp3.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button6_Click_1(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Form1.sp3.PortName = "COM10";
|
|||
|
|
Form1.sp3.BaudRate = 4800;
|
|||
|
|
Form1.sp3.Parity = Parity.None;
|
|||
|
|
Form1.sp3.DataBits = 8;
|
|||
|
|
Form1.sp3.StopBits = StopBits.One;
|
|||
|
|
Form1.sp3.ReceivedBytesThreshold = 1;
|
|||
|
|
Form1.sp3.DataReceived += new SerialDataReceivedEventHandler(serialPort_wenshidu_DataReceived1);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp3.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
button6.Enabled = false;
|
|||
|
|
}
|
|||
|
|
private void serialPort_wenshidu_DataReceived1(object sender, SerialDataReceivedEventArgs e)
|
|||
|
|
{
|
|||
|
|
Thread.Sleep(1000);
|
|||
|
|
string Time = DateTime.Now.ToString(); string Time_CZ = DateTime.Now.ToString("yyyyMMdd");
|
|||
|
|
byte[] byteRead = new byte[Form1.sp3.BytesToRead]; //BytesToRead:sp1接收的字符个数
|
|||
|
|
Form1.sp3.Read(byteRead, 0, byteRead.Length);
|
|||
|
|
sp2.DiscardInBuffer();
|
|||
|
|
string strRcv = null;
|
|||
|
|
//int decNum = 0;//存储十进制
|
|||
|
|
for (int i = 0; i < byteRead.Length; i++) //窗体显示
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
strRcv += byteRead[i].ToString("X2"); //16进制显示
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
Invoke((EventHandler)(delegate
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
label28.Text = (Convert.ToInt64(strRcv.Substring(6, 4), 16) / 10.00).ToString(); //湿度
|
|||
|
|
label27.Text = (Convert.ToInt64(strRcv.Substring(10, 4), 16) / 10.00).ToString(); ; //温度
|
|||
|
|
label26.Text = Time;
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
sb.AppendLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + " ");
|
|||
|
|
string path_wsd1 = @"D:\环境参数记录" + "\\" + Time_CZ + "\\";
|
|||
|
|
if (!Directory.Exists(path_wsd1))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(path_wsd1);
|
|||
|
|
}
|
|||
|
|
System.IO.File.AppendAllText(path_wsd1+"温湿度1.txt", "时间:" + label26.Text + " " + "湿度:" + label28.Text + " " + "温度:" + label27.Text + "\r\n");
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}));
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer3_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 04 00 00 00 08 F1 CC";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp4.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer4_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
/*if(true){}
|
|||
|
|
Button btn = (sender as Button);
|
|||
|
|
bool isopen = (btn.ImageIndex == 0) ? false : true;
|
|||
|
|
|
|||
|
|
int io = Convert.ToInt32(btn.Tag);
|
|||
|
|
|
|||
|
|
btn.ImageIndex = (isopen) ? 0 : 1;
|
|||
|
|
|
|||
|
|
byte[] info = CModbusDll.WriteDO(Convert.ToInt16(txtaddr.Text), io - 1, !isopen);
|
|||
|
|
byte[] rst = sendinfo(info);
|
|||
|
|
if (rst != null)
|
|||
|
|
{
|
|||
|
|
btn.ImageIndex = (rst[0] == 0) ? 0 : 1;
|
|||
|
|
}*/
|
|||
|
|
btnDO1_Click_1(btnDO1,e);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void button14_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string strSecond = "01 04 00 00 00 08 F1 CC";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp4.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer5_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Form1.sp2.PortName = "COM9";
|
|||
|
|
Form1.sp2.BaudRate = 4800;
|
|||
|
|
Form1.sp2.Parity = Parity.None;
|
|||
|
|
Form1.sp2.DataBits = 8;
|
|||
|
|
Form1.sp2.StopBits = StopBits.One;
|
|||
|
|
Form1.sp2.ReceivedBytesThreshold = 1;
|
|||
|
|
Form1.sp2.DataReceived += new SerialDataReceivedEventHandler(serialPort_wenshidu_DataReceived);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp2.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
button7.Enabled = false;
|
|||
|
|
|
|||
|
|
Form1.sp3.PortName = "COM10";
|
|||
|
|
Form1.sp3.BaudRate = 4800;
|
|||
|
|
Form1.sp3.Parity = Parity.None;
|
|||
|
|
Form1.sp3.DataBits = 8;
|
|||
|
|
Form1.sp3.StopBits = StopBits.One;
|
|||
|
|
Form1.sp3.ReceivedBytesThreshold = 1;
|
|||
|
|
Form1.sp3.DataReceived += new SerialDataReceivedEventHandler(serialPort_wenshidu_DataReceived1);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp3.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
button6.Enabled = false;
|
|||
|
|
|
|||
|
|
Form1.sp4.PortName = "COM8";
|
|||
|
|
Form1.sp4.BaudRate = 9600;
|
|||
|
|
Form1.sp4.Parity = Parity.None;
|
|||
|
|
Form1.sp4.DataBits = 8;
|
|||
|
|
Form1.sp4.StopBits = StopBits.Two;
|
|||
|
|
Form1.sp4.ReceivedBytesThreshold = 1;
|
|||
|
|
Form1.sp4.DataReceived += new SerialDataReceivedEventHandler(serialPort_dianyadianliu_DataReceived);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Form1.sp4.Open();
|
|||
|
|
Console.WriteLine("多参数串口打开成功");
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw (new Exception("打开多参数串口出错:" + ex.Message));
|
|||
|
|
}
|
|||
|
|
button9.Enabled = false;
|
|||
|
|
|
|||
|
|
string strSecond = "01 03 00 00 00 02 C4 0B";
|
|||
|
|
//处理数字转换
|
|||
|
|
string sendBuf = strSecond;
|
|||
|
|
string sendnoNull = sendBuf.Trim();
|
|||
|
|
string sendNOComma = sendnoNull.Replace(',', ' '); //去掉英文逗号
|
|||
|
|
string sendNOComma1 = sendNOComma.Replace(',', ' '); //去掉中文逗号
|
|||
|
|
string strSendNoComma2 = sendNOComma1.Replace("0x", ""); //去掉0x
|
|||
|
|
strSendNoComma2.Replace("0X", ""); //去掉0X
|
|||
|
|
string[] strArray = strSendNoComma2.Split(' ');
|
|||
|
|
|
|||
|
|
int byteBufferLength = strArray.Length;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
byteBufferLength--;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// int temp = 0;
|
|||
|
|
byte[] byteBuffer = new byte[byteBufferLength];
|
|||
|
|
int ii = 0;
|
|||
|
|
for (int i = 0; i < strArray.Length; i++) //对获取的字符做相加运算
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Byte[] bytesOfStr = Encoding.Default.GetBytes(strArray[i]);
|
|||
|
|
|
|||
|
|
int decNum = 0;
|
|||
|
|
if (strArray[i] == "")
|
|||
|
|
{
|
|||
|
|
//ii--; //加上此句是错误的,下面的continue以延缓了一个ii,不与i同步
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
decNum = Convert.ToInt32(strArray[i], 16); //atrArray[i] == 12时,temp == 18
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try //防止输错,使其只能输入一个字节的字符
|
|||
|
|
{
|
|||
|
|
byteBuffer[ii] = Convert.ToByte(decNum);
|
|||
|
|
}
|
|||
|
|
catch (System.Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("字节越界,请逐个字节输入!", "Error");
|
|||
|
|
//timer_EXO2.Enabled = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ii++;
|
|||
|
|
}
|
|||
|
|
sp2.Write(byteBuffer, 0, byteBuffer.Length);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer6_Tick(object sender, EventArgs e)//定时监控socket
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (tclient.Connected == false)
|
|||
|
|
{
|
|||
|
|
tclient.Connect(tbIP.Text, Convert.ToInt32(tbPort.Text));
|
|||
|
|
if (tclient.Connected == true)
|
|||
|
|
btnopen.Text = "关闭";
|
|||
|
|
|
|||
|
|
ns1 = tclient.GetStream();
|
|||
|
|
ns2 = tclient.GetStream();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
tclient.Close();
|
|||
|
|
tclient = new TcpClient();
|
|||
|
|
btnopen.Text = "打开";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
tclient.Close();
|
|||
|
|
tclient = new TcpClient();
|
|||
|
|
MessageBox.Show(ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer7_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Sonar_Show(true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer8_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
btnDO1_Click_1(null,null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer9_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (btnopen.Text=="打开") {
|
|||
|
|
btnopen_Click(null, null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void timer10_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Initialization_Sonar();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/* public void write(string str, TextBox tb)
|
|||
|
|
{
|
|||
|
|
if (InvokeRequired)
|
|||
|
|
this.Invoke(new Write(write), str, tb);
|
|||
|
|
else
|
|||
|
|
tb.AppendText("\r\n" + str);
|
|||
|
|
}
|
|||
|
|
private void target()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
StateObject state = new StateObject();
|
|||
|
|
state.worksocket = Soc;
|
|||
|
|
Soc.BeginReceive(state.buffer, 0, state.buffer.Length, 0, new AsyncCallback(ReceiveCallBack), state);
|
|||
|
|
}
|
|||
|
|
catch (Exception err)
|
|||
|
|
{
|
|||
|
|
write(err.Message, textBox1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void ReceiveCallBack(IAsyncResult ar)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
StateObject state = (StateObject)ar.AsyncState;
|
|||
|
|
Socket client = state.worksocket;
|
|||
|
|
int bytesRead = client.EndReceive(ar);
|
|||
|
|
state.sb.Append(System.Text.Encoding.UTF8.GetString(state.buffer, 0, bytesRead));
|
|||
|
|
string aa = state.sb.ToString();
|
|||
|
|
state.sb.Remove(0, aa.Length);
|
|||
|
|
write(aa, textBox1);
|
|||
|
|
client.BeginReceive(state.buffer, 0, state.buffer.Length, 0, new AsyncCallback(ReceiveCallBack), state);
|
|||
|
|
}
|
|||
|
|
catch (Exception err)
|
|||
|
|
{
|
|||
|
|
write(err.Message, textBox1);
|
|||
|
|
}
|
|||
|
|
}*/
|
|||
|
|
}
|
|||
|
|
}
|