Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set serial port pin high using python

Is it possible to set one pin of the serial port continuously high using python (or C)? If yes, how?

like image 492
morph Avatar asked Mar 13 '10 15:03

morph


People also ask

Is Pyserial the same as serial?

PySerial is a library which provides support for serial connections ("RS-232") over a variety of different devices: old-style serial ports, Bluetooth dongles, infra-red ports, and so on.

Is Pyserial full duplex?

Yes serial port hardware is full duplex. Yes, you can use threads to do Rx and Tx at the same time. Alternatively, you can use a single thread loop that does reads with a short timeout and alternates between reading and writing. Save this answer.


2 Answers

Using the pyserial methods setRTS(level=True) and setDTR(level=True) you can control the RTS and DTR lines at will. For instance, the following code will toggle the RTS pin of the first serial port. (See the pyserial documentation for the details).

import time
import serial

ser = serial.Serial(0)
ser.setRTS(False)
time.sleep(0.5)
ser.setRTS(True)
time.sleep(0.5)
ser.setRTS(False)
like image 139
Alejandro Avatar answered Oct 18 '22 22:10

Alejandro


Yes it is possible using pySerial.

like image 45
Pratik Deoghare Avatar answered Oct 18 '22 21:10

Pratik Deoghare