Astro VG876图像信号发生器控制软件

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 { }
        }
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zybpub

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值