Friday, January 30, 2009

Travels in RFID pt 6

On my linux box, to read directly from the usb port (which has a usb to serial adaptor fitted)

cat < /dev/ttyUSB1

this sends the output directly to the screen and each swipe of the tag gives the RFID chip id YAY !!!

all i need to do now is redirect this direct to a php script or web server

Tuesday, December 9, 2008

Dos batch to read contents of folder and write a playlist from it

This is something I wrote to automate running videos on a plasma continuously but randomly.

However, what i wanted it to do was check the contents of the folder every time the machine was booted (or the batch file read) and re-write the playlist of files that the program plays in a random play.

The program used for playing the videos was VLC


C:
cd\

::ERASE ORIGINAL PLAYLIST FILE
erase movie.m3u

::GET INFORMATION OF WHICH FILES ARE IN C:\MEDIA\VIDEO
:: CHANGE YOUR DETAILS AS NECESSARY

cd media
cd video

@echo off

::REMOVE OLD FILE

erase avifiles.txt

:: MAKE TEXT FILE DIRECTORY OF ALL AVI FILES IN A FOLDER
dir /o /b *.avi >avifiles.txt

:: ADD FIRST LINE TO THE TEXT FILE
echo #EXTM3U >movie.m3u

:: PARSE AVIFILES.TXT FILE INTO MOVIE.M3U txt file
FOR /F %%i in (avifiles.txt) do echo c:\media\video\%%i>> movie.m3u


:: MOVE FILE to C :\

move movie.m3u c:\
c:
cd\
cd program files
cd videolan
cd vlc

:: RUN VLC FULLSCREEN WITH A RANDOMISED SELECTION
:: OF ALL FILES IN THAT ORIGINAL FOLDER TAKING FILES FROM c:\MOVIE.M3U


vlc --disable-screensaver --fullscreen --random c:\movie.m3u

Monday, December 8, 2008

Changing the windows date - starting a program & then changing the date back again.

Recently at work there was some software that suddenly wouldn't work at work because it ran out of date.

The supplier told us just to turn back clock until new version arrived which was late.

However this of course would mean that everyone's clocks and dates would be all over the place and potentially could cause problems especially with accounting software.

So... I wrote this batch file that when you click it it does the following

1. Gets todays date

2. Changes the month and tells the computer to be that date

3. Writes another batch file (in the same dir its run from) temporarily
that the first one will call (reasons to follow)

4. Calls the written batch file (which incidentally calls the program that
is located in the new batch file)

5. Puts the date back to normal

6. Pings nothing / to delay the batch file

7. closes (leaving program running)

I've annotated it somewhat more since writing it earlier today

Oh... yeah reasons for stuff...
Writing a batch file that writes a batch file which calls a program
sounds a bit arse about face.

But the reason being - if you call the program directly from the batch file
, the batch file cant continue on and change the date back until you close the program you opened originally. which makes it pointless.

So. it writes a batch file which opens the program - so the focus of the original batch is relieved (if you like) allowing it to continue on (after a delay) and change the date back again... make sense ?

The reason for a batch - its easy to write - quick and can be run in windows from a central store without issue.

@ECHO OFF

:: ----- -- DATE CHANGER FOR ------ COCKUP -----
:: ----- -- CREATED BY CHRIS GAVIN-EGAN
:: ----- -- AMPS.co.nz

:: IGNORE THIS LINE
:: IGNORE THIS ONE TOO (written previously) SET PROGRAMLOCATION="TW2.BAT"
:: -------------------------------------
:: -------------------------------------



:: -------------------------------------------
::THESE LINES WRITES THE NEW BATCH FILE
:: /D "C:\program files...." is the folder that it starts in
:: /B starts cmd in same window
:: /Seperate cmd in new process
:: /normal - run it at normal process speed
:: INET4EPC.EXE is the program we're trying to run
:: ---------------------------------------
ECHO start /B /D "C:\Program Files\Triumph EPC" /SEPARATE /NORMAL INET4EPC.exE >TW3.BAT

:: Add exit to the batch file
ECHO exit >>TW3.BAT

:: ---------------------------------------
:: Clear the screen and let people know whats happening
:: ---------------------------------------

cls
ECHO.
ECHO.
ECHO.
ECHO.
ECHO CHANGING DATE ONE MONTH BACK
ECHO WILL NOW THE PROGRAM
ECHO WHEN FINISHED - HIT RETURN TO RESTORE DATE
ECHO.
ECHO.
echo.

::SET THINGS UP

:: GET TODAYS DATE
for /F "tokens=1 delims=/- " %%A in ('date/T') do set varday=%%A
for /F "tokens=2 delims=/- " %%A in ('date/T') do set vardays=%%A
for /F "tokens=3 delims=/- " %%A in ('date/T') do set varmonth=%%A
for /F "tokens=4 delims=/- " %%A in ('date/T') do set varyear=%%A
:: ---------------------------------------
:: this var not used in this prog -------
:: ---------------------------------------
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%C%%A%%B
:: ---------------------------------------




:: ---------------------------------------
:: --- find month and set new variable ----
:: -------- then jump further down -------
:: ---------------------------------------


if %varmonth%==12 set varchanged=11
if %varmonth%==12 goto setback
if %varmonth%==11 set varchanged=10
if %varmonth%==11 goto setback
if %varmonth%==10 set varchanged=09
if %varmonth%==10 goto setback
if %varmonth%==09 set varchanged=08
if %varmonth%==09 goto setback
if %varmonth%==08 set varchanged=07
if %varmonth%==08 goto setback
if %varmonth%==07 set varchanged=06
if %varmonth%==07 goto setback
if %varmonth%==06 set varchanged=05
if %varmonth%==06 goto setback
if %varmonth%==05 set varchanged=04
if %varmonth%==05 goto setback
if %varmonth%==04 set varchanged=03
if %varmonth%==04 goto setback
if %varmonth%==03 set varchanged=02
if %varmonth%==03 goto setback
if %varmonth%==02 set varchanged=01
if %varmonth%==02 goto setback
if %varmonth%==01 set varchanged=12

:: ----------------------------------------------
:: --- this line ACTUALLYS CHANGES the date ----
:: ----------------------------------------------

:setback
date=%vardays%-%varchanged%-%varyear%


:: ----------------------------------------------
:: -- THIS CALLS THE BATCH FILE WRITTEN EARLIER --
:: ----------------------------------------------
START TW3.BAT
cls

:: ----------------------------------------------
:: -- THIS STRANGE PING COMMAND - DELAYS THINGS 15 SECS
:: -- JUST LONG ENOUGH FOR THE PROGRAM TO START
:: -- PING USED BECAUSE IT JUST WORKS EVEN WHEN NOTHING TO PING --
:: -- CHANGE 15000 to something bigger if you need it
:: ----------------------------------------------
PING 1.1.1.1 -n 1 -w 15000 >NUL

:: -----------IGNORE LINE BELOW - OLD VERSION ---
::START %PROGRAMLOCATION%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO PRESS ANOTHER KEY TO
ECHO RESTORE THE DATE
ECHO.
ECHO.
ECHO.
echo.




:: ---------------------------------------
:: --- find month and set OLD MONTH variable ----
:: -------- then jump further down -------
:: ---------------------------------------
:: GET TODAYS DATE
for /F "tokens=1 delims=/- " %%A in ('date/T') do set varday=%%A

for /F "tokens=2 delims=/- " %%A in ('date/T') do set vardays=%%A
for /F "tokens=3 delims=/- " %%A in ('date/T') do set varmonth=%%A

for /F "tokens=4 delims=/- " %%A in ('date/T') do set varyear=%%A

for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%C%%A%%B

if %varmonth%==12 set varchanged=01
if %varmonth%==12 goto setforward
if %varmonth%==11 set varchanged=12
if %varmonth%==11 goto setforward
if %varmonth%==10 set varchanged=11
if %varmonth%==10 goto setforward
if %varmonth%==09 set varchanged=10
if %varmonth%==09 goto setforward
if %varmonth%==08 set varchanged=09
if %varmonth%==08 goto setforward
if %varmonth%==07 set varchanged=08
if %varmonth%==07 goto setforward
if %varmonth%==06 set varchanged=07
if %varmonth%==06 goto setforward
if %varmonth%==05 set varchanged=06
if %varmonth%==05 goto setforward
if %varmonth%==04 set varchanged=05
if %varmonth%==04 goto setforward
if %varmonth%==03 set varchanged=04
if %varmonth%==03 goto setforward
if %varmonth%==02 set varchanged=03
if %varmonth%==02 goto setforward
if %varmonth%==01 set varchanged=02

:: ----------------------------------------------
:: --- this line ACTUALLYS CHANGES the date ----
:: ----------------------------------------------
:setforward
date=%vardays%-%varchanged%-%varyear%

:: ----------------------------------------------
:: --- this line CHECKS FOR BATCH FILE AND DELETES IT ----
:: ----------------------------------------------
iF EXIST TW3.BAT ERASE TW3.BAT

:: ----------------------------------------------
:: --- this line CLOSES THE BATCH FILE ----
:: ----------------------------------------------
EXIT

Travels in RFID pt5

Troublesome bits of information about the ID-12 that was hard to find with clarity .

ID-Innovations link

Sparkfun link

Sparkfun pinout modifier PCB if you dont want to mess around with drilling your own.

Info that is NOT on all of the PDFs about the ID-12 RFID reader module




















This bit of info was a real bugger as its right at the end of the document but isn't immediatley obvious that it is to do with the ID-12 RFID reader.





























If its hard to read...
16) Connection direct to a computer.
Direct connection to a computer RS232 can be made by connecting Pin 8 to a 1k series resistor and connecting the other end of the resistor to the computer RS232 input. The mode is called pseudo RS232. On a standard D9 socket, connect the output of the ID2/12/20 vai the series 1k to pin2 of the D-type. Connect the ground to pin5 on the D-type.

Travels in RFID pt 4

Jumper wires and re-used components.

Components from the kit that have been re-purposed are :

The LED which originally was driven by the microprocessor
1k Resistor to limit current on LED
1k Resistor for output from RFID reader to RS232 input
Jumper block (shown with Orange and Brown wires) were for output to relays and are now TX from RFID - to RS232 and ground.

The two jumpers on the far side of the board are Ground (signal ground and LED ground)



The other side (RFID reader side

Looking on the Right hand side from the top.

Pin 10 is LED/ Beeper. Jumpered to the LED soldered position.

Pin 9 Used to feed data to the Atmel processor (now missing) but this is not RS232 data which is actually fed from Pin 8, So Pin 9 is now ignored

Pin 8 (originally no connection) is jumpered across to the 1k resistor and that is then fed straight to an RS232 lead/plug via the connector block.
The remaining unanswered blue wire is the LED - earth (via another 1k resistor)

All other parts on the Board are basically LM7805 voltage regulator - caps for smoothing and a zener diode for spike protection.

With 12v DC across the power connector the LED on the unit blinked momentarily.

Swiping the RFID fob near the unit made the LED illuminated for about 3/4 second. See clip below.



So at least from that it could be determined to be working.

Next is the RS232 serial port connector. Amazingly it is hard to find something both understandable and definitive for simple serial connection. Most of the diagrams on the internet seem to be both 2 dimensional and non specific and vague as to orientation
Hence the reason this photo is both real and othorographic.

Something i didnt notice was that the pins are numbered although almost in microscopic text.

So - in this picture the cables you need to pay attention too are. Orange (TX from RFID or RX into PC) and Brown (signal ground)



(some parts have been ommitted from the post where i spent a considerable number of hours trying to work out why the PC wouldnt/ couldnt see the unit. Normal trouble shooting occured. I found that i had wired the output of pin 9 for sometime to an entirely useless point. Then after re-routing that, I couldnt assertain what the exact pin outs of the RS232, I then found that Pin 9 was actually incorrect and by further reading of the spec sheet (near the end) it comments on the fact that for RS232 output you have to output from pin 8 not 9. Oh and lastly my pc's serial port is an unknown presently and i resorted to a USB to serial adaptor which allowed it to be seen immediately oh - in linux)

Travels in RFID pt 3


Here is the board from JAY CAR with only the power supply section of the board fitted and the RFID reader.

What i have done is keep items in the correct places per the instructions - even IF i use the component for a different job than originally intended.

If you want to JUST connect your board to a PC - look carefully - remember the old saying - measure twice - cut once.
-----------------------

The parts ommitted are for either driving buzzers - driving relays - or processor timing (none of which are required)

The bottom view of the board looks like this



As you can see there are 5 wire jumpers.

Descriptions follow

Travels in RFID pt 2


ID-innnovations ID-12 RFID card reader.

A great piece of kit. Completely encapsulated with all the workings and antenna hidden.

A couple of things that are problematic

1. The pinout below the unit is 2mm as opposed to the more normal 2,54mm (0.1") so dont assume you can in anyway plug this into a socket. I have yet to look for this pin spec. So beware.

2. The PDF that is available for its specs etc seem to be (for the uninitiated) somewhat vague.
you can download the pdf here from CORE
http://www.rfidshop.com/core-12-rfid-reader-module-110-p.asp

Most of it is fine - you need to follow the wiring schematic

But remember - we are modifying a kit to suit.

Now luckily because its a kit - the pinout for the ID-12 is already made so there are no worries there.

The kit is available from JAYCAR although they no longer seem to list it on their website - but its in the stores.

Altronics stock it - check here
Dick smith electronics used to sell it but no longer do.
(Altronics K9300, DSE K7215, Jaycar KC5393)

The Altronics kit presnetly is cheap at $69 Australian dollars.

So - bit expensive when its really only the ID-12 required. but needs must: and when you consider it is pre-sized to fit a blanking plate for mains and it is has a pre-made PCB, I just bit the bullet : Kit bought.