I went a round about way to get serial read/write capabilities on a connectport x4. I used the Digi ESP program to write the serial_loopback example to the router and pulled the library from there.
My code is a littler different but you should be able to modify it. I'm taking data from a remote AIO device and trying to write the data to the serial port on the connectport which will be attached to an arduino. CRC implantation is next on my list.
import sys, os
sys.path.insert(0, os.path.join(os.path.abspath('.'), '_serial_loopback-1.zip'))
sys.path.insert(0, os.path.join(os.path.abspath('.'), 'dpdebug.zip'))
import serial
#import termios
from xbee import ddo_get_param, ddo_set_param
from io_sample import parse_is
s = serial.Serial('/com/0', 9600, timeout = 10)
addr = '00:13:a2:00:40:a8:ae:88!'
##Enabling Ten volt mode on terminals 1 and 2
ddo_set_param(addr, 'D8', 4)
ddo_set_param(addr, 'D4', 5)
ddo_set_param(addr, 'D6', 5)
##Enabling terminals 1 and 2 for analog input
ddo_set_param(addr, 'D0', 2)
ddo_set_param(addr, 'D1', 2)
##Applying changes and writing to flash
ddo_set_param(addr, 'AC')
ddo_set_param(addr, 'WR')
##Taking a sensor sample, printing the raw binary string to STDOUT
sample = ddo_get_param(addr, 'IS')
print 'sample(%d)' % len(sample),
for by in sample:
print '%02X' % ord(by),
print
d = parse_is(sample)
s.write ("sample")
print "ADO = ", (d/1023.0*10), "V" #Value has calibration factor from Excel change with every unit
#print "AD1 = ", d/1023.0*10, "V" (1-0.102)
#print "AD2 = ", d/1023.0*10, "V"
#print "AD3 = ", d/1023.0*10, "V"
s.close()