直流电源IT6800PC控制软件 专用类

using System;
using System.IO.Ports;

namespace Nathan_Soft
{

//直流电源IT6800PC控制软件 专用类
    public class It6800_Command {
        public static string pc_remote = "AA 09 20 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D4";
        public static string local_control = "AA 09 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 D3";
        public static string Set_5V = "AA 09 23 88 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 71";
        public static string Set_12V = "AA 09 23 E0 2E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 E4";
    }
    public class Serial_It6800
    {
        byte[] command = new byte[26];
        SerialPort serialPort;
        public Serial_It6800() {

           
        }

        public string Portname;
        public Int16 BaudRate = 9600;
        private void  command_set_zero() {
            command = new byte[26];
            for (int i = 0; i < 26; i++) command[i] = 0;
        }

        public string set_remote_control() {
            command_set_zero();
            serialPort = Get_SerialPort();
            command[0] = 0xAA;
            command[1] = Convert.ToByte(config_json.SerialPort_Addr);
            command[2] = 0x20;
            command[3] = 0x01;
            command[25] = gen_check();
            return SendCommandToIT6800();
        }

        public string send_command(string command)
        {
            serialPort = Get_SerialPort();
            try
            {
                serialPort.Open();
                try
                {
                    serialPort.Write(HexToByte(command), 0, 26);
                    System.Threading.Thread.Sleep(1000);
                    serialPort.Close();
                }
                catch (Exception ex){
                    serialPort.Close();
                    return ex.Message;
                }
                return "Portname:" + serialPort.PortName + " Baudrate:" + serialPort.BaudRate + " DataBits:" + serialPort.DataBits + " Stopbit:" + serialPort.StopBits + " Parity:" + serialPort.Parity
                    + "\r\n command:" + command+"\r\n";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        /// <summary>
        /// HexToByte
        /// </summary>
        private byte[] HexToByte(string msg)
        {
            msg = msg.Replace(" ", "");
            byte[] comBuffer = new byte[msg.Length / 2];
            for (int i = 0; i < ms

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zybpub

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

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

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

打赏作者

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

抵扣说明:

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

余额充值