Thursday, 27 December 2007

Bibliography in LaTex: JabRef

Problem: bibliographical list of cites in LaTeX being grown and became on the thither side of fifty sources. Sorting and storing of bibliographical list in scientific papers is evident.
Solve: there is cross platform system for bibliography base - JabRef.

During creation of vast scientific works, problems with bibliography in LaTeX frequently arises. In the base level of LaTeX study, users applies direct links to literature in the TEX-file:

\addcontentsline{toc}{chapter}{References}
\begin{thebibliography}{99}

\bibitem{catheydowskinewparadigm} W.T. Cathey and E.R. Dowski, ``New paradigm for imaging systems'', Appl. Opt. 41, pp. 6080-6092, 2002.
This means literally "add section References at the end of table of contents, and enumerate links (bibitem) as they follows in bibliography list". And that is where shoe pinches for LaTeX-beginners - in the text links will have been enumerated as they are in list of references but not in the order of citing.

Besides that, where will be a big problems when you want to include part of bibliography items in another document. Which of them are useful, and in what order? To prevent such kind of problems, BiBTeX was invented.


Bibliography databases
This is a simple text file, where all you bibliography sources are listed. Such file can be used by LaTeX to produce bbl-file with only that literature sources, which were cited in document.
Every time you compiling you LaTeX document, BiBTeX searches citations in base and substitutes them into bbl-file. Obtained bbl-file is used as "thebibliography" list - but it created automatically.

Hence, you don't need to fight with bibliography in LaTeX - just add literature to you BiBTeX base using fancy GUI program. Created bibliography base can be used with many document, and benefits are:
  1. if there are any errors in literature item, it can be corrected in the BibTeX base only - and all documents, which are using this base, will be corrected automatically after next recompilation;
  2. links appears in desirable order and numbered automatically;
  3. you can search literature in base to find out bibtex key to substitute in \cite{};
  4. one BiBTeX base can be used in loads of documents;
  5. import \ export in different formats is possible.
Thus, you ought to make an effort to use BiBTeX - using you bib-base, it is possible to simply type \cite{source} and don't pay attention on which order cited literature appears in document. Simple and easy.


How it works
To start working with BiBTeX, it is necessary to install any program to work with BiBTeX, create new bib-base and full it with literature sources which you have. If you wrote early at the end of document:
\addcontentsline{toc}{chapter}{Reference}
\begin{thebibliography}{99}
hence, now you must point to bib-base like that (don't write .bib extension!):
\bibliography{path/to/bibliography/file}
e.g.,
\bibliography{biblio/my}
and, apart from other, choose bibliography style which you want to use - often unsorted list is used (i.e., in order of mentioning in text):
\bibliographystyle{unsrt}
This string must be pasted in header of LaTeX document, after \usepackage but before \begin{document}.

Here we exploiting possibilities of our OS, which alleviates our life: use symlinks. For example, we have two documents in different directories, but they using the same bib-base. How can it be used in either documents? Easily:just make symbolic link to directory with bib-base file and copy this symlink in desirable directories. This can be done in any UNIX systems.

So, if we have bibliography base file my.bib placed in ~/docs/matlab/docus/topics/biblio/ we need to point in LaTeX document to it \bibliography{biblio/my} and make symlink on directory:
ln -s ~/docs/matlab/docus/topics/biblio/ biblio
and copy symlink in desirable directories. That's all, you LaTeX documents will work with bib-base.


Installation
For described miracles to be working, installation of bibtex-viewer program is required. Let's use crossplatform software JabRef, Java-written and GPL-licensed.

Hence, we need to download from Internet  j2re*.deb (for example, jpre1.4_1.4.2.03-1_i386.deb), jabref*_all.deb (I have jabref_2.0.1-1_all.deb) and take first DVD-disk with Debian.

Firstly, installing  java-common :
#apt-get install java-common
Then installing Java-machine (correct file name if you have another version of Java):
#dpkg -i jpre1.4_1.4.2.03-1_i386.deb
Several questions may be asked during installation process, such as licence agreement. Then install JabRef - as separate package, if it isn't in distribution:
#dpkg -i jabref_2.0.1-1_all.deb
That's it: now add  JabRef to menu of you favourite window manager and run:
jabref
Don't forget to correct your LaTeX documents and point LaTeX to use BibTeX base:
\bibliography{path/to/bib-file/base}
and work as usual - citing literature and don't boring, BibTeX will do this job instead of us. At the end of document references will be typesetted by all rules.


A few advises
Fistly, don't forget to backup you bib-base. It can be exported in different formats or simply be copied in different disk

Second, many journals as SpringerLink or Elsavier brings Citations for published works. Don't miss them and collect this files - they are usually in RIS or BIB-formats. Download them and the import to JabRef base, give them bibkey names and you get proper citing of desirable article.

Read more...

Saturday, 15 December 2007

GPRS in Debian GNU/Linux with mobile phone Siemens ME45

Problem: connect to the Internet via mobile phone and GPRS using USB-adapter Prolific PL2303 under Linux.
Solve: there are enough tools in Debian to do so.


What we have
All above mentioned will have show in my notebook Asus M5200AE under Debian GNU/Linux and Siemens ME45, adapter and local Beeline cellphone provider.


Before starting
For work to be done, PPP in kernel is required:

Networking options->
TCP/IP networking ->
Network device ->
PPP (point-to-point protocol) support

monolith or as module. Besides it, in kernel support of phone link adapter must be activated:
USB support->
Support for USB ->
USB Serial Converter support->
USB Serial Converter support
[m] USB Generic Serial Driver
[m] USB Prolific 2303 Single Port Serial Driver
If this is done, plug phone link USB adapter into USB and look at logs:
usb 3-1: new full speed USB device using uhci_hcd and address 3
drivers/usb/serial/usb-serial.c: USB Serial support registered for pl2303
pl2303 3-1:1.0: pl2303 converter detected
usb 3-1: pl2303 converter now attached to ttyUSB0
usbcore: registered new driver pl2303
drivers/usb/serial/pl2303.c: Prolific PL2303 USB to serial adaptor driver

That's all, adapter is found and recognized by kernel, new port /dev/ttyUSB0 which will be pointed to dial program.


Tune GPRS

Only thing to do is to point to dialer right parameters, and one can use GPRS without problems. Gaining root privileges and go to /etc/ppp/peers/ to create file beeline with following contents:
/dev/ttyUSB0
57600
noauth
defaultroute
usepeerdns
persist
noipdefault
lock
connect '/usr/sbin/chat -v -f /etc/chatscripts/beeline-connect'
novjccomp
nopcomp
noaccomp
noipdefault
nodeflate
novj
Don't set too big speed of connection, it can be cause of connection breakage. One more file, beeline-connect, one ought to make in directory /etc/chatscripts/ and write in it:
TIMEOUT 45
ABORT 'NO ANSWER'
ABORT 'BUSY'
ABORT 'NO CARRIER'
SAY 'Starting GPRS connection\n'
ABORT ERROR
"" 'ATZ'
"" 'ATE1'
OK AT+CGDCONT=1,"IP","internet.beeline.ru"
OK ATD*99***1#
CONNECT c
If you use different operator, change the line AT+CGDCONT=1,"IP","internet.beeline.ru" to that which is written on a website of you cellphone provider.


Connecting to the Internet via GPRS
All necessary tweaks are done and now one can use GPRS in Linux - let's enter the command from root:
pppd call beeline
or
pon beeline
A few seconds of waiting and it is possible to work as usual:



To disconnect from the internet, type:
killall pppd
or
poff beeline
That's all.


If something goes wrong...
Not everything can be done from first trying, and if GRPS doesn't work properly, you must look up in logs, and concretely - /var/log/syslog. This file in being red only root, so gaining root privileges and reading logs:

Aug 14 08:30:37 localhost chat[7715]: timeout set to 45 seconds
Aug 14 08:30:37 localhost chat[7715]: abort on (NO ANSWER)
Aug 14 08:30:37 localhost chat[7715]: abort on (BUSY)
Aug 14 08:30:37 localhost chat[7715]: abort on (NO CARRIER)
Aug 14 08:30:37 localhost chat[7715]: abort on (ERROR)
Aug 14 08:30:37 localhost chat[7715]: send (ATZ^M)
Aug 14 08:30:37 localhost chat[7715]: send (ATE1^M)
Aug 14 08:30:37 localhost chat[7715]: expect (OK)
Aug 14 08:30:37 localhost chat[7715]: g^?ATZ^MAT^M
Aug 14 08:30:37 localhost chat[7715]: OK
Aug 14 08:30:37 localhost chat[7715]: -- got it
Aug 14 08:30:37 localhost chat[7715]: send (AT+CGDCONT=1,"IP","internet.beeline.ru"^M)
Aug 14 08:30:38 localhost chat[7715]: expect (OK)
Aug 14 08:30:38 localhost chat[7715]: ^M
Aug 14 08:30:38 localhost chat[7715]: EAT+CGDCONT=1,"IP","internet.beeline.ru"^M^M
Aug 14 08:30:38 localhost chat[7715]: OK
Aug 14 08:30:38 localhost chat[7715]: -- got it
Aug 14 08:30:38 localhost chat[7715]: send (ATD*99***1#^M)
Aug 14 08:30:38 localhost chat[7715]: expect (CONNECT)
Aug 14 08:30:38 localhost chat[7715]: ^M
Aug 14 08:30:38 localhost chat[7715]: ATD*99***1#^M^M
Aug 14 08:30:38 localhost chat[7715]: CONNECT
Aug 14 08:30:38 localhost chat[7715]: -- got it
Aug 14 08:30:38 localhost chat[7715]: send (c^M)
Aug 14 08:30:38 localhost pppd[7314]: Serial connection established.
Aug 14 08:30:38 localhost pppd[7314]: Using interface ppp0
Aug 14 08:30:38 localhost pppd[7314]: Connect: ppp0 <--> /dev/ttyUSB0
Aug 14 08:30:41 localhost pppd[7314]: PAP authentication succeeded
Aug 14 08:30:44 localhost pppd[7314]: Cannot determine ethernet address for proxy ARP
Aug 14 08:30:44 localhost pppd[7314]: local IP address 10.0.103.11
Aug 14 08:30:44 localhost pppd[7314]: remote IP address 192.168.254.254
Aug 14 08:30:44 localhost pppd[7314]: primary DNS address 217.118.66.243
Aug 14 08:30:44 localhost pppd[7314]: secondary DNS address 217.118.66.244

After that strings I gained network interface ppp0

notebeast:/home/beast# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:84 errors:0 dropped:0 overruns:0 frame:0
TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5483 (5.3 KiB) TX bytes:5483 (5.3 KiB)

ppp0 Link encap:Point-to-Point Protocol
inet addr:10.1.193.83 P-t-P:192.168.254.254 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:204 errors:0 dropped:0 overruns:0 frame:0
TX packets:273 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:109516 (106.9 KiB) TX bytes:27628 (26.9 KiB)

through which Internet is being shed like a broad river.
Read more...

Wednesday, 12 December 2007

Long-time remote shooting with Canon EOS 400D

Problem: Shooting with exposure times 30 and more is required and this process must be automated.
Solve: using soldering iron, common chips and bash script in Linux, it is possible to make PC-driven remote control device.


What we have
We have Canon EOS 400D, Debian-powered notebook and necessity of shooting pictures with exposure longer than 30 seconds. There is good scheme proposed by Michael A. Covington here. Anyway, mirroring it here:


Pretty good scheme, but it doesn't work for Canon EOS 400D - shutter will lift up bot not down.

Scheme for Canon EOS 400D
After some fruitless trying, I am with my colleague Alexey Ropyanoi, found out why proposed scheme not work and propose new one:


And it works! Our laboratory Canon EOS 400D begin open and close shutter by computer command.

Necessary electric components
To do the same remote shooting wire, you need 4-wire cable (from audio devices or from telephone cable), 2.5mm jack (or 3/32 inch jack), mentioned in scheme chips, 9-pin COM-port and USB-COM adapter (for using this remote shooting wire on novel computers).

The best USB-COM adapter is on Profilic 2303 chip - it is the most common chip and it works in Linux, like practically all, "out of the box".


Software
For remote control of camera, little program on C is needed. It is setSerialSignal and it source code is placed here. It can be compiled with GCC, which is part of any UNIX-like OS distribution.

gcc -o setSerialSignal setSerialSignal.c
Works on Debian GNU/Linux v4.0 r.0 "Etch", gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21).

This is the code:

/*
* setSerialSignal v0.1 9/13/01
* www.embeddedlinuxinterfacing.com
*
*
* The original location of this source is
* http://www.embeddedlinuxinterfacing.com/chapters/06/setSerialSignal.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* setSerialSignal
* setSerialSignal sets the DTR and RTS serial port control signals.
* This program queries the serial port status then sets or clears
* the DTR or RTS bits based on user supplied command line setting.
*
* setSerialSignal clears the HUPCL bit. With the HUPCL bit set,
* when you close the serial port, the Linux serial port driver
* will drop DTR (assertion level 1, negative RS-232 voltage). By
* clearing the HUPCL bit, the serial port driver leaves the
* assertion level of DTR alone when the port is closed.
*/

/*
gcc -o setSerialSignal setSerialSignal.c
*/


#include
#include
#include

/* we need a termios structure to clear the HUPCL bit */
struct termios tio;

int main(int argc, char *argv[])
{
int fd;
int status;

if (argc != 4)
{
printf("Usage: setSerialSignal port DTR RTS\n");
printf("Usage: setSerialSignal /dev/ttyS0|/dev/ttyS1 0|1 0|1\n");
exit( 1 );
}

if ((fd = open(argv[1],O_RDWR)) < 0)
{
printf("Couldn't open %s\n",argv[1]);
exit(1);
}
tcgetattr(fd, &tio); /* get the termio information */
tio.c_cflag &= ~HUPCL; /* clear the HUPCL bit */
tcsetattr(fd, TCSANOW, &tio); /* set the termio information */

ioctl(fd, TIOCMGET, &status); /* get the serial port status */

if ( argv[2][0] == '1' ) /* set the DTR line */
status &= ~TIOCM_DTR;
else
status |= TIOCM_DTR;

if ( argv[3][0] == '1' ) /* set the RTS line */
status &= ~TIOCM_RTS;
else
status |= TIOCM_RTS;

ioctl(fd, TIOCMSET, &status); /* set the serial port status */

close(fd); /* close the device file */
}



Sending signals
Compiling program and making it executable, and below listed signals which will open and close shutter:

DTR
setSerialSignal /dev/ttyS0 1 0



Clear DTR
setSerialSignal /dev/ttyS0 0 0


RTS
setSerialSignal /dev/ttyS0 0 1


Clear RTS
setSerialSignal /dev/ttyS0 1 1


Shutter opens at DTR and closes at RTS.


Shell script for remote shooting
Next, it is comfortable to use bash script by Eugeni Romas aka BrainBug, but for Canon 400D script was edited and here it is:

#!/bin/bash

for i in `seq $3`; do
{
setSerialSignal /dev/ttyUSB0 0 0 &&
sleep $1 && setSerialSignal /dev/ttyUSB0 0 1 &&
sleep 0.3 && setSerialSignal /dev/ttyUSB0 0 0 &&
sleep $2 && setSerialSignal /dev/ttyUSB0 1 1 && echo "One more image captured!" &&
sleep $4;

}
done

echo "Done!"

Script parameters:
1: shutter opening delay
2: exposure time in seconds
3: amount of shots
4: delay between shots

Example:
make_captures 4 60 30 2

Script is written to work with USB-COM adaptor, and you need to edit it if you have different port.

How it works
Remote shooting wire is ready, inserting USB-COM adapter with wire and next:
  • Turn on camera, setting BULB mode, setting aperture size and ISO speed.
  • Inserting jack into the camera, another and in COM-USB adapter and then in USB-port.
  • Looking at logs: kernel must recognize chip and write something like this:
usb 2-1: new full speed USB device using uhci_hcd and address 2
usb 2-1: configuration #1 chosen from 1 choice
drivers/usb/serial/usb-serial.c: USB Serial support registered for pl2303
pl2303 2-1:1.0: pl2303 converter detected
usb 2-1: pl2303 converter now attached to ttyUSB0
usbcore: registered new interface driver pl2303
drivers/usb/serial/pl2303.c: Prolific PL2303 USB to serial adaptor driver
  • Now shoot:
    make_capture 1 5 2 3
Here we make 2 images with 5 second exposure, delay between shots is 3 seconds, delay for shutter lifting 1 second.

Acknowledgements
I would like to express my gratitude to:
  • Michael A. Covington for his original article "Building a Cable Release and Serial-Port Cable for the Canon EOS 300D Digital Rebel".
  • Eugeni Romas aka BrainBug for link to original post and discussion.
  • Anton aka NTRNO for searching key posts at Astrophorum.
  • Alexey Ropjanoi, who experimentally found out problem and eliminated it, proposing new shceme for shooting.
And I deeply thankful to my colleagues for Solid State physic department of Moscow Engineer Physics Institute.

Read more...

Friday, 7 December 2007

How to change MAC-address of Ethernet card

Sometimes changing MAC-address of a network card is needed. For example, when it used for authorisation by internet provider. This is relatively simple yet unobvious in a first time procedure, but here are some examples.



Temporary MAC-address change
Go to the terminal and type:
sudo ifconfig eth0 hw ether xx:xx:Xx:xx
and MAC-address change and will stay until reboot. If you wish to change
MAC-address permanently, you need to do this:


Permanent change of
MAC-address
In Debian, for example, go to  /etc/network/if-pre-up.d/ and create file from root named pre-up.
Let`s write to them strings like this:
#! /bin/sh
ifconfig eth0 hw ether 00:00:00:00
Change zeroes by needed
MAC-address. To make changes active immediately, restart of network subsystem is required:
/etc/init.d/networking restart
In first time, following diagnostic messages are expected to appear:
# /etc/init.d/networking restart
Setting up IP spoofing protection: rp_filter.
Reconfiguring network interfaces...SIOCDELRT: No such process
ifup: interface lo already configured
SIOCSIFHWADDR: Device or resource busy
run-parts: /etc/network/if-pre-up.d/pre-up exited with return code 1
done.
No problems, repeat command, and it will execute smoother:
notebeast:/home/beast# /etc/init.d/networking restart
Setting up IP spoofing protection: rp_filter.
Reconfiguring network interfaces...ifup: interface lo already configured
done.
Here we go, the MAC-address is changed permanently.


How to find out MAC-address of network card in Linux
It's very simple, just type:
sudo ifconfig
and you see something like this:
eth0 Link encap:Ethernet HWaddr 00:0A:E4:53:AA:2D
inet addr:10.26.49.77 Bcast:10.26.63.255 Mask:255.255.240.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:208554 errors:0 dropped:0 overruns:0 frame:0
TX packets:125071 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40664531 (38.7 MiB) TX bytes:45919980 (43.7 MiB)
Interrupt:21 Base address:0x4c00

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:18511 errors:0 dropped:0 overruns:0 frame:0
TX packets:18511 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:537155 (524.5 KiB) TX bytes:537155 (524.5 KiB)

One's MAC-address is emphased by red font colour.


Yet another tips to change MAC-address

For example, MAC-address in Gentoo can be changed in /etc/conf.d/net


mac_eth0="00:50:8D:63:41:DE"
config_eth0=( "192.168.100.37 netmask 255.255.252.0" )
routes_eth0=(
"default via 192.168.100.1"
)

Or edit /etc/network/interfaces adding one string:
pre-up ifconfig eth0 hw ether 00:00:00:00:00:00
Indeed, there are loads of variants, because it is Linux :-)

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
hwaddress ether xxxxxxxxxxxx


Conclusion
This post can be useful to those who connected to Internet via provider authorising by MAC-address.

Read more...

Thursday, 6 December 2007

Yet another Linux to Windows printing tip

Problem: one have a printer shared for networks printing and connected to a windows machine. From the other side, there is Linux-powered machine with CUPS installed and we want to print on windows shared printer.
Solve: with CUPS webform, adding printer and specifying login guest for printing without a password in a windowish printer.

Let's consider a common situation: we have winXP computer with network address 192.168.1.1, it has network shared printer LaserJet 1200 visible by SAMBA with name HPLaserJ. From another windows machines all printed without problems, but from Linux machine with CUPS when you attempt to print something you getting error.

Connection failed with error NT_STATUS_ACCESS_DENIED

If you attempt to print on it via IPP, you get:
Unable to connect to SAMBA host, will retry in 60 seconds...foomatic-rip version $Revision$ running...

There is no password on shared printer in windows - it is empty.

Solve of this puzzle is ridiculously simple. Just add in CUPS webform new printer, choose "Windows printer via Samba", and in address field write:
smb://guest@192.168.1.1/HPLaserJ

And that's all! Printing without a problems!

It's incredible that in huge and pretty goofy CUPS documentation this useful example is missing.

In KDE applications you ought to choose local printing address 127.0.0.1:631.

Read more...