c# - 在 C# 或 python 上写入 COM 端口

标签 c# windows-7 serial-port pyserial

我正在尝试使用 Visual Studio C# 将字符串写入 COM4,这是一个 usb 串行适配器,但出现以下错误:

Access to the port 'COM4' is denied.

我的程序非常简单:

serialport.Open();
serialport.WriteLine("test");
serialport.Close();

我还尝试将 pyserial 与 python 一起使用并得到:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    ser.write("string")
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 255, in write
    raise SerialException("WriteFile failed (%s)" % ctypes.WinError())
SerialException: WriteFile failed ([Error 6] The handle is invalid.)

我知道这个问题与编程并没有真正的关系,可能是 Windows 7 的问题,但我希望有人已经遇到过类似的问题。

最佳答案

试试这个:

右键单击您的可执行文件并选择“以管理员身份运行”。 Windows 7 默认运行没有管理员权限的程序。我敢打赌,写入 COM 端口的能力需要以管理员身份运行程序。

关于c# - 在 C# 或 python 上写入 COM 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640812/

相关文章:

c# - SQL Server : cannot connect from local website (SQL Network Interfaces, 错误:26 - 定位指定的服务器/实例时出错)

linux - 嗅探IOCTL和串口通信

具有非托管 DLL 的 C# 应用程序卡住整个系统

c# - 部分线程安全的字典

c# - 使用依赖注入(inject)将字典保存在应用程序中的位置

java - 创建 Windows 7 任务栏图标

c# - FileUpload.PostedFile 在 UpdatePanel 中始终为 null

c++ - 关于在 Windows 7 下工作的 Turbo C

node.js - npm 串口获取输出以 react 组件

python - 在 Windows 上使用 pyserial 将串行数据写入 Arduino