Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Tuesday, June 2, 2009

OWFS, GLPK, and Python

OWFS: Two weeks ago I installed OWFS and got it working with the sensors from the command line. This week I experimented with the python bindings to OWFS. Via Python I could easily connect to the sensors and read the temperature. What seemed difficult via the Python bindings was changing the temperature scale from the default of Celsius to common weather temperature of Fahrenheit. Via the command line this was an easy task, via Python binding it was a perplexing situation. After reading the documentation it appears the Python binding is not full featured enough to do this. So I figured I could write a simple Python line to issue the command line setting to complete this task. What prevent this was the binding to OWFS did not leave an obvious path to make this change and did not provide a command to find the path. So my conclusion was to write a Python script where half of it issues commands to the OS as if it were a shell script and then pull the data into Python logging and graphing. Below are some examples of what I needed I needed to do.

First I have to mount the file system for the controlling device. Since this is a USB device I need to do this as root. For now I just run my IDE Eric4 via gksudo until I can think of a better way
os.system('/opt/owfs/bin/owfs -u /var/1-wire/mnt')
So next I enumerate the interfaces on the wire
dirlist = os.popen('ls /var/1-wire/mnt/alarm/').read()
print "these are the interfaces"
print dirlist
PreIfaces = dirlist.split('\n')
IfaceLst = []
for listing in PreIfaces:
if re.match('10\.\w', listing):
print listing, "is a single interface"
listing = str(listing)
IfaceLst.append(listing)
So here is where I change the temperature scale and then see if my change took place

os.system('echo "F" > /var/1-wire/mnt/settings
/units/temperature_scale')
TempScale = os.system('cat /var/1-wire/mnt
/settings/units/temperature_scale && echo')
print TempScale
The rest of my code is learning the best (or most Pythonic) way to pass the list to the function os.popen so I can programmaticly get a temperature on all three interfaces without having to name each one. I think I will also just log the data to three text files using the CSV module for this current version. Then for version 2 of the script I may move logging to SQLite. I have the book
Beginning Python Visualization for guidance with making graphs in Python.

GLPK: So on the Ubuntu Linux machine I got PyMathProg installed. In my past post I stated I had the PyMathProg installed but that was the earlier version (since it was an Ubuntu package), that does not work with the examples on the current PyMathProg site: http://pymprog.sourceforge.net/. So tonight I uninstalled the Ubuntu package version and installed the version from the tarball I downloaded. Then I ran the basic PyMathProg examples and it seems to work now. So give another cheer for progress.

Thursday, May 7, 2009

Ubuntu: New software packages installed

As a follow up to my previous post, I just installed GNU Linear Programming Kit (GLPK) and PyMathProg. GLPK is recommended by Larry of http://industrialengineertools.blogspot.com/ and PyMathProg is a Python implementation of GLPK. I also installed SimPy which is a Python queuing simulation modeler. At some point, after I build a core set of skills, I will provide samples of theses programs in the blog.

Ubuntu to you too or me in this case.

With a focus on Open Source tools while working on Operations Management skills (or the more popular term seems to be Operations Research) I needed to get a machine on an Open Source OS. A various times in the past I have had both physical and virtual machines running Linuxes such as Debian, Red Hat, CentOS, Gentoo and BSDs such FreeBSD (which I really like, but that's a post for another time) and OpenBSD.

Last weekend I decided to try Ubuntu Linux 9.04. Since it is based on Debian I figured it can't be too different. The only sense of difference was when it came to the GUI, it would take me a few tries to get x-window working properly. On Ubuntu it was simple, simple simple. The only thing that took a little bit of thinking was applying the wireless driver. The wireless card (on an old laptop) I used only had Windows drivers. So I got to try the famous Linux NDIS wrappers to run Windows drivers on the Linux OS. Of course since the network was not enabled yet, I had to download the .deb package files, burn them to CD, then mount the CD. Since a command line is not immediately available in Ubuntu by default, running dkpg or apt-get was not an option to install the local .deb files for NDIS. But I found that if I right click the .deb file, "GDebi Package Installer" will install the .deb file (yes I was clued in enough to know to check http://packages.ubuntu.com/ for dependencies first and download them). So once NDIS wrappers was installed, I ran it against the Windows drivers, then entered the wireless info and the rest is wireless network success.

I have heard good things about Ubuntu for awhile. Now that I have installed it, I am impressed with it as a easy to install laptop Linux. I plan to install Operations Research tools on Ubuntu laptop to expand my skills. Do you have any success stories with Ubuntu?