Ask Your Question
1

read from serial port

asked 2011-08-01 18:47:22 +0200

Bill gravatar image

I'm trying to get sagemath to read from my USB port which has an arduino attached to it. The arduino is throwing a bunch of text to the serial port with address /dev/ttyUSB0

A preliminary Google search reveals that there is a python library pySerial which is designed to do just this. Can I make sagemath recognize this library somehow?

Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-08-01 19:28:59 +0200

benjaminfjones gravatar image

You should install the python library using sage -python. See the answer to this related question: http://ask.sagemath.org/question/537/...

edit flag offensive delete link more

Comments

I executed this commange from the pySerial folder: sage -python setup.py install

Bill gravatar imageBill ( 2011-08-01 19:43:30 +0200 )edit

now in a sage notebook, my commands "import serial" "import pySerial" "import pyserial-2.5, etc all give errors.

Bill gravatar imageBill ( 2011-08-01 19:44:39 +0200 )edit

It would be helpful if you post the actual code that produces the error and the error itself.

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-01 19:45:31 +0200 )edit

>import pyserial No module named serial

Bill gravatar imageBill ( 2011-08-01 19:47:28 +0200 )edit

import pyserial-2.5 SyntaxError: invalid syntax

Bill gravatar imageBill ( 2011-08-01 19:47:52 +0200 )edit

Look at the example from the pySerial documentation: http://pyserial.sourceforge.net/shortintro.html The correct module to import is "serial", not "pyserial" or "pyserial-2.5".

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-01 19:51:40 +0200 )edit

That as well gives me the error "ImportError: No module named serial"

Bill gravatar imageBill ( 2011-08-01 19:57:53 +0200 )edit

I just downloaded pyserial-2.5, used `sage -python setup.py install`, then ran sage at the terminal and did `import serial`. I get no errors. Here is the log: https://gist.github.com/1119201

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-01 20:07:58 +0200 )edit

@benjaminfjones: I seem to be able to have it work in the sage command line, but still get errors in the sage notebook. Any idea why this might be? Thanks for your help!

Bill gravatar imageBill ( 2011-08-02 13:51:02 +0200 )edit

Are you using the same Sage installation for the command line and the notebook? If you run the command line Sage where `import serial` works, and then do `notebook()`, does import serial work in the notebook that loads?

benjaminfjones gravatar imagebenjaminfjones ( 2011-08-02 14:27:31 +0200 )edit

I run from the sage command line 'import serial' and it works, then from the same command line I run notebook() and 'import serial' returns the error 'No module named serial'.

Bill gravatar imageBill ( 2011-08-02 14:45:41 +0200 )edit
0

answered 2011-08-02 22:17:24 +0200

Bill gravatar image

This ended up working for me, both in command line, and notebook:

cmd_folder = os.path.dirname(os.path.abspath('/home/william/pyserial-2.5/serial'))
if cmd_folder not in sys.path:
    sys.path.insert(0, cmd_folder)
import serial

I found the solution here.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-08-01 18:47:22 +0200

Seen: 869 times

Last updated: Aug 02 '11