UniLogic functions

Int to Real

D = A + B x 10 ^ (-C)

Real to Int

A = XXXXXX.YYYYYY

C = XXXXXX

D = Round 0.YYYYYY to B decimal places, then multiply by 10 ^ B

At least I think this is what it’s supposed to do – it seems to have some issues:

  • Rounding close to 0.5 can be somewhat unpredictable. e.g. A = 5.246, B = 1 will give D=3, not D=2 as it should.
  • Note that the Integer part is always simply truncated – don’t expect this function to Round correctly – e.g. A = 12.99, B = 1 will give C=12 and D=10, instead of C=13, D=0 as you might expect!

Allen Bradley Micro810 LCD Characters

Updated, now that I’ve found out how to directly enter a character code

Updated again. I’ve lost all the uploads to this site, so while the tables might still be useful, you’ll need to generate the characters youself if you want to see them.

If you’re the curious type (quite possible) and you’ve been playing with an Allen Bradley Micro810 (less likely) you might have wondered what special characters you can put on the screen.

And you’d stay curious if you tried to find the answer in the Allen Bradley Documentation, because it’s shit: It doesn’t even tell you how many characters there are on a each line. Incidentally, the answer is 16.

So, in an attempt to remedy the situation, I wrote a simple program which displays every character. Unfortuantely this was lost, but it shouldn’t be hard to re-create it. You will need Connected Components Workbench.

Entering the characters into strings is pretty easy – just type $ followed by the 2 digit Hex code. e.g. ‘Hello$21’ would appear as Hello!.

The first 32 are dramatically different to the ASCII standard, and well worth knowing about, but there are a few others different 5C,5E & 7F. Codes 80 to FF are less useful, but there are a few accented characters in there that might be of use, depending on which language you use.

Characters 00 – 3F (0-63)

Loads of goodies in here, look!

HEX DEC Symbol ASCII Description Micro810 Display
00 0 NUL Null char Space
01 1 SOH Start of Heading Empty Box
02 2 STX Start of Text Filled Box
03 3 ETX End of Text Up/down arrows
04 4 EOT End of Transmission Double down arrow
05 5 ENQ Enquiry Double Up arrow
06 6 ACK Acknowledgment Filled Box
07 7 BEL Bell Vertical Bar
08 8 BS Back Space Filled box with hole
09 9 HT Horizontal Tab Circle
0A 10 LF Line Feed Filled box with circle
0B 11 VT Vertical Tab Male Symbol
0C 12 FF Form Feed Female Symbol
0D 13 CR Carriage Return 1 musical note
0E 14 SO Shift Out / X-On 2 musical notes
0F 15 SI Shift In / X-Off Star
10 16 DLE Data Line Escape Right Arrow
11 17 DC1 Device Control 1 (oft. XON) Left arrow
12 18 DC2 Device Control 2 Up/down arrow thin
13 19 DC3 Device Control 3 (oft. XOFF) Something, not sure what
14 20 DC4 Device Control 4 Vertical line
15 21 NAK Negative Acknowledgement Section sign
16 22 SYN Synchronous Idle Small filled box
17 23 ETB End of Transmit Block Up/down arrow 3
18 24 CAN Cancel Up arrow thin
19 25 EM End of Medium Down arrow thin
1A 26 SUB Substitute Right arrow thin
1B 27 ESC Escape Left arrow thin
1C 28 FS File Separator Small “L”
1D 29 GS Group Separator Lef/Right arrow thin
1E 30 RS Record Separator Up Arrow
1F 31 US Unit Separator Down arrow
20 33 Space  
21 33 ! Exclamation mark  
22 34 Double quotes (or speech marks)  
23 35 # Number  
24 36 $ Dollar  
25 37 % Percentage  
26 38 & Ampersand  
27 39 Single quote  
28 40 ( Open parenthesis (or open bracket)  
29 41 ) Close parenthesis (or close bracket)  
2A 42 * Asterisk  
2B 43 + Plus  
2C 44 , Comma  
2D 45 Hyphen  
2E 46 . Period, dot or full stop  
2F 47 / Slash or divide  
30 48 0 Zero  
31 49 1 One  
32 50 2 Two  
33 51 3 Three  
34 52 4 Four  
35 53 5 Five  
36 54 6 Six  
37 55 7 Seven  
38 56 8 Eight  
39 57 9 Nine  
3A 58 : Colon  
3B 59 ; Semicolon  
3C 60 < Less than (or open angled bracket)  
3D 61 = Equals  
3E 62 > Greater than (or close angled bracket)  
3F 63 ? Question mark

Characters 40-7F

Most of these are pretty similar to standard ASCII, but with a few exceptions

HEX DEC Symbol ASCII Description Micro810 Display
40 64 @ At symbol  
41 65 A Uppercase A  
42 66 B Uppercase B  
43 67 C Uppercase C  
44 68 D Uppercase D  
45 69 E Uppercase E  
46 70 F Uppercase F  
47 71 G Uppercase G  
48 72 H Uppercase H  
49 73 I Uppercase I  
4A 74 J Uppercase J  
4B 75 K Uppercase K  
4C 76 L Uppercase L  
4D 77 M Uppercase M  
4E 78 N Uppercase N  
4F 79 O Uppercase O  
50 80 P Uppercase P  
51 81 Q Uppercase Q  
52 82 R Uppercase R  
53 83 S Uppercase S  
54 84 T Uppercase T  
55 85 U Uppercase U  
56 86 V Uppercase V  
57 87 W Uppercase W  
58 88 X Uppercase X  
59 89 Y Uppercase Y  
5A 90 Z Uppercase Z  
5B 91 [ Opening bracket  
5C 92 \ Backslash Weird Portcullis thing
5D 93 ] Closing bracket  
5E 94 ^ Caret – circumflex Right arrow tall (Cursor)
5F 95 _ Underscore  
60 96 ` Grave accent  
61 97 a Lowercase a  
62 98 b Lowercase b  
63 99 c Lowercase c  
64 100 d Lowercase d  
65 101 e Lowercase e  
66 102 f Lowercase f  
67 103 g Lowercase g  
68 104 h Lowercase h  
69 105 i Lowercase i  
6A 106 j Lowercase j  
6B 107 k Lowercase k  
6C 108 l Lowercase l  
6D 109 m Lowercase m  
6E 110 n Lowercase n  
6F 111 o Lowercase o  
70 112 p Lowercase p  
71 113 q Lowercase q  
72 114 r Lowercase r  
73 115 s Lowercase s  
74 116 t Lowercase t  
75 117 u Lowercase u  
76 118 v Lowercase v  
77 119 w Lowercase w  
78 120 x Lowercase x  
79 121 y Lowercase y  
7A 122 z Lowercase z  
7B 123 { Opening brace  
7C 124 | Vertical bar  
7D 125 } Closing brace  
7E 126 ~ Equivalency sign – tilde  
7F 127   Delete Square Root sign

Characters 80-BF

A couple of accented letters, but not much else.

Characters C0-FF

A solitary asian symbol (I have no idea which language it’s from) and some more accents.

Sysprep Notes

Sysprep

With the OOBE and Generalise options,

  • Will preserve user accounts
  • Drivers will automatically re-install
  • Remembers network keys
  • Forgets network locations (Home/Work/Public)
  • Updates remain installed
  • Windows update need to complete an initial scan
  • Microsoft update is turned off
  • Action Centre items in default state
  • Antivirus starts and works correctly

List all the files in a windows directory

Ever wanted to list all the files in a directory tree – I tend to find this useful when checking if there’s anything in a mass of automatically generated directories

Use this command:

dir /S /A:-D /B

Here’s what the switches mean:

/S
Look in all subdirectories
/A:-D
Don’t show subdirectories in the list of files
/B
Bare Format. Just shows the path, no extra information

Updating WordPress

Updating wordpress:

mkdir ~/temp
cd ~/temp/
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

cd /var/www/html/

sudo rm -Rf wp-admin/
sudo rm -Rf wp-includes/

sudo cp -R ~/temp/wordpress/wp-admin/ .
sudo cp -R ~/temp/wordpress/wp-includes/ .


rsync -vcrultO ~/temp/wordpress/wp-content/ wp-content/

sudo chgrp -R apache .
sudo chown -R apache .

rsync -nvcrultO --exclude 'wp-content' --exclude 'wp-includes' --exclude 'wp-admin' ~/temp/wordpress/* .

Set-up SpiderOak on CentOS

Download the relevant SpiderOak binary – for the 32-bit Fedora installer it’s:

wget https://spideroak.com/getbuild?platform=fedora&arch=i386

Install

sudo yum install spideroak-download-file.rpm

Set up, using interactive mode

/usr/bin/SpiderOak --setup=-

Enter details and protect your data!

Use cron to run this command as frequently as necessary

/usr/bin/SpiderOak --batchmode

VirtualBox direct access to SD Card in Windows

I’ve trying to get my Raspberry Pi working with a touchscreen (eGalax Touch).

This blog post has been an incredible help, but I stumbled at the very last hurdle – modifying the contents of the SD card.

You see, my compile system (Ubuntu 13.04) was in a virtual machine (VM) – VirtualBox running on Windows 7.

Windows 7 doesn’t know how to read the various linux filesystems, so they’re invisible, which means I needed to access to the whole, raw disk directly from the VM.

Here’s a step-by-step guide to directly mounting raw SD card in your virtual machine, so you can edit it.

    1. Get the DeviceID for you SD Card reader

Open a command window as an administrator. (Press Start, type cmd, right click on cmd.exe in the list, and choose “Run as administrator”)

type

wmic diskdrive list brief

and if your system is anything like mine you’ll get something like this:

C:\Users\Sandy Scott>wmic diskdrive list brief
Caption                      DeviceID            Model                        Partitions  Size
WDC WD7500BPKT-75PK4T0       \\.\PHYSICALDRIVE0  WDC WD7500BPKT-75PK4T0       3           750153761280
O2Micro SD SCSI Disk Device  \\.\PHYSICALDRIVE1  O2Micro SD SCSI Disk Device  1           3964584960

The top item is the main hard drive, the lower one is the SD card.

The bit we’re interested in is the DeviceID, in this case \\.\PHYSICALDRIVE1

    1. Navigate to the VirtualBox directory

Next thing you’ll need to find is the installation directory for VirtualBox. This is usually C:\Program Files\Oracle\VirtualBox\. You’ll know it’s the right one if it has lots of files starting with VBox in it.

Go there by entering this command

cd C:\Program Files\Oracle\VirtualBox
    1. Create the link file to the SD card
VBoxManage internalcommands createrawvmdk -filename "%USERPROFILE%/Desktop/sdcard.vmdk" -rawdisk "\\.\PHYSICALDRIVE1"

The file you’ve just created (sdcard.vmdk, on your Desktop) is a special link that lets a virtual machine access the SD card.

    1. Connect the VM to the SD card using the link

Now, open VirtualBox as Administrator, and open the Settings for your virtual machine. Go to Storage -> Controller: SATA -> (right click) Add Hard Disk -> Choose Existing Disk and open the file you just created.

Fire up the VM and you should be able to access the SD card in all it’s glory!

Batch Editing with Gimp Script-fu

A couple of days I posted a short script, that did a few very simple tasks – that was just a start, to help me get into Gimp Scripting, and help with a little job.

Today’s task is quite a bit meatier.

I’m doing tech for a play, and I want a copy of the script that I can mark up. I’ve scanned the whole thing, but it has all the usual problems with scans – pages aren’t aligned, background isn’t white, and you can see text on the other side of the page showing through.

All these can be fixed, and some even automated.

I’m not enough of an image processing wizard to fix the alignment automatically, but Gimp’s rotate and crop tools should do you proud! I found the Fixed->Size option in Rectangle Select very useful for getting all the output images the same size.

The script does the rest, read the comments (anything after a “;” on a line) to see how it works.

(script-fu-register
            "script-fu-scan-text-enhance"  ;func name
            "Scanned Text Enhance"         ;menu label
            "Scanned Text Enhancement"     ;description
            "Sandy Scott"                  ;author
            "Copyright 2013, Sandy Scott"  ;copyright notice
            "August 4, 2013"               ;date created
            "*"                            ;image type that the script works on
            SF-IMAGE       "Input image" 0
            SF-DRAWABLE    "Input drawable" 0 
            )
(script-fu-menu-register "script-fu-scan-text-enhance" "/Filters/Text")

(define (script-fu-scan-text-enhance image drawable)

    (let* ( )    
        
        ; Prep
        (gimp-context-push)
        (gimp-image-undo-group-start image)
        
        ; Actual work here
        
        ; Duplicate Layer
        (gimp-image-insert-layer image (car (gimp-layer-copy (car (gimp-image-get-active-layer image)) FALSE)) 0 0)
        
        ; Threshold
        (gimp-threshold (car  (gimp-image-get-active-drawable image)) 127 255)
        
        ; Select by Colour
        (gimp-context-set-antialias TRUE)
        (gimp-context-set-feather TRUE)
        (gimp-context-set-feather-radius 1.5 1.5)
        (gimp-context-set-sample-merged FALSE)
        (gimp-context-set-sample-threshold-int 1)
        (gimp-context-set-sample-transparent FALSE)
        (gimp-image-select-color image CHANNEL-OP-REPLACE (car  (gimp-image-get-active-drawable image)) '(0 0 0))
        
        ; Grow Selection
        (gimp-selection-grow image 1)
        (gimp-selection-invert image)
        
        ; Hide Duplicated Layer
        (gimp-item-set-visible (car  (gimp-image-get-active-drawable image)) FALSE)
        
        ; Activate Bottom Layer
        (gimp-image-set-active-layer image (vector-ref (cadr (gimp-image-get-layers image)) (- (vector-length (cadr (gimp-image-get-layers image))) 1)))
        
        
        ; Fill Selection with White
        (gimp-edit-fill (car  (gimp-image-get-active-drawable image)) WHITE-FILL)
        
        ; Clear Selection
        (gimp-selection-none image)
        
        ; Finishing Off
        (gimp-image-undo-group-end image)
        (gimp-context-pop)
        (gimp-displays-flush)
    )
)

Save with a .scm file extension put this in your scripts Directory (go to Edit->Preferences->Folders->Scripts if you don’t know where that is) then reload scripts (Filters->Script-Fu->Refresh Scripts). It should appear as Filters->Text->Scanned Text Enhance.

That’s all well and good if you’ve only got one image. What if you’ve got 80? Let’s automate this with a script.

The above script does the actual work of manipulating the image – the next one does the donkey work of loading the file, starting the manipulation script, then saving the file. In this case, it just saves over the old file, so make sure you’ve got a copy of the original in case it goes wrong. This should also be saved with a .scm extension in your scripts directory.

(define (scan-text-enhance filename)
    (let* (
            (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
            (drawable (car (gimp-image-get-active-layer image))) )
        (script-fu-loot-prep2 image drawable)
        (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
        (gimp-image-delete image)
    )
)

This has helped a bit – this script allows us run the text processing with only one piece of information – the filename, but how do you run it?
Type this into your command line:

"C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b "(scan-text-enhance \"filename.png\")" -b "(gimp-quit 0)"

You might need to change the path to your installation of Gimp, and also filename.png to the path to your image.

Finally, to automate this, I’m going to use a batch file. Make a batch file with this text:

for %%x in (*.png) do "C:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b "(script-enhance \"%%x\")" -b "(gimp-quit 0)"

This will run our script on all the .png images in the current directory.

Thanks to:
Gimp Tutorials: GIMP Batch Mode
Gimp Docs: A Script-Fu Tutorial
SuperUser: Windows batch processing images with gimp and saving them to new files

A basic Gimp script-fu

I’ve just been playing with Gimp, and getting to grips with the scripting system.

I’m sharing a very basic script – it only does two simple tasks:

  • Sets the image to Grayscale
  • Rotates 90 degrees counter-clockwise

It doesn’t need any extra parameters, so I thought I’d share it as a very simple example that you can adapt to your needs!

(script-fu-register
    "script-fu-test-script"                     ;func name
    "Test Script"                               ;menu label
    "Test script that does a few simple tasks"  ;description
    "Sandy Scott"                               ;author
    "Copyright 2013, Sandy Scott"               ;copyright notice
    "August 3, 2013"                            ;date created
    "*"                                         ;image type that the script works on
    SF-IMAGE       "Input image" 0
    SF-DRAWABLE    "Input drawable" 0 
            )
(script-fu-menu-register "script-fu-test-script" "/Filters/Test")

(define (script-fu-test-script image drawable)

    (let* ( )
        
        ; Prep
        (gimp-context-push)
        (gimp-image-undo-group-start image)
        
        ; Actual work here
        
        ; Convert to grayscale
        (gimp-image-convert-grayscale image)
        ;Rotate 90 CCW
        (gimp-image-rotate image ROTATE-270)
        
        ; Finishing Off
        (gimp-image-undo-group-end image)
        (gimp-context-pop)
        (gimp-displays-flush)
    )
)