Writing to a COM port in C # or python

im trying to write a string in COM4, ​​which is a usb-serial adapter using Visual Studio C #, and got the following error:

Access to the "COM4" port is denied.

My program is very simple:

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

I also tried using pyserial with python and got:

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.)

I know this question is not related to programming and probably refers to Windows 7, but I was hoping that someone already had a similar problem.

+3
source share
3 answers

. , , - , (64- Python 32- pyserial), .

, , , #, . python.

+1

:

" ". Windows 7 . , COM- .

+1

. , , .

+1

Source: https://habr.com/ru/post/1763199/


All Articles