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