简体   繁体   English

如何在Linux中将二进制数据写入串行端口(RS232)设备文件中?

[英]How to write binary data into a serial port (RS232) device file in linux?

I'm doing a project in linux for which i need to write binary data into the device file of serial port (RS232) port. 我正在Linux中做一个项目,为此我需要将二进制数据写入串行端口(RS232)端口的设备文件中。 when i write the file into serial port (RS232), a RF transmitter connected to this port must send signal to RF receivers situated at different places. 当我将文件写入串行端口(RS232)时,连接到此端口的RF发送器必须将信号发送到位于不同位置的RF接收器。

The data to written is in a user created file.I have to just copy the data from that file and write into the device file whenever user wants(say a button click in java interface) 要写入的数据在用户创建的文件中。我只需要复制该文件中的数据并在用户需要时将其写入设备文件中(例如在Java界面中单击按钮)

I have googled but couldn't get much of the information and some i couldn't understand.What is the simplest way to do this using shell script.(C program will work too) 我已经在谷歌上搜索了,但是无法获得很多信息,有些我无法理解。使用shell脚本执行此操作的最简单方法是什么(C程序也可以工作)

From the command line, for example: 从命令行,例如:

cat file.bin > /dev/ttyPS0
  • file.bin is binary file, file.bin是二进制文件,
  • /dev/ttyPS0 is device representing serial port. /dev/ttyPS0是代表串行端口的设备。

Note: use stty to configure serial port appropriately. 注意:使用stty适当配置串行端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM