Seite 1 von 1

Relais mit der seriellen Schnittstelle ansteuern

Verfasst: Montag 29. Mai 2006, 07:00
von KiS
Hi Leute!
Ich möchte mit Python auf die serielle Schnittstelle zugreifen und dann Relais ansteuern. Aber ich habe null Ahnung wie ich das machen soll :D
Kann mir irgendwer helfen?

Verfasst: Montag 29. Mai 2006, 07:52
von querdenker
Die Suche hast du schon verwendet, oder ?

mfg, querdenker

Verfasst: Montag 29. Mai 2006, 07:59
von KiS
Ja aber die haben nur einen Link zu folgender Seite:
http://pyserial.sourceforge.net/
reicht einfach der Code:
Open port 0 at "9600,8,N,1", no timeout

>>> import serial
>>> ser = serial.Serial(0) #open first serial port
>>> print ser.portstr #check which port was realy used
>>> ser.write("hello") #write a string
>>> ser.close() #close port

Open named port at "19200,8,N,1", 1s timeout

>>> ser = serial.Serial('/dev/ttyS1', 19200, timeout=1)
>>> x = ser.read() #read one byte
>>> s = ser.read(10) #read up to ten bytes (timeout)
>>> line = ser.readline() #read a '\n' terminated line
>>> ser.close()

Open second port at "38400,8,E,1", non blocking HW handshaking

>>> ser = serial.Serial(1, 38400, timeout=0,
... parity=serial.PARITY_EVEN, rtscts=1)
>>> s = ser.read(100) #read up to one hunded bytes
... #or as much is in the buffer

Get a Serial instance and configure/open it later

>>> ser = serial.Serial()
>>> ser.baudrate = 19200
>>> ser.port = 0
>>> ser
Serial<id=0xa81c10, open=False>(port='COM1', baudrate=19200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=0, rtscts=0)
>>> ser.open()
>>> ser.isOpen()
True
>>> ser.close()
>>> ser.isOpen()
False

Und mehr brauch ich nicht?

Verfasst: Montag 29. Mai 2006, 16:54
von Leonidas
KiS hat geschrieben:Und mehr brauch ich nicht?
  • Ausprobieren?
  • Dokumentation ansehen?