0

I'm trying to send and receive messages between two Linux running laptops via serial communication using Python. The receiver system must see the message "waiting for the message" until it receives the message from the sender. I was searching for sample code to test this. The sample code I have for the sender is as follows:

import serial
com = serial.Serial('/dev/ttyUSB0',baudrate=115200)
com.write('2')
com.close()

But I cannot figure out what to put for the receiver code, where it will display a message on the receivers display as "waiting" and once the message is received it should display "received".

Does anyone have a sample code to work this out?

1
  • What have you looked for or tried? Commented Jun 27, 2013 at 6:04

1 Answer 1

1

Reading a serial device is as easy as reading a file:

import serial
com = serial.Serial('/dev/ttyUSB0',baudrate=115200)

print "Waiting for message"

char = com.read(1)
print char

com.close()
Sign up to request clarification or add additional context in comments.

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.