为 Arduino 编写 Windows 命令行 com-port

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9247630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:13:03  来源:igfitidea点击:

Windows command line com-port writing for Arduino

windowscommand-linearduino

提问by Rai220

I need to send some information from my PC to an Arduino. I tested it with PuTTYand it works great.

我需要将一些信息从我的 PC 发送到 Arduino。我用PuTTY对其进行了测试,效果很好。

I need to send characters, '1' or '2', to control a servo and I am using these commands:

我需要发送字符“1”或“2”来控制伺服,我正在使用这些命令:

mode com10:9600,n,8,1

模式 com10:9600,n,8,1

... and I see that my Arduino received some data.

...我看到我的 Arduino 收到了一些数据。

After that, I try to use that:

之后,我尝试使用它:

echo 1>com10

回声 1>com10

OR

或者

echo "1">com10

echo "1">com10

and nothing nothing happens.

什么也没有发生。

With PuTTY it works corrent and turning, when I press 1 or 2. With the Arduino serial monitor it works great too.

使用 PuTTY,当我按 1 或 2 时,它可以正常工作并转动。使用 Arduino 串行监视器,它也可以很好地工作。

采纳答案by Rai220

At the end, I used PowerShellto do this task:

最后,我使用PowerShell来完成这个任务:

powershell "$port= new-Object System.IO.Ports.SerialPort COM10,9600,None,8,one; $port.open(); $port.WriteLine("1"); $port.Close()"

回答by Khulja Sim Sim

What worked for me was, something like:

对我有用的是,例如:

echo ON > \.\COM4
echo OFF > \.\COM4

Thislink provides some good info.

这个链接提供了一些很好的信息。

So, in general, the format to send simple ASCII chars to serial port:

所以,一般来说,将简单的 ASCII 字符发送到串口的格式:

echo [ASCII chars / string you want to send]    >       \.\    [Com Port #]

回答by jfrmilner

PowerShell is very useful when working with Arduinos, here is a linkto a post where I did the same.

PowerShell 在使用 Arduinos 时非常有用,这里有一个链接,我在那里做了同样的事情。

I've added a COM port lookup and some error handling to ease the process. Hope this helps someone.

我添加了一个 COM 端口查找和一些错误处理来简化这个过程。希望这可以帮助某人。

回答by unununun



mode com3 BAUD=9600 PARITY=n DATA=8 STOP=1 && echo blahblah > com3

模式 com3 BAUD=9600 PARITY=n DATA=8 STOP=1 && echo blahblah > com3



about the same:

差不多:



powershell "$port= new-Object System.IO.Ports.SerialPort COM10,9600,None,8,one; $port.open(); $port.WriteLine("1"); $port.Close()"


回答by dc42

This will send the contents of a file to COM10 under Windows 7, not sure about other versions:

这将在Windows 7下将文件内容发送到COM10,其他版本不确定:

copy myfile \\.\COM10

复制我的文件 \\.\COM10

If you just use "copy myfile COM10" then it creates a file called COM10 instead.

如果您只是使用“copy myfile COM10”,那么它会创建一个名为 COM10 的文件。

So you might like to try:

所以你可能想尝试:

echo 1>\\.\com10

回声 1>\\.\com10

回答by Joey

Three points:

三点:

  1. COM10 isn't a reserved file name like COM1–4, so it couldbe that you're just creating a file.
  2. echo 1>foois the same as echo >foowhich will print ECHO is on.(you're redirecting stream 1, aka stdout).
  3. echo "1">foowill print "1"includingthe quotes.
  1. COM10 不是像 COM1-4 那样的保留文件名,因此您可能只是在创建文件。
  2. echo 1>fooecho >foo将打印的相同ECHO is on.(您正在重定向流 1,又名标准输出)。
  3. echo "1">foo将打印"1"包括引号。

To actually echo a 1somewhere you'd have to use

要实际回声1某个地方,您必须使用

>foo echo 1

or

或者

(echo 1)>foo