从串口获取数据 [英] Get data from serial port

查看:78
本文介绍了从串口获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从电源安捷伦E3634获得测量但是我变成了这个错误(无限期响应后-440查询未经确认)



我有什么尝试过:



这是我的代码:



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Threading;
使用 System.Management;
使用 System.IO.Ports;
使用 System.IO;

命名空间 ConsoleApplication1
{
class PortDataReceived
{
public static void Main()
{
SerialPort mySerialPort = new SerialPort( COM1);
mySerialPort.BaudRate = 9600 ;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.Two;
mySerialPort.DataBits = 8 ;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true ;
mySerialPort.ReadTimeout = 1000 ;

mySerialPort.Open();

mySerialPort.WriteLine( MEAS:VOLT?);
Thread.Sleep( 750 );

string voltagevalue = mySerialPort.ReadExisting();
Console.WriteLine(voltagevalue);

mySerialPort.Close();
}
}
}

解决方案

猜测 - 这就是它可以没有访问硬件 - 错误消息是说你没有正确终止查询,可能是新行或类似的?



不要跳入代码:潜在的问题来源太多了。相反,从HyperTerminal开始,首先建立可靠的通信:键入命令MEAS:VOLT?进入HT,看看会有什么回来。当您有可靠的通信(并且设备的手册在这里有帮助)时,您可以通过代码开始自动化过程:但直到您知道 完全 什么可以开始,你正在遇到太多未知因素,无法在合理的时间内获得任何好处。手册中的大多数通信描述都过于开放而无法解释(或者只是简单的错过)。



我还会查看制造商的网站,看看是否有任何示例代码可用 - 这可能是一个很好的起点,因为它应该可以正常运行框。

I trying to get measurement From the Power Supply Agilent E3634 but I become this error (-440 Query UNTERMINATED after indefinite response)

What I have tried:

this is my Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Management;
using System.IO.Ports;
using System.IO;

namespace ConsoleApplication1
{
    class PortDataReceived
    {
        public static void Main()
        {
            SerialPort mySerialPort = new SerialPort("COM1");
            mySerialPort.BaudRate = 9600;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.Two;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;
            mySerialPort.RtsEnable = true;
            mySerialPort.ReadTimeout = 1000;

            mySerialPort.Open();

            mySerialPort.WriteLine("MEAS:VOLT?");
            Thread.Sleep(750);

            string voltagevalue = mySerialPort.ReadExisting();
            Console.WriteLine(voltagevalue);

            mySerialPort.Close();
        }
    }
}

解决方案

At a guess - and that's all it can be without access to the hardware - the error message is saying that you didn't terminate the query properly, possibly with a new line or similar?

Don't leap into code: there are too many potential problem sources. Instead, start with something like HyperTerminal and establish reliable communications first: type your command "MEAS:VOLT?" into HT and look at what comes back. When you have reliable communications (and the manual for the device will help here) then you can start automating the process via code: but until you know exactly what works to start with, you are running up against too many unknowns to get anywhere in a reasonable time frame. And most communications descriptions in manuals are far too open to interpretation (or just plain miss stuff out).

I'd also look at the manufacturer's website and see if any sample code is available - that could be a good starting point because it should work "right out of the box".


这篇关于从串口获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆