如何配置和与串行端口通信? [英] How do I configure and communicate with a serial port?

查看:168
本文介绍了如何配置和与串行端口通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过串行连接(RS-232和RS-422)发送和接收数据。

如何设置和连接这样的连接?我如何确定配置设置(例如波特率)应该是什么,以及如何设置它们?

特别是我正在寻找这样做在Java,C / C ++或主要Unix shell,但我也对使用Windows / Hyperterminal的串行编程感兴趣。

解决方案

构建时间机器,回到1987?


我如何做?找出配置设置(例如波特率)应该是...


阅读数据表?好的好的。认真的,最后一个。如果您不知道您尝试与之通信的设备的波特率,您有两个选择。开始猜测,或者可能打破o范围。如果你需要一个好的起点,让我建议9600-8-N-1。我的怀疑是你可以相对迅速地用暴力到达那里。有一个第三个选择,有一个老师忍者谁可以告诉刚才的LOCK的混乱字符在一些标准的波特率什么实际波特率。一个令人印象深刻的派对诀窍是确定的。



希望你有权访问这些信息。在unix / linux中,你可以直接使用minicom来播放串口。


其中一个主要的Unix shell


在Unix中,串行端口被文件映射到/ dev / subdir。 ttyS0。如果你设置正确的波特率和使用minicom的什么,你甚至可以猫的东西到那个文件发送东西在那里。



在问题的肉,你可以通过POSIX头以编程方式访问它。 termios.h是大的。



查看: http://www.easysw.com/~mike/serial/serial.html#3_1
(不会提供任何内容)


但我也对使用Windows / Hyperterminal的串行编程感兴趣。


Hyperterminal和minicom基本上是相同的程序。至于Windows如何让你访问串口,我会离开这个问题给别人。我从没有这样做在Windows自Win95天。


I need to send and receive data over serial connections (RS-232 and RS-422).

How do I set up and communicate with such a connection? How do I figure out what the configuration settings (e.g. baud rate) should be and how do I set them?

In particular I am looking to do this in Java, C/C++, or one of the major Unix shells but I also have some interest in serial programming using Windows/Hyperterminal.

解决方案

Build a time machine and go back to 1987? Ho ho.

Ok, no more snarky comments.

How do I figure out what the configuration settings (e.g. baud rate) should be...

Read the datasheet? Ok, ok. Seriously, last one. If you don't know the baud rate of the device you are trying to communicate with, you have two choices. Start guessing, or possibly bust out an o-scope. If you need a good starting point, let me suggest 9600-8-N-1. My suspicion is you can get there with brute force relatively quickly. There's a third option of having an old-school ninja who can tell just by the LOOK of the garbled characters at some standard baud rate what actual baud rate is. An impressive party trick to be sure.

Hopefully though you have access to this information. In unix/linux, you can get ahold of minicom to play with the serial port directly. This should make it fairly quick to get the configuration figured out.

one of the major Unix shells

In Unix the serial port(s) is/are file-mapped into the /dev/ subdir. ttyS0, for example. If you setup the correct baud rate and whatnot using minicom, you can even cat stuff to that file to send stuff out there.

On to the meat of the question, you can access it programmatically through the POSIX headers. termios.h is the big one.

See: http://www.easysw.com/~mike/serial/serial.html#3_1 (NOT AVAILABLE ANYMORE)

but I also have some interest in serial programming using Windows/Hyperterminal.

Hyperterminal and minicom are basically the same program. As for how Windows let's you get access to the serial port, I'll leave that question for someone else. I haven't done that in Windows since the Win95 days.

这篇关于如何配置和与串行端口通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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