ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 02 Aug 2011 22:17:24 +0200read from serial porthttps://ask.sagemath.org/question/8208/read-from-serial-port/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!
Mon, 01 Aug 2011 18:47:22 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/Answer by Bill for <p>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</p>
<p>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?</p>
<p>Thanks!</p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?answer=12551#post-id-12551This ended up working for me, both in command line, and notebook:
>
<pre><code>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
</code></pre>
I found the solution <a href="http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder"> here</a>.
Tue, 02 Aug 2011 22:17:24 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?answer=12551#post-id-12551Answer by benjaminfjones for <p>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</p>
<p>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?</p>
<p>Thanks!</p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?answer=12549#post-id-12549You should install the python library using `sage -python`. See the answer to this related question: http://ask.sagemath.org/question/537/import-data-xls#925Mon, 01 Aug 2011 19:28:59 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?answer=12549#post-id-12549Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21433#post-id-21433I executed this commange from the pySerial folder: sage -python setup.py installMon, 01 Aug 2011 19:43:30 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21433#post-id-21433Comment by benjaminfjones for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21428#post-id-21428Look 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".Mon, 01 Aug 2011 19:51:40 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21428#post-id-21428Comment by benjaminfjones for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21423#post-id-21423Are 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?Tue, 02 Aug 2011 14:27:31 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21423#post-id-21423Comment by benjaminfjones for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21431#post-id-21431It would be helpful if you post the actual code that produces the error and the error itself.Mon, 01 Aug 2011 19:45:31 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21431#post-id-21431Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21432#post-id-21432now in a sage notebook, my commands "import serial" "import pySerial" "import pyserial-2.5, etc all give errors.Mon, 01 Aug 2011 19:44:39 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21432#post-id-21432Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21427#post-id-21427That as well gives me the error "ImportError: No module named serial"Mon, 01 Aug 2011 19:57:53 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21427#post-id-21427Comment by benjaminfjones for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21426#post-id-21426I 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/1119201Mon, 01 Aug 2011 20:07:58 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21426#post-id-21426Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21424#post-id-21424@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! Tue, 02 Aug 2011 13:51:02 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21424#post-id-21424Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21422#post-id-21422I 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'. Tue, 02 Aug 2011 14:45:41 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21422#post-id-21422Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21430#post-id-21430>import pyserial No module named serialMon, 01 Aug 2011 19:47:28 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21430#post-id-21430Comment by Bill for <p>You should install the python library using <code>sage -python</code>. See the answer to this related question: <a href="http://ask.sagemath.org/question/537/import-data-xls#925">http://ask.sagemath.org/question/537/...</a></p>
https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21429#post-id-21429import pyserial-2.5 SyntaxError: invalid syntaxMon, 01 Aug 2011 19:47:52 +0200https://ask.sagemath.org/question/8208/read-from-serial-port/?comment=21429#post-id-21429