Controlling MDrive 23 with Python under Linux
Question: MDrive 23 motor takes commands from a terminal, and I got it to work with
screen program:

    
    
    screen /dev/ttyUSB0
    

Is this is called a serial terminal? I'm unfamiliar with the details of the
connection, but feel like I should be able to use PySerial to send the
commands.

I tried:

    
    
    import serial
    ser = serial.Serial('/dev/ttyUSB0', 19200)
    ser.isOpen() # Returns True
    ser.write('ma 100000\r\n') # Does nothing...
    ser.inWaiting() # Returns 0
    ser.close()
    

I didn't know how to set the other init variables, like:

    
    
    parity = serial.PARITY_ODD,
    stopbits = serial.STOPBITS_TWO
    bytesize = serial.SEVENBITS    
    

I'm going to try guessing some values next... The documentation is lame, but
it mentions MODBUS TCP and Mcode.

How do I set these and are there any syntax errors in my snippet?

I know how to send arguments to the Serial object, but I do not know what
values are typical.


Answer: The other parameters to the Serial constructor are set in a similar way as
port and baudrate:

    
    
    ser = serial.Serial(port = '/dev/ttyUSB0', baudrate=19200, bytesize=serial.SEVENBITS, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO)
    
    ser.write('whatever')
    ser.flush() # wait for data to be written
    ser.close()
    

* * *

Edit: It [seems](http://motion.schneider-
electric.com/support/knowledge_base.html) the default settings are 9600 baud,
8 bits, no parity and 1 stop bit. In addition no flow-control is used. That
would be equivalent to:

    
    
    ser = serial.Serial(port = '/dev/ttyUSB0', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, xonxoff=False, rtscts=False, dsrdtr=False)
    

As all values, except port, are set to their defaults, you may use:

    
    
    ser = serial.Serial(port = '/dev/ttyUSB0')
    

The last thing to worry about is which (read) timeout to set. This is
measured/set in seconds (float allowed) and sets how long a read() command
will block before returning what has been read.

