Join GitHub today
Mar 10, 2011 - You have access to it from the serial port /dev/ttyS1 of the Korebot. What is sugested. Spawn picocom /dev/ttyUSB0 -b 115200 -e y --send-cmd sb -vv picocom v1.4. Expect expect-script /dev/ttyUSB0 'protect on 1:0-1' spawn.
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upHave a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
commented Mar 31, 2015
Hi, I'm working on a project in which I will need to communicate on a serial port (RS232) and I wanted to make my life easy by using PySerial, but I don't see any way of using it, if even possible. I tried a few things but I keep getting crashes. Can you tell me if it's possible? If so, I'd really love a small code example. Else, is there another way of achieving this easily? The only 'special' option I need is to set the baud rate to 115200. Thanks a lot! |
commented Mar 31, 2015
If your platform is unix (not windows) it is probably possible using fdspawn, http://pexpect.readthedocs.org/en/latest/api/fdpexpect.html#fdspawn-class by providing a file descriptor it may read/write to. @erikb85 mentioned some kind of integration with PySerial in issue #137 perhaps he could help. |
commented Mar 31, 2015
If you can get a file descriptor from PySerial, you can use it with fdspawn. Otherwise, once Pexpect 4 comes out, it should be possible to subclass SpawnBase and customise it to work with a serial port object. |
commented Mar 31, 2015
Also if you figure it out and want to make a simple demonstration to examples/ and doc/examples.rst we'd probably accept a pull request for it. |
commented Apr 2, 2015
Thanks a lot for the super fast replies! So, technically, I should be able to use the fileno() function to get the file descriptor number and send it to the fdspawn class? From there, I can simply use the normal functions (expect, send, etc.)? (Kinda new to python too, so sorry if this sounds newbie!) |
commented Apr 2, 2015
correct |
commented Apr 7, 2015
Because I was mentioned I also want to add what we did with pySerial and pexpect. In the past we implemented Ssh connections and serial connections separately. For this we used a ssh library (there are two, but I forgot both names). For serial connections we used pySerial. But there were many things I didn't like about pySerial, number one being that it was very different from the ssh stuff. I wanted to maintain as much as possible in one class, so we switched to pexpect. Now we use pexpect.pxssh() for ssh and scp, and pexpect.fdpexpect.fdspawn()for serial connections. This way we can use the same send()-> expect()` patterns for both connection types.Creating the serial spawn object looks like that: Important here is to use os.open() and not just open() because we want the file descriptor and not a file object. |
commented Apr 7, 2015
![Parallel Parallel](https://fedetft.files.wordpress.com/2010/04/serialgui-linux.png)
Aha, so you didn't use Pexpect and Pyserial together. That's also an interesting data point for the send method with fdspawn - that method is currently removed in master because not all fds are writable, and you can use os.write() in any case. |
commented Apr 20, 2015
PySerial does support fileno(). So, I ended up using PySerial, although I could have simply used the same spawn as erikb85, since it's pretty much the same thing it does in background... Here is some sample code: ser = serial.Serial(serialPort,115200) # open the serial port reader = fdpexpect.fdspawn(ser)#, 'wb', timeout=50) reader.send('x03') state = reader.expect(['#', 'Please press Enter to activate this console.', 'ar7240>']) You could add some things in the doc or wiki if you want. Thanks for the help! |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment