Tuesday, January 26, 2010

Eclipse CDT incompatibility with Cygwin 1.7

Eclipse failed to detect the Cygwin GCC toolchain. Attempts to manually set the toolchain in project properties led to an error being displayed below the choice: "The configuration support is not installed on the system". This is because Eclipse gets Cygwin paths from the registry, and Cygwin 1.7 stopped storing them there. To fix the problem, I added the paths to the registry using a .reg file:

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2]
"cygdrive prefix"="/cygdrive"
"cygdrive flags"=dword:00000022

[HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/]
"native"="C:\\cygwin"
"flags"=dword:0000000a

[HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/bin]
"native"="C:\\cygwin\\bin"
"flags"=dword:0000000a

[HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/lib]
"native"="C:\\cygwin\\lib"
"flags"=dword:0000000a

Customize the "native" values to point to your cygwin directory.

Thursday, January 21, 2010

Compiling HPLIP in Windows using Cygwin

Windows drivers for the HP Color LaserJet 2840 All-in-One Printer are a bloated piece of garbage. Scanning over the network doesn't work, and downloadable drivers only offer printing support for 64-bit versions of Windows. The potentially decent Windows driver alternatives may be to only use the all-in-one for printing or connect the printer via USB to a computer running Windows 7.

Via HPLIP (HP Linux Imaging and Printing), Hewlett-Packard provides Linux drivers for many HP printers and all-in-one devices. The 2840 is fully supported. These drivers consist of applications and dynamically linked libraries which can work in Cygwin in Windows The process of compiling them is not straightforward, but it's certainly not impossible. Here I will concisely describe how to compile a lite version of HPLIP with scanning and printing support.

First, note the dependencies that are listed in the manual installation page. Some of these, (such as gcc, libjpeg and libcrypto) are standard Cygwin packages. They can simply be installed via the setup program. That is the easy part. The next step is compiling the dependencies. The following instructions list the important points (such as problems and workarounds) and omit the obvious things (such as running make and "make install"). They place everything under /opt/hplip, to keep things tidy and somewhat portable.

Net-SNMP 5.5

HPLIP seems to only require a stripped-down version of Net-SNMP; basically only the library is needed. Compiling only the needed parts simplifies things and avoids some issues:

./configure --prefix=/opt/hplip --disable-agent --disable-applications --with-perl-modules=no --disable-embedded-perl

The entire agent subdirectory is not needed; remove it from SUBDIRS in the generated top level Makefile.

Windows DLLs can't have undefined symbols, and because of this libtool normally requires a -no-undefined switch to build shared libraries in Windows. In in the Cygwin section of func_mode_link () in libtool uncomment the allow_undefined=no line and comment out the yes line. Note comments explaining the issue.

CUPS (1.4.2)

Even the network scanner driver depends on CUPS. Fortunately, CUPS is easy to compile. The only problem is that the rules for generating shared libraries are for Unix only. One could add Cygwin-specific rules or set up the project for Automake and Libtool, but it's far simpler to just disable shared libraries:

LIBS=-lz ./configure --prefix=/opt/hplip --disable-shared --with-cups-group=None

After CUPS is installed, create an administration password with "lppasswd -g admin -a root" and change AuthType to BasicDigest in /opt/hplip/etc/cups/cupsd.conf. The administration interface is at http://localhost:631/ and https://localhost:631/. Note that you don't need to let cupsd through your Windows firewall to access the administration interface on localhost.

SANE (sane-backends-1.0.20)

This is easiest to build. I simply configured it using:

./configure --prefix=/opt/hplip --with-group=None --disable-ipv6

When attempting to run "saned -d" before, I got "invalid fd in set, attempting to re-bind" errors. I think disabling IPv6 fixed that. In any case, I don't need IPv6.

While building tools/sane-desc, I got missing include file errors the first time. Surprisingly, retrying fixed that error.

HPLIP (3.9.12)

If you get a .run file, you can get a .tar.gz by starting with the 0x1F byte after the shell script. The contents of the resulting tar.gz are not all in one directory, like with most software. That means you need to create a new directory, change to it and extract there. You can also download a .tar.gz from HP. At this point you definitely need the dependencies, so add /opt/hplip/bin to the path and use CPPFLAGS and LDFLAGS:

CPPFLAGS=-I/opt/hplip/include LDFLAGS=-L/opt/hplip/lib LIBS="-lssl -lz" ./configure --prefix=/opt/hplip --enable-hpijs-only-build=no --enable-hpijs-install=no --enable-gui-build=no --enable-dbus-build=no --enable-cups-drv-install=yes --with-cupsbackenddir=/opt/hplip/lib/cups/backend --with-cupsfilterdir=/opt/hplip/lib/cups/filter --enable-qt4=no --enable-lite-build

After this, the generated libtool again needs to be fixed. Under the "libtool link mode" comment, uncomment "allow_undefined=no" and comment out "allow_undefined=yes". In prnt/hpcups/ErnieFilter.cpp, ensure that math.h is included; remove the conditional around the include.

After "make install" copy data/models/models.dat to /opt/hplip/share/hplip/data/models/models.dat, or maybe move the whole data directory. Also, move /opt/hplip/lib/bin/cygsane-hpaio-1.dll to /opt/hplip/lib/sane/. Then, add a hpaio line to /opt/hplip/etc/sane.d/dll.conf. You can comment out all the other lines in that dll.conf and remove /etc/sane.d and the dll.conf file found there. The only file that remains outside of /opt/hplip is /etc/hp/hplip.conf. That path is hard-coded into several hplip files.

Finally, it's time to configure CUPS. You can create a URI for your printer by probing it with hp-mkuri. For example "hp-mkuri -i 1.2.3.4" would give you something like hp:/net/HP_Color_LaserJet_2840?ip=1.2.3.4 if successful. When adding a printer, choose HPLIP and enter that URI. You can find your PPD file in /opt/hplip/share/ppd/HP/ and with the 2840, CUPS can retrieve settings from the printer (it just takes a while). At that point, you can print a test page.

At this point, scanning should work. Scanning from the command line via scanimage does not need saned running because it uses the backend directly. The output goes to standard output, so be sure to redirect it. Scanning from a GUI is possible via xsane-win32 and there even TWAIN frontends for SANE. Note that although saned is designed to run under inetd, it can be run temporarily via "/opt/hplib/sbin/saned -d".

The HPLIP GUI is not available and faxing isn't supported. The LyX instructions for compiling Qt in Cygwin seem promising, but I may not work on that anytime soon because I don't need the fax features and I expect the GUI would be bloated.

Thursday, December 31, 2009

PH61153 video selector switch disassembly

Disassembly Instructions
  1. Remove the silver front. It is only held by clips. Push inwards on the black part near the silver while pulling the silver part away. Start where it's easiest and go from there. You can put folded up paper in the gap to keep it open. The front will remain attached by cables.
  2. Separate the black parts of the case. Once the front is off, these clips are obvious.
  3. Unplug the cables going to the front from the main circuit board.
  4. Unscrew the small circuit board for the front input, and unplug its cable from the main board.
  5. Unscrew the screws holding the main board and the screws holding RCA connectors to the back. Remove the main board

Photos

The top of the main board shows the through-hole components and the back of the RCA jack circuit board. The socketed chip is a EM78P156EL microcontroller.



The bottom shows the surface mount components. The chips are 4000-series CMOS. The three along the bottom are 4052L. Each contains two four-channel analog multiplexers. The chip above them is an HEF4053B. It contains three two-channel analog multiplexers.



Here is the rest of the device. Note how except for the RF modulator, there's no shielding. Even the video signal from the front panel connects via ordinary wires. Nevertheless, the switch does not seem to degrade video quality.


The Story

I just got a PH61153 video selector switch. It has four inputs, supports composite and S-video and stereo audio and has an RF modulator. The best part is that it can automatically switch to the highest priority input which has a video signal, and so I can basically hide it and forget about it.

I got it from XSCargo. They were the only local store that had it in stock, and they certainly had what seemed like a good price ($19.95). Unfortunately, the low price only reflected the low quality. First I noticed that that Philips wasn't mentioned anywhere. Then I noticed that most of the them were badly scratched and scuffed, and one had something rattling around inside. Finally, when I bought one and brought it home, I found that one of the inputs didn't work. The switch never auto-switched to the first input, and if I manually switched to it I got no composite video or audio.

I didn't like the idea of going back to XSCargo. It was a long drive, and the replacement could again have some issue. At this point, I didn't want to open up the switch and so I first measured resistance at the inputs. Unlike the other inputs, the broken input had an open circuit on all three RCA jacks. Based on this, I concluded that the problem was probably a bad connection, and not a burned out part. So, I decided to open up the device.

The problem turned out to be a crack on the back circuit board. The RCA connectors on the back are all mounted the back circuit board, and the S-video connectors are mounted on the main board. The back circuit board has large square holes for the S-video connectors. As a result, it is only connected to the main board via four fingers. One of these fingers had cracked. That's not surprising when you consider how some RCA connectors can be very tight and hard to fully seat or unplug. It was an easy fix.

Saturday, December 26, 2009

Old Avant Browser user agent causes sites to redirect to mobile versions in IE

Avant Browser (an Internet Explorer shell) can come back to haunt you. When uninstalling, it leaves behind its addition to the Internet Explorer User-agent (in this case "Avant Browser [avantbrowser.com]"). That addition causes some sites to redirect to the mobile versions in Internet Explorer 8. In some cases, it is impossible to view the normal version of the websites because even deep links redirect to the mobile homepage. To fix the problem, remove the User-agent addition. You can search for "Avant" in regedit.

Thursday, December 24, 2009

Cygwin 1.7 upgrade breaks Perl due to missing libssp0 dependency

After upgrading Cygwin to version 1.7, Perl failed with the following error message:

/usr/bin/perl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

Then I ran "cygcheck /usr/bin/perl" and saw a bunch of these errors:

cygcheck: track_down: could not find cygssp-0.dll

I then installed libssp0 (current version 4.3.4-3), and Perl worked properly.

Wednesday, December 23, 2009

I saw the Torch today

I used to think that the Olympics are a part of human cultural heritage and that they're meant to be an expression of certain ideals. Starting with the 2008 Beijing Olympics I learned more about the business aspects of the Olympics. What I learned looked bad. I saw that the Olympics were being run like a corporation. Ideals, individuals or even athletes seemed to be less important than sponsors and branding. Basically, free speech and other freedoms are restricted to please the sponsors and control what people see. This is not acceptable, and it's especially disappointing to see this happening in Canada.

At first, I was planning to not see the Torch this year. What changed my mind was the thought that very many things are seriously messed up, and that I should focus more on recognizing the good parts and less on rejecting things because of bad parts.

At first I contemplated seeing the Torch at Point Pelee National Park, but I scheduled something else and I couldn't make it to Pt. Pelee on time. So I ended up seeing the 2008 Vancouver Torch in Kingsville, Ontario, and that turned out quite well. Plenty of people lined the streets in Kingsville, but it wasn't too crowded and everyone could get a close view of the Torch. Before and afterwards, the entertainment was children singing Christmas songs, which was quite nice.

This was the third Olympic Torch Relay I saw. The other two were the 1984 Sarajevo and 1988 Calgary Relays. It's interesting how they keep getting bigger. In late 1983, there was just the torchbearer and one or two cars, the 1988 Relay involved more vehicles, and finally in 2010 there was a whole mini-parade of vehicles for officials, sponsor displays and security. Maybe that's another illustration of how the Olympics have strayed from what is really important, or maybe not. I can't really complain about what I saw today.

Sunday, December 20, 2009

Enabling UAC Virtualization so old plugins can save settings

Originally, Windows had no filesystem security, and applications could write data wherever they wanted. Because of that old software often stores settings in the Windows directory or the application directory. For example, old Winamp plugins store their settings into the plugin directory (typically C:\Program Files\Winamp\Plugins). Starting with Vista, writing to those directories requires administrative privileges. To allow old software to function correctly, Windows can redirect such accesses to a place within the user's profile folder (%userprofile%\AppData\Local\VirtualStore). The same issues can exist with registry writes, and Windows can also redirect those. When an application is specifically designed for Vista or Windows 7, this redirection (called UAC Virtualization) is not needed and so it is disabled.

This normally works so well that one doesn't need to know about it. However, it fails when an application designed for Vista or Windows 7 loads old plugins. For example, some old Winamp plugins cannot save settings. Here are some solutions:
  • Grant write access to the directory.
  • Delete the manifest resource from the executable using a registry editor. However, some executables such as winamp.exe require the manifest resource.
  • Edit the manifest resource in the executable and remove the trustInfo section from the manifest. This means removing text from "<trustinfo" to "</trustinfo>". It's best to use a resource editor, but you can overwrite the text with spaces in a hex editor.
Task Manager can tell you if UAC Virtualization is enabled: right click on the executable and look for the check mark by "UAC Virtualization". This method can be used to change the setting, but I do not recommend it because it would have to be repeated every time the application is run.

Thursday, December 17, 2009

Changing Windows Live Messenger status via Windows messages from HoeKey

I use HoeKey for hotkeys. I love how it's tiny and unobtrusive. It's only using 128K of RAM now. I change instant messaging status via HoeKey so statuses in multiple applications stay synchronized. Here are the lines I use for Windows Live (formerly MSN) Messenger:

=Msg|MSBLWindowClass|273|40166 ; WLM Available
=Msg|MSBLWindowClass|273|40169 ; WLM Away
=Msg|MSBLWindowClass|273|40168 ; WLM Busy
=Msg|MSBLWindowClass|273|40210 ; WLM Sign out


To use those lines, either put a hotkey identifier before the equals sign or append them to other hotkeys. MSBLWindowClass is the window class of the Windows Live Messenger window. 273 means the message is WM_COMMAND. The 5 digit numbers correspond to wParam of the message and identifiers of entries on the File menu. Text after the semicolon is an explanatory comment.

Disclaimer: I don't like Windows Live Messenger. I just use it because it fully supports all the features of the protocol.