I have some C++ code to talk to a modem, based on a class BufferedAsyncSerial
(see here) using the serial library from boost. With a short code in C++ like this
BufferedAsyncSerial device("/dev/ttyACM0",9600);
device.writeString("AT\r");
std::cout << device.readString() << std::endl;
boost::this_thread::sleep(boost::posix_time::seconds(2));
std::cout << device.readString() << std::endl;
device.close()
I am able to send an AT
command to an analog modem at the serial port /dev/ttyACM0
and to receive the correct answer from the port, namely 'OK
'. The sleep in between is to ensure the modem has some time to process the input.
All of this I wrapped within a xmlrpc class to communicate the read/write across a different computer (for the test its actually the identical one), so to access the functionality with xmlrpc
with python:
device = xmlrpclib.ServerProxy("http://localhost:8080/RPC2")
device.serial.open("/dev/ttyACM0")
device.serial.send("AT\r")
for i in range(100):
time.sleep(0.1)
print device.serial.read()
On the C++ server side the open/close/read/and write functions are wrapped accordingly, the port name is the same as well as the baud rate. However, when executing these python functions, the AT
is sent to the modem (I am able to read it back through the xmlrpc connection!), but never an OK
appears, no matter how often or how long I try.
If there is a C++/boost/serial/xmlrpc/python specialist available, I would appreciate any advice. Here are some additional comments and remarks:
- The C++ xmlrpc server used is abyss/xmlrpc-c, neither I am familiar with
- If I code all the open/write/read/close chain in a single function I cann over xmlrpc, I get the expected result
- I have checked that the access to the actual BufferedAsyncSerial instance is done through one class and have logged the order and details of each command. They are identical in both cases, I do not miss anything.
- I also have checked that the object I am working on is the same object, i.e. hast the same address in memory