Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言格式化输出#_C#_Get_Position - Fatal编程技术网

C# 用C语言格式化输出#

C# 用C语言格式化输出#,c#,get,position,C#,Get,Position,以上是获取步进电机当前位置的代码。下面是指向我的输出的链接。但我无法将其格式化为数字 这是: 这里是输出:您对串行端口的速度估计过高 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports; using System.Threading; namespace ConsoleApplication1 { class Program

以上是获取步进电机当前位置的代码。下面是指向我的输出的链接。但我无法将其格式化为数字

这是:


这里是输出:

您对串行端口的速度估计过高

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            SerialPort sp = new SerialPort();
            sp.PortName = "COM1";
            sp.BaudRate = 9600;
            sp.Open();

            if (sp.IsOpen)
            {
                sp.Write("ENA;");
                Thread.Sleep(1000);

                sp.Write("POS;");
                Thread.Sleep(1000);                    
                string msgPos = sp.ReadExisting();

                Console.WriteLine(msgPos);

                sp.Write("OFF;");
                sp.Close();
                Console.ReadKey();
            }

        }
    }
}
:根据编码读取SerialPort对象的流和输入缓冲区中的所有立即可用字节


当您调用
ReadExisting
时,它将立即返回串行端口缓冲区中已有的数据,这可能远远早于连接的设备接收到
POS
命令。

询问步进电机SDK供应商。其他任何人都不可能知道。如果你解释一下什么是sp,你用什么SDK/API,马达附带了什么手册,也许他们可以解释一下。。。(Beavis和Butthead样式)
POS
…:-)更重要的是,
sp
?一些流媒体阅读器?你在使用图书馆吗?它是什么图书馆?我们需要更多的代码。
sp.Write("POS;");                 // Writes the data to the serial port
string msg = sp.ReadExisting();   // Immediately reads already available data