Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing commands to serial
#5
Thank you, I managed to make it send command, but not to make the

        out = ser.read()
        print('Receiving...'+out)
work. What I am trying to do is this: I wrote a code to read from Arduino through Serial, and I want to send commands to the Arduino through serial (by typing the commands through the keyboard). The code I am using is this:

import serial,time
ser = serial.Serial(
    port='COM4',
    baudrate=38400,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    xonxoff=False
)
line = ser.readline();

while line:
     line = ser.readline()
     print(line)
     ser.reset_input_buffer()
     cmd = input("Enter command or 'exit':") + '\r\n'
     if len(cmd)>0:
        ser.write(cmd.encode())
     else:
        continue
but what I see is that the code blocks, until I print something. I want to read continuously from Serial what Arduino sends and if I type a command from keyboard, to write it to the serial. I am trying changes and I read the pyserial documentation but I cannot figure out something...
Reply


Messages In This Thread
Writing commands to serial - by python_beginner - Jan-30-2018, 02:41 PM
RE: Writing commands to serial - by sparkz_alot - Jan-30-2018, 04:04 PM
RE: Writing commands to serial - by DeaD_EyE - Jan-30-2018, 04:25 PM
RE: Writing commands to serial - by cvh - Jun-23-2020, 08:59 PM
RE: Writing commands to serial - by sparkz_alot - Jan-30-2018, 08:29 PM
RE: Writing commands to serial - by python_beginner - Feb-01-2018, 01:19 PM
RE: Writing commands to serial - by dalwood - Feb-01-2018, 03:48 PM
RE: Writing commands to serial - by DeaD_EyE - Feb-02-2018, 10:10 AM
RE: Writing commands to serial - by jambuna35 - Feb-03-2019, 09:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,507 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Trouble writing over serial EngineerNeil 1 2,672 Apr-07-2019, 08:17 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020