0

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
dsolimano
  • 8,870
  • 3
  • 48
  • 63
Alex
  • 41,580
  • 88
  • 260
  • 469
  • How did you implement the XMLRPC server? You are not showing any code from there. – Janne Karila Oct 29 '12 at 13:44
  • It would be too much to post here. But I am sure that I perform the exact same commands in the same order in both cases, but the result is very different. – Alex Oct 29 '12 at 13:47
  • I see it has separate open, send and read functions, so it is not quite the same. Try exposing the upper code snippet as a single function and see if that makes any difference. – Janne Karila Oct 29 '12 at 13:53
  • I do not quite understand what you suggest. – Alex Oct 29 '12 at 14:02
  • I mean, just for troubleshooting, create a function on the RPC server that opens the device, sends command, waits, reads the response and closes the device. All in a single RPC call. See if that works any better. – Janne Karila Oct 29 '12 at 14:05
  • So, with all the example sequence in one function on the server side in C++, called by the python side via xmlrpc, it does seem to work. What does this mean? That the xmlrpc request chain breaks something up? (I have also implemented the server side in python instead of C++ to talk to the serial port - works without problem. So the xmlrpc does not seem to be the problem. Neither the modem. And neither C++. ) – Alex Oct 29 '12 at 14:22
  • The issue could have something to do with how the C++ xmlrpc server processes the requests. Is it multithreaded? That could complicate things. – Janne Karila Oct 29 '12 at 14:26
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18723/discussion-between-alex-and-janne-karila) – Alex Oct 29 '12 at 14:27

0 Answers0