进行串行通信的基本示例

进行串行通信的基本示例

本文介绍了与 Windows XP/win32 进行串行通信的基本示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用需要通过串行通信的外围设备.我可以使用超级终端向它发送命令,但现在我需要编写程序,让我在没有超级终端的情况下也能做到.有人可以将我指向一个网站和/或向我展示一个示例 hello world 程序以帮助我入门吗?我搜索了许多网站,这些网站提供了无法编译/古老的 VC6 代码.

I am working with a peripheral device that needs to be communicated through serial. I can send it commands using HyperTerminal, but now I need to write programs that will let me do it without HyperTerminal. Can somebody point me to a website and/or show me a sample hello world program to get me started? I have searched through many sites which give me uncompilable/ancient VC6 code.

推荐答案

为了与串行端口连接,您需要打开一个文件名为COM1"到COM9"的特殊文件名之一.对于数字较大的串口,特殊文件名以\\?\开头,在C/C++代码中必须转义为\\\\?\\COM10"等

In order to interface with the serial port, you open a file with one of the special filenames "COM1" through "COM9". For serial ports with higher numbers, the special filename begins with \\?\, which in C/C++ code must be escaped as "\\\\?\\COM10", etc.

http://msdn.microsoft.com/en-us/library/ms810467.aspx 有一个关于使用串行端口.请注意,您应该使用 Windows 文件 I/O 函数,例如 CreateFile()ReadFile()WriteFile().我不确定使用标准 I/O 函数(例如 fopen()fread()fwrite() 是否可行)>.

http://msdn.microsoft.com/en-us/library/ms810467.aspx has a really good tutorial on using the serial port. Note that you should use the Windows file I/O functions such as CreateFile(), ReadFile(), and WriteFile(). I'm not sure if it will work to use standard I/O functions such as fopen(), fread(), and fwrite().

这篇关于与 Windows XP/win32 进行串行通信的基本示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:21