• 大小: 105KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: C#
  • 标签: SCPI  

资源简介

winform串口通过SCPI协议与数控电源M8811通信

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO.Ports;
using System.Threading;

namespace DPtest
{
    class DPM88
    {
        SerialPort sp = new SerialPort();
        public DPM88()
        {
            sp.DataBits = 8;
            sp.Parity = Parity.None;
            sp.StopBits = StopBits.One;
            sp.ReadBufferSize = 4096;
            sp.ReadTimeout = 50;
            sp.ReceivedBytesThreshold = 1;
        }

        int waitTime = 500;
        public bool OpenDevice(int baudrate)
        {
            bool ret = false;
            if (sp.IsOpen)
                sp.Close();
            string[] spNames = SerialPort.GetPortNames();
            foreach (var v in spNames)
            {
                try
                {
                    sp.PortName = v;
                    sp.BaudRate = baudrate;
                    sp.Open();

                    sp.WriteLine(“*IDN?“);
                    long tgTime = DateTime.Now.Ticks + 10000 * waitTime;
                    while (sp.BytesToRead < 0 && tgTime < DateTime.Now.Ticks)
                        Thread.Sleep(1);

                    if (sp.BytesToRead > 0)
                    {
                        sp.DiscardInBuffer();
                        ret = true;
                        sp.WriteLine(“SYST:REM“);
                        break;
                    }
                }
                catch { }
            }
            return ret;
        }
        public void SetVoltage(double voltage)
        {
            string str = voltage.ToString(“0.0000“);
            sp.WriteLine(“VOLT “ + str);
        }
        public void SetCurrent(double current)
        {
            string str = current.ToString(“0.0000“);
            sp.WriteLine(“CURR “ + str);
        }
        public double GetSetVoltage()
        {
            double vol = 0;
            vol = GetDoubleCmd(“VOLT?“);
            return vol;
        }
        public double GetSetCurrent()
        {
            double cur = 0;
            cur = GetDoubleCmd(“CURR?“);
            return cur;
        }
        public double GetOutVoltage()
        {
            double vol = 0;
            vol = GetDoubleCmd(“MEAS:VOLT?“);
            return vol;
        }
        public double GetOutCurrent()
        {
            double cur = 0;
            cur = GetDoubleCmd(“MEAS:CURR?“);
            return cur;
        }
        private double GetDoubleCmd(string cmd)
        {
            double ret = 0;
            sp.WriteLine(cmd);
            long tgTime = DateTime.Now.Ticks + 10000 * waitTime;
            while (sp.BytesToRead < 0 && tgTime < DateTime.Now.Ticks)
                Thread.Sleep(1);

            if (sp.BytesToRead > 0)
            {
                try
                {
                    string str = sp.ReadLine();
                    ret = Convert.ToDouble(str);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11264  2016-10-21 20:33  SCPI\DigitalPower\bin\Debug\DigitalPower.exe

     文件      30208  2016-10-21 20:33  SCPI\DigitalPower\bin\Debug\DigitalPower.pdb

     文件      24216  2016-10-21 22:30  SCPI\DigitalPower\bin\Debug\DigitalPower.vshost.exe

     文件        490  2010-03-17 22:39  SCPI\DigitalPower\bin\Debug\DigitalPower.vshost.exe.manifest

     文件       3738  2016-10-21 19:24  SCPI\DigitalPower\DigitalPower.csproj

     文件       2398  2016-10-21 20:33  SCPI\DigitalPower\Form1.cs

     文件       6078  2016-10-21 20:33  SCPI\DigitalPower\Form1.Designer.cs

     文件       6016  2016-10-21 20:33  SCPI\DigitalPower\Form1.resx

     文件        865  2016-10-21 15:55  SCPI\DigitalPower\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6821  2016-10-21 20:33  SCPI\DigitalPower\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1388  2016-10-21 22:30  SCPI\DigitalPower\obj\Debug\DigitalPower.csproj.FileListAbsolute.txt

     文件        977  2016-10-21 20:33  SCPI\DigitalPower\obj\Debug\DigitalPower.csproj.GenerateResource.Cache

     文件       2211  2016-10-21 19:24  SCPI\DigitalPower\obj\Debug\DigitalPower.csprojResolveAssemblyReference.cache

     文件      11264  2016-10-21 20:33  SCPI\DigitalPower\obj\Debug\DigitalPower.exe

     文件        180  2016-10-21 20:33  SCPI\DigitalPower\obj\Debug\DigitalPower.Form1.resources

     文件      30208  2016-10-21 20:33  SCPI\DigitalPower\obj\Debug\DigitalPower.pdb

     文件        180  2016-10-21 19:24  SCPI\DigitalPower\obj\Debug\DigitalPower.Properties.Resources.resources

     文件        493  2016-10-21 15:55  SCPI\DigitalPower\Program.cs

     文件       1366  2016-10-21 15:55  SCPI\DigitalPower\Properties\AssemblyInfo.cs

     文件       2876  2016-10-21 15:55  SCPI\DigitalPower\Properties\Resources.Designer.cs

     文件       5612  2016-10-21 15:55  SCPI\DigitalPower\Properties\Resources.resx

     文件       1099  2016-10-21 15:55  SCPI\DigitalPower\Properties\Settings.Designer.cs

     文件        249  2016-10-21 15:55  SCPI\DigitalPower\Properties\Settings.settings

     文件       1005  2016-10-21 15:55  SCPI\DigitalPower.sln

    ..A..H.     33792  2016-10-21 22:43  SCPI\DigitalPower.v12.suo

     文件      13824  2016-10-21 21:10  DPtest\DPtest\bin\Debug\DPtest.exe

     文件      34304  2016-10-21 21:10  DPtest\DPtest\bin\Debug\DPtest.pdb

     文件      22704  2016-10-21 22:33  DPtest\DPtest\bin\Debug\DPtest.vshost.exe

     文件        490  2010-03-17 22:39  DPtest\DPtest\bin\Debug\DPtest.vshost.exe.manifest

     文件       4120  2016-10-21 21:08  DPtest\DPtest\DPM88.cs

............此处省略40个文件信息

评论

共有 条评论

相关资源