0

I would like to send but especially receive serial communication using the RS-232 standard. I would like to write a python program to receive data and then write it to files when they come down the line.

How do i write a program in Python to block while waiting for data to arrive instead of spinning in a loop and checking?

3 Answers 3

6

Try pySerial

Sign up to request clarification or add additional context in comments.

1 Comment

Please refer to How do I write a good answer? and refrain from answering questions with a single link and no explanation.
1

select

1 Comment

This does not qualify as an answer to the question. Please see How do I write a good answer?
0

Use this code:

def read_data():
    data = ser.read(1)
    if data:
        n = ser.inWaiting()
        if n > 0: data += ser.read(n)
        return data

ser = serial.Serial(...)
print read_data()

You can experiment with timeout param for make the function more efficient.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.