# Sending G-code commands to Hyrel System 30M using python

I am using python 3.6 with pySerial library to connect to the Hyrel System 30M 3D Printer. I am able to read the data from the device but unable to write any commands to it

Here is the code:

    ser = serial.Serial()
ser.port = 'COM4'
ser.baudrate = 38400
ser.write(b'M106 T14 S30\n') %This is the command to turn on the fan at 30% power


Can somebody suggest me how to write commands to printer through python

ser.flush()