The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Category: PC Tweakage

Remembering which tweaks worked

  • Oscilloscope Screen Shots

    A long time ago I got an HP54602B oscilloscope with a serial port data link. HP provided a sample app that snarfed screenshots & data from the scope, but it wasn’t really ready for prime time and, besides, I vastly preferred to use OS/2 (!) and then Linux rather than Windows.

    Here’s my Kermit script to fetch screenshots. All the software comes more-or-less standard in Ubuntu Linux and (I presume) in most others. If you’re running Windows, you’re on your own.

    Scope Setup

    HP54602B Serial Setup Screenshot
    HP54602B Serial Setup Screenshot

    The oscilloscope’s HP Plotter setting spits out bog-standard HPGL commands in flat ASCII. I’ve always meant to investigate what HP Printer does, but …

    I wish the scope ran faster than 19200 b/s, but that speed works reliably over generic USB-to-serial converters (and the scope can’t feed data that fast, anyway). The other choice, back in the day, was HPIB / GPIB; I’d have had to buy three or four different adapters to suit all the PC data buses since then: ISA, EISA, VLB, PCI …

    Xon/Xoff flow control (a.k.a. handshaking) works better than hardware flow control, simply because the cable’s easier to build.

    The Factors setting adds a bunch of text to the end of the data stream that’s not useful, except for the fact that an HPGL LB instruction follows all of the useful data and gives the Kermit script something to look for. Otherwise, the only way to detect the end of the stream is to time out after a looong time.

    I haven’t the foggiest idea what Resolution does, but High seems appropriate.

    Hardware Notes

    The scope requires a Null Modem in front of a standard DB-25 to DB-9 cable. I’ve been meaning to rewire my standard cable to eliminate the Null Modem, but …

    Adding an LED breakout / monitoring adapter to the serial port loads the signals too much and can lead to puzzling errors. Maybe it’s just my adapter: YMMV.

    I’ve run the cable all the way across my basement lab with no problem. This is, after all, good old RS-232, not some high-falutin’ USB or Firewire interconnect.

    Taking the Shot

    Get a picture you like, poke the Print Screen button, then quick like a bunny run the script. The scope copies the current screen into an internal buffer, then sends out a torrent of HPGL commands. The script will capture the data and eventually spit out a PNG file.

    You may want to Stop the trace, rather than leave it running.

    In XY mode, the scope seems to have trouble copying the entire trace. I tap Auto Store twice, then Stop, then Print Screen. It’s fuzzier, but copies the whole thing.

    What Happens

    The script captures the incoming serial data into a log file, processes that text through the hp2xx program to get an Encapsulated Postscript EPS file, then runs that though convert to get a PNG file. The bank shot off EPS results in better-looking output, for reasons I don’t understand.

    The 240-second timeout value for the Input command seems long, but it takes a lot of plotter commands to define a four-trace plot. A too-short timeout chops off the tail end of the HPGL stream and prompts bizarre error messages from hp2xx.

    The parameters for hp2xx and convert came from protracted and tedious twiddling. The ‘scope image is 512 dots across and 300-some-ish vertically; the output mimics the not-quite-square graticule aspect ratio on the actual screen. If HP thinks it looks good, then it looks good to me.

    The active (bright) traces use Pen 2, which I’ve set to Blue (color 4). The graticule, annotations, and stored traces all use Pen 1, which appears as Black (color 1). Tweak -c 14 as you wish.

    The pen widths (set by -p 34) don’t actually seem to do very much, although I vaguely recall that using the default width of 1 makes the output entirely too faint.

    The PNG has a transparent background that turns white when you actually use it in a document; I suppose you could overlay it atop a background image if you wanted to get cute.

    When the dust settles and the smoke clears, you get PNG images like this. It’s an XY plot, so the blue section appears as a bright trace on the oscilloscope’s screen.

    BH curve for LC0263-A coil
    BH curve for LC0263-A coil

    Kermit Script

    #!/usr/bin/kermit +
    # Fetches screen shot from HP54602B oscilloscope
    # Presumes it's set up for plotter output...
    # Converts HPGL to PNG image

    set modem none
    set line /dev/ttyS0
    set speed 19200
    set flow xon/xoff
    set carrier-watch off

    # Make sure we have a param
    if not defined %1 ask %1 {File name? }

    set input echo off
    set input buffer-length 150000

    # Wait for PRINT button to send the plot
    echo Set HP54602B for HP Plotter, FACTORS ON, 19200, XON/XOFF
    echo Press PRINT SCREEN button on HP54602B…

    log session “%1.hgl”

    # Wait for end of data stream
    input 240 lb

    echo … got final lb command

    close session
    close

    echo Converting HPGL in
    echo — %1.hgl
    echo to PNG in
    echo — %1.png

    # without labels = no terminating lb info
    #run hp2xx -m png -a 1.762 -h 91 -c 14 “%1.hgl”
    #run mogrify -density 300 -resize 200% “%1.png”

    # with labels = terminating lb
    run hp2xx -q -m eps -r 270 -a 0.447 -d 300 -w 130 -c 14 -p 34 “%1.hgl”
    run convert -density 300 -resize 675×452+2+2 “%1.eps” “%1.png”

    echo Finished!

    exit 0

  • CD Longevity, Lack Thereof

    Remember when they said CDs would last for a hundred years?

    Some years back, a bit o’ PC shuffling around here spat out a 60 GB hard drive and brought the Big Box of CDs up from the fireproof safe at the same time. A little mental math: hey, why not?

    Turns out that all 130+ of my “purchased” CDs, mostly with Windows programs & device drivers, add up to 42 GB of ISO images. Creating ISOs is trivial with Linux:

    dd if=/dev/cdrecorder of=image.iso

    and you’re done. Depending on your system, you’ll get faster transfer with a bigger blocksize: bs=1M is more than enough.

    I used the two upstairs PCs as readers, with the hard drive installed in the milling-machine PC downstairs. It took the better part of a day to think up file names and feed CDs into the slots. Typical speeds were 3 MB/s, dropping dramatically with read retries: a minute or two or three per CD. The average CD is half-full.

    I wrote a trivial script to do the tedious work: loaded the CD, issued the dd command, computed MD5 checksums on the raw CD data and the stored file, and ejected the CD. The checksums always matched except when the disc had read errors, but gave me confidence I wasn’t losing any bits along the way, because the CD got read twice and any marginal sectors that were fixed-in-error would pop out.

    One CD was completely unreadable because of a nasty scratch. Another, never used, turned out to be cracked in the sealed envelope.

    What’s scary is the number of previously good, visibly undamaged, used-once-or-twice CDs that couldn’t be read in at least one drive. I don’t abuse the things and I -know- some of these haven’t seen the light of day more than once or twice.

    Dozens (I lost count) weren’t readable in at least one drive and many weren’t readable in three drives. If you happened to have two of those drives in your one-and-only PC you’d be sunk without a trace.

    I had a visibly undamaged CD that couldn’t be read in any of the four drives, although rubbing it down with toothpaste (got nothing to lose!) persuaded it to play in the CD burner. Perhaps a minute scratch? Dunno, but if that CD was damaged, then you can’t even look at ’em without damaging the things.

    The most reliable drive was a CD-only burner. The DVD-ROM and DVD-burner drives could read most discs, but fell flat on others. There’s no obvious difference between a DVD+(only) burner and the DVD+/- burners.

    Bottom line: maybe a quarter of those spendy pressed commercial CDs on your shelf won’t work when you really need to reinstall those programs. Should you happen to do an installation that doesn’t read the part of the CD with rotten bits, then you’ll never notice. I was copying the entire bit stream off the disc, so every single sector had to pass muster. How lucky do you feel?

    If you think you’ll ever need ’em again, get ’em on a hard drive now. Then you can burn ’em as needed. Oh, yeah, put the serial number right in the file name, too, it’ll come in handy.

    Hundred years, ptui!

    Back then I didn’t know about GNU ddrescue. Now, I do. Life is good. Well, better.

    Update: Nowadays, I keep everything on a 500 GB drive in the file server, which does a daily backup to a 500 GB external drive. Once a month, more or less, I dump the contents of the daily backup drive to a similar drive that lives in the fireproof safe.

    Tip: mounting an ISO is easier than finding & mounting the CD. They’re served up over an NFS share mounted locally at /mnt/diskimages, so it goes a little something like this:

    mount -o loop,ro /mnt/diskimages/ISOs/name-of-CD.iso /mnt/loop/

    and away you go. The ro option keeps you from screwing things up with an inadvertent write.

    That doesn’t work in Windows, more’s the pity, but you can find GUI utilities that more-or-less do the same thing from a SAMBA share. Not that I care all that much.

  • Windows Partitioning: MediaDirect vs Everyone Else

    This is probably more than you really want to know, but it might come in handy at some point…

    Prior to refurbishing a friend’s dog-slow XP laptop, I did some exploratory surgery on mine just to make sure I understand the parameters. I’ve long since repartitioned my laptop’s drive and done horrible things to it, so it’s an ideal testbed. Before doing that, of course, I backed up all the partitions & MBR, Just Because.

    So, to begin…

    Partitions

    Dell laptops have (at least) three partitions in addition to the one that holds XP.

    1. Dell Utilities, accessed by Ctrl-F12 during boot, then selecting the “Diagnostics” boot. The same utilities are also on the Utilities CD and you can fetch an ISO, so you really don’t need this partition, but it’s handy to have if something hardware-ish goes wrong. I think I’ve used the diagnostics once, over the course of a decade or so.
    2. Dell Restore, accessed by Ctrl-F11 during boot. This blows away whatever’s in the XP partition and reinstalls an image copy of whatever the laptop had when it shipped. This includes all the apps, bloatware, and other junk that came with your copy of XP. It is not a “reinstallation” of XP that saves your data; you must back up & restore that yourself.
    3. Dell MediaDirect, a special “embedded” version of XP that runs a Dell-branded media player so you can watch DVDs without enduring the lengthy XP boot process. W00t!

    It turns out that you cannot restore the drive to its as-shipped condition with all those functions in place and operable, at least without far more tinkering that seems worthwhile under any reasonable circumstances.

    Utilities

    This must be the first partition on the drive, with partition ID DE. It’s booted by the BIOS and seems relatively rugged; you can restore it from back up and it’ll work.

    Restore

    This must be either the third or fourth entry in the MBR partition table, with partition ID DB. It’s invoked by code in the MBR’s boot code when you hit Ctrl-F11 during boot. When you repartition the drive and install GRUB to run Linux, you destroy that loader.

    The distinguishing feature of the Dell MBR loader is that it puts a blue bar across the top of the screen with www.dell.com (or some such) while it’s booting. If you hit Ctrl-F11 (or, according to some sources, just F11) while that bar’s on the screen, you’ll reach the System Restore program.

    If you don’t see the blue bar, you’re sunk for Restore, even if there’s a Restore Partition on the hard drive. Some sources indicate you can boot into it with Grub, but I didn’t try that.

    There’s a non-Dell repair utility (search for it; I’ve lost the link) that can generally replace / repair the Dell MBR loader, which naturally kills GRUB in the process. You can tweak the Windows boot process to present you with a menu that includes Linux (!), but the procedure seems fraught with peril.

    If the Restore Partition is still on the drive and still listed properly in the MBR table, then you can repair the MBR loader and restore XP to its as-shipped condition. Of course, if you did a partition backup soon after you got the laptop, you could do that yourself.

    MediaDirect

    Recent Dell laptops have a MediaDirect button with two functions.

    1. When the laptop is off, the MD button turns it on and boots the MediaDirect partition.
    2. When the laptop is on, the MD button fires up a version of the Dell-branded media player as an ordinary Windows program; it has no obvious advantages over Windows Media Center, but, yo, it’s Dell.

    It turns out that the MediaDirect button depends on an incredibly frail structure to pull off function 1. The embedded XP + media player dingus lives in a separate, hidden partition with partition ID DD that prevents it from appearing in the normal XP’s view of the machine.

    The BIOS checks for that partition when you poke the MD button, rewrites the partition table on the fly to change the ID and make the partition active, then boots the embedded XP. As part of the MD boot, another program evidently rewrites the partition table again to hide the evidence. The reliable sources differ on this. Opinion: WTF were they thinking?

    It is thus possible (nay, likely) that Something Bad Will Happen to kill the button’s function. If the BIOS can’t find the appropriate partition ID, it boots the first bootable partition it finds in the MBR. Most often, that’s the normal XP partition and away you go: the MediaDirect partition is just not available.

    Dell provides a “MediaDirect Repair” CD with which you can fix that issue. It’s a pretty big hammer, though, as it repartitions & reformats the entire drive, destroying the existing drive contents as it goes. It then reinstalls the Dell Utility partition and replaces the MBR. You manually reinstall XP, then run a setup program from the MD Repair CD that finishes setting up the MD partition.

    En passant, MD Repair also replaces the Dell Restore boot loader in the MBR and destroys the Restore partition, so you cannot get your as-shipped XP back. You must restore from the CD… except, of course, that Dell no longer ships XP Reinstallation CDs, expecting that you’ll use the restore partition in case of trouble. Whoops.

    MD allows you to create either one or two partitions on the drive, so you may have one giant XP-and-data partition or an XP “system” partition and a “data” partition. Any attempt to change that partition structure prevents MD from finishing its installation: XP will work fine, but MD will be dead. You cannot fix MD without starting all over again from scratch by blowing the drive away.

    Oh, yeah, almost forgot. Dell has, natch, several different versions of MediaDirect floating around, each with incompatible repair / restore / update requirements. None of what you’ve just read may apply to your PC.

    What a piece of crap!

    Fresh Windows

    While discovering all this, I did a clean install of XP from the Reinstallation CD (IIRC, I paid extra to get it when I bought the laptop: me being no fool!) with drivers from the Drivers CD. That’s a bit tedious, as the network interface doesn’t work until you feed in the driver CD, so Windows gets pissy. When XP finally sees the Internet, it’s not happy until it downloads all 100+ patches from the Mother Ship; it’s been a while since the XP SP2 version that’s rolled into that CD.

    This process does not install the usual bloatware and it turns out that bone-stock Windows XP is actually pretty snappy: it starts up quickly, shuts down even faster, and is generally pretty responsive. You can’t do very much with it, as you don’t have many programs, but … that’s Windows!

    I then reinstalled the Windows programs I use with the various & sundry hardware gadgets: device programmers, data loggers, note-taking tablet, stuff like that.

    It’s worth mentioning that my well-cared for and rarely used Windows turned into the usual dog-slow lump everybody complains about over the course of two years. Bit rot is real and you need a clean install to fix it.

    Bottom line(s)

    Dell Restore will be useful if I ever give the laptop away. I’ll zero the drive, restore the Restore partition from my backup, run the fixup program to get the right boot loader, boot into the Restore partition, restore XP to its as-shipped level, do the updates, and be done with it.

    I suppose I could do the restore, do a partition backup, restore MediaDirect with one partition for XP, install a base version of XP, finish the MD install, -then- restore XP. I suspect that wouldn’t actually work, which is why I haven’t tried it.

    MediaDirect isn’t compelling enough to make me want to futz with it that much, particularly as it appears to be incompatible with any Linux installation.

    Props to SystemRescueCD from http://www.sysresccd.org, which I used for all the partition backups, restores, copies, MBR editing, hex dumping, and so forth and so on. All my backups live on the file server in the basement and SRC makes network backups a cinch. Can’t (and shouldn’t) live without it.

    At this point, words fail me…

  • Using DVDs for Backups and the Futility Thereof

    Early this year I made backups of a friend’s PC hard drive on DVDs (using partimage, my full-partition-backup hammer of choice) and now must recover a file for her.

    Each of the seven DVDs has two 2 GB files on it and, on every DVD, the second file is riddled with errors.

    Thousands, nay, tens of thousands of errors.

    The first file on each DVD is perfect: zero read errors.

    I’ve tried them on three different drives and, while the errors vary, the pattern is basically the same.

    Tick me right off. I’ve had a PC running ddrescue on ’em for the last few days. I’m hoping that by reading them on various drives, the recovery program can merge the good parts, but I’m not holding out a lot of hope. (Update: worked like a champ. Whew!)

    Because I’m that type of guy, I always verify the data when I write a CD or DVD, so I know these were good when they were written. Most of the DVDs seem to be visually OK, but some have dark spots in the dye layer. There aren’t any scratches or defects beyond what you’d expect for a DVD that’s been written once and handled by somebody who’s neurotically careful about that sort of thing: they’re not pristine, but they’re not far from it.

    Also because I’m that type of guy, they’re generic no-name DVDs, but so what?

    Achtung: use the GNU version of ddrescue, because it’s the one that creates & uses a log file to help retry the errors on different machines. The other non-GNU version doesn’t do that.

    Memo to self: next time, record -three- sets of DVDs and store the sets separately.