2 Answers
2

You should use the serial device much like a normal file. The only difference is that it needs some ioctl()s to do the speed and control line setup.

So don't use os.system("echo ... but f = open('/dev/ttyUSB3', 'rw') and then f.write() and f.read().

In theory you could use ioctl() to set the speed and so on, but at that stage it's simply easier to use pySerial than to do all of the parameter marshalling yourself. ser = serial.Serial(port='/dev/ttyUSB3', baudrate=9600, timeout=1, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) with ser.write() and ser.read().

thank you, that is perfect. I should have mentioned python in my OP. If I do as you suggest re naming ports, it would think any usb0-9 was a modem? I will have a few other usb interfaces that are not, so is it about finding a unique parameter in that type of interface?
– PaulJan 27 '15 at 11:03

I may have phrased it badly. How would I do this in one command in one terminal? So i would have echo -e "ATZ\r" > /dev/ttyUSB3 but also some way to redirect the results? Is that possible? Or do I misunderstand your answer?
– PaulJan 26 '15 at 15:56

@Paul I don't know what you mean by "redirect". Something must read the data from the modem. In your example that was done by cat. But if the shell reads the data itself then there is no need for redirection. There is input redirection in this case, though.
– Hauke LagingJan 26 '15 at 16:04

By redirect I mean store in a variable/file. I want the data stored after it is read from the modem so that I can manipulate it. I am using python to make the call os.system("echo -e..."). Now what confuses me is do i have to use this read command concurrently in python to running the os.system call or how would I know which data is associated with which command?
– PaulJan 26 '15 at 16:43