using System;
using System.Windows.Forms;
namespace VG876控制软件
{
public partial class Form_VG876 : Form
{
public Form_VG876()
{
InitializeComponent();
}
private void Form_VG876_Load(object sender, EventArgs e)
{
foreach (string com in System.IO.Ports.SerialPort.GetPortNames()) //自动获取串行口名称
{
cmb_serialPort.Items.Add(com);
}
try { cmb_serialPort.Text = config_json.VG876_PortName; } catch { }
this.serialPort_VG876.BaudRate = 38400;
}
class config_json
{
//VG876
public static string VG876_PortName = "COM3"; //
public static byte[] pattern_white = { 0x02, 0xfd, 0x24, 0x20, 0x31, 0x31, 0x32, 0x31, 0x2c, 0x32, 0x03 };
public static byte[] pattern_red = { 0x02, 0xfd, 0x24, 0x20, 0x31, 0x31, 0x32, 0x32, 0x2c, 0x32, 0x03 };
public static byte[] pattern_green = { 0x02, 0xfd, 0x24, 0x20, 0x31, 0x31, 0x32, 0x33, 0x2c, 0x32, 0x03 };
public static byte[] pattern_blue = { 0x02, 0xfd, 0x24, 0x20, 0x31, 0x31, 0x32, 0x34, 0x2c, 0x32, 0x03 };
public static byte[] pattern_black = { 0x02, 0xfd, 0x24, 0x20, 0x31, 0x31, 0x32, 0x35, 0x2c, 0x32, 0x03 };
public static byte[] pattern_50gray = { 0x02, 0xfd, 0x24, 0x20, 0x31, 0x31, 0x32, 0x36, 0x2c, 0x32, 0x03 };
}
private void btn_open_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false)
{
tb_memo.Text += "端口已打开成功!";
serialPort_VG876.Open();
btn_open.Enabled = false;
}
else
{ tb_memo.Text += "端口已打开或被占用!"; }
}
private void btn_close_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen) {
serialPort_VG876.Close();
tb_memo.Text = "端口关闭成功!";
btn_open.Enabled = true;
}
}
private void btn_white_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try { serialPort_VG876.Write(config_json.pattern_white, 0, config_json.pattern_white.Length); } catch { }
}
private void btn_red_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try
{
serialPort_VG876.Write(config_json.pattern_red, 0, config_json.pattern_white.Length);
}
catch { }
}
private void btn_green_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try
{
serialPort_VG876.Write(config_json.pattern_green, 0, config_json.pattern_white.Length);
}
catch { }
}
private void btn_blue_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try
{
serialPort_VG876.Write(config_json.pattern_blue, 0, config_json.pattern_white.Length);
}
catch { }
}
private void brn_black_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try
{
serialPort_VG876.Write(config_json.pattern_black, 0, config_json.pattern_white.Length);
}
catch { }
}
private void btn_50gray_Click(object sender, EventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try
{
serialPort_VG876.Write(config_json.pattern_50gray, 0, config_json.pattern_white.Length);
}
catch { }
}
private void Form_VG876_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort_VG876.IsOpen == false) serialPort_VG876.Open();
try
{
if (serialPort_VG876.IsOpen) serialPort_VG876.Close();
}
catch { }
}
}
}