Consignment Tracking System by alicejenny

VIEWS: 4 PAGES: 16

									dfghjklzxcvbnmqwertyuiopasdfghjklz
xcvbnmqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasd
          Consignment Tracking System
fghjklzxcvbnmqwertyuiopasdfghjklzx
            System Design & Presentation

cvbnmqwertyuiopasdfghjklzxcvbnmq
                  2/10/2010

                  Aron Bury


wertyuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmrtyuiopasdfghjkl
zxcvbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfghjklz
xcvbnmqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasd
fghjklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvbnmq
                                         Consignment Tracking System

                                         Table of Contents
Introduction ............................................................................................................................................ 3
General Use............................................................................................................................................. 4
   What is the Consignment Tracking System?....................................................................................... 4
   Inputting the Data ............................................................................................................................... 4
   Using the CTS Scanner Unit................................................................................................................. 5
How does it Work?.................................................................................................................................. 6
   How the Data is Entered and Stored .................................................................................................. 6
       The Process ..................................................................................................................................... 6
       The Programming............................................................................................................................ 6
   How the consignment note is generated............................................................................................ 7
       The Process ..................................................................................................................................... 7
       The Programming............................................................................................................................ 7
   How the Scanner Unit Works .............................................................................................................. 7
       The Process ..................................................................................................................................... 7
       The Code ......................................................................................................................................... 7
Tools, Software and Hardware Used ...................................................................................................... 8
   Software Tools & Languages ............................................................................................................... 8
       Coding: PSPad Freeware Editor ...................................................................................................... 8
       Web Debugging: Firebug................................................................................................................. 8
       Server-Side Scripting Language: PHP Hypertext Pre-processor ...................................................... 8
       Database Engine: PostgreSQL ......................................................................................................... 8
       Arduino Coding: Arduino IDE .......................................................................................................... 8
Changing the LCD Output ....................................................................................................................... 9
   Hardware ............................................................................................................................................ 9
       Arduino Mega ................................................................................................................................. 9
       Network Shield ................................................................................................................................ 9
       LCD Screen .................................................................................................................................... 10
       PS/2 Barcode Scanner ................................................................................................................... 10
       Power Regulator ........................................................................................................................... 10
       Construction.................................................................................................................................. 10
Acknowledgements............................................................................................................................... 13
Appendices............................................................................................................................................ 14


System Design & Presentation – Aron Bury                                                                                                        Page 2
                          Consignment Tracking System

Introduction
The Consignment Tracking System is a tool that will be used in INTE 2043 Business Information
Technology to give students an introduction to industrial computing and embedded systems. The
example used in this introduction is that of using a microcontroller unit to scan barcode codes.

There are two parts to the System, the software side and the hardware side. The software side is a
web server connected to a database backend that allows users to input information and generate a
consignment note with a barcode attached. The hardware side describes a microcontroller unit that
scans the barcode and displays information about that particular consignment on an LCD screen.

This document details the stages of development of the Consignment Tracking System, describes all
languages used and describes how to modify the system if maintenance is required.

Whilst this project was focused on a system that would track consignments, it also demonstrates the
power of prototyping. It is becoming easier to write software and program hardware to do all sorts
of interesting and useful things.




                  Figure 1: Barcode Scanner Unit




System Design & Presentation – Aron Bury                                                    Page 3
                           Consignment Tracking System

General Use

What is the Consignment Tracking System?
The Consignment Tracking System (CTS) is designed to simulate the creation and management of a
package that needs to go from one place to another. Although this may seem trivial at first thought,
it is actually an integral part of how commerce works in our world. As the demand for online
shopping grows, more and more packages are being sent from companies, through couriers to their
consumers.

Much of the technology that is used in industry is locked, and cannot be looked at to see how it
functions. The idea of the CTS is to help students understand how consignment tracking works, and
how a barcode can be used as a quick, effective means of identification and communication. How
can 1 barcode tell 5 different people involved in the movement of a package different things?
Through this example students are introduced to embedded systems and the world of industrial
computing.

Inputting the Data
To enter in a consignment, users must navigate to http://inte2043.bf.rmit.edu.au/scanner/login.php
and log in using their credentials (Username: user | Password: password). Users can then choose to
enter in a new consignment (New) or view an existing one (Manage).




             Figure 2: Inventory Management System Home page


It is quite easy to enter a new consignment, simply follow the 5 steps, entering in the customer
information, pickup address, delivery address, item information and finalize the order. Any errors
will be shown automatically before you go to the next page.

When you finish, it will present you with a PDF consignment note such as figure 3. Save or print it off
(you can view it later if you wish) and click back to navigate back home.



System Design & Presentation – Aron Bury                                                        Page 4
                           Consignment Tracking System




               Figure 3: Consignment Note


To view an existing consignment, simply select manage from the top navigation menu, select the
senders name, and click “generate” on the desired consignment.

Using the CTS Scanner Unit
Once you have a consignment note with a barcode, you can use it with the scanner unit. Ensure the
device is powered on (if there is no text on the screen simply hit the reset button), and connected
with an Ethernet cable to the in lab network (room 108.08.012).

Once it is ready, it should display a welcome message on the screen. Simply get the scanner unit, run
it over the barcode and wait for the beep. If the barcode number is recognised, it will display
information about the consignment on the LCD screen (default value is delivery address)




         Figure 4: Barcode scanner displaying information from CTS database




System Design & Presentation – Aron Bury                                                      Page 5
                              Consignment Tracking System

How does it Work?
For something that seems so simple, it is quite a detailed sequence of
events and interconnected systems that allows you to view your
consignment information on the scanner unit.

The website is powered by PHP, XHTML and CSS. It is hosted off an
apache web server (running on SUSE Linux) and connected to a backend
PostgreSQL database. The scanner unit is built with Arduino
Microcontroller components and programmed on a language based on C.
The entire project was powered by open source technologies and is a
powerful example of what can be accomplished with 0 dollars invested
into language usage rights, Development environments and
web/database hosting services.

How the Data is Entered and Stored
The Process
How can a stateless protocol (HTML) save and carry data through a user’s session? The easy way to
do this is using a session variable; however the proper way to do it is to store the data into a
database. There is a temporary table that stores all the consignment variables during the session.




 Figure 5: data distribution into database

Once the user confirms the consignment, the data is then distributed from the temporary table into
the relevant permanent tables.

The Programming
The programming is all done in Object Oriented Programming in PHP. Each time the user clicks next,
a PHP page is loaded on the server side, establishes a connection to the database and inserts all the
data into the table.




At confirmation, a query is run to insert all data from the temporary table to the relevant table. All
data that was being used by that user in that session is then deleted from the temporary table.


System Design & Presentation – Aron Bury                                                         Page 6
                             Consignment Tracking System

How the consignment note is generated
The Process
We decided the best way to generate a barcode was to put it on a consignment note in PDF form.
Consignment notes are generated by writing line by line, what you want and where. The barcode is
in 3of9 (or code 39) format and is a font that is easy to implement into normal document.

Once a consignment is created and the note generated, it is not stored on the server. To save space,
whenever a user requests an existing consignment note, they are simply directed to a PHP page and
providing that page with three Primary key values. The PHP page then queries the database for the
information that matches the relevant values and displays it on the PDF.

The Programming
As PDF files are generated one line at a time, it is a challenge to perform any type of sophisticated
layout, let alone effects such as curved boxes. Instead of spending hours and hours learning how to
perform this, I incorporated a library that allowed me to easily layout the data in boxes. This also
used OOP, by calling the FPDF class, then the function to add a particular type of data (sender
information, receiver information etc)

How the Scanner Unit Works
The Process
The scanner unit itself is a combination of Arduino hardware (detailed in a different section), a PS/2
keyboard/barcode scanner and LCD screen.

When the unit is turned on, it checks that it is connected to a network and obtains a DHCP lease
(gets an IP Address from the server) and waits for user input.

If a user successfully scans a barcode, the board loops, reading a bit at a time (8 loops per number).
It then concatenates the numbers together to create the consignment ID. This is used to query the
database later on.

The board does not have the power or language capability to query the database itself, so instead it
asks a PHP page to do it instead. The board constructs a URL:

(GET http://inte2043.bf.rmit.edu.au/scanner/ardunio.php?con_id= + consignment ID) and sends it
to the PHP page for processing. The PHP page returns the result, however all is not done.

Modern browsers hide much of the code behind a webpage; unfortunately the Arduino is not so
advanced. This means that the PHP returns a whole bunch of useless header information. The board
goes through each character in the data set and only displays what is in between the “|” characters
(XML tags are very complex to program for the Arduino) It then displays the result on the LCD screen
and waits for the next scan.

The Code
Programming an Arduino microcontroller for a process like this is a challenge for a number of
reasons. It is a very primitive version of C, with little to no ability to manipulate strings or connect to
networks. Luckily as it is open source, there are external libraries that contain functions that allow us
to what we needed to do. A full copy of the code is included in the appendices.

System Design & Presentation – Aron Bury                                                           Page 7
                                 Consignment Tracking System

Tools, Software and Hardware Used

Software Tools & Languages
Coding: PSPad Freeware Editor
This is the main program I used thought the majority of the program to write anything to do
with the web site. Capable of highlighting 28 different formats with many tools that can be
used by developers. The use of multiple tabs, syntax highlighting and HTML verification were
its major strengths. Unfortunately there is no debugging ability for PHP, so this had to be
done in the browser.

Program Version: 4.5.4

Author: Jan Fiala1

Web Debugging: Firebug
This program is invaluable for pulling apart HTML/CSS and debugging JavaScript. I
used this mainly during the latter half of the website development to test and
debug the AJAX effects.

Program version: 1.5.0

Author: Joe Hewitt2

Server-Side Scripting Language: PHP Hypertext Pre-processor
This is the language that runs the server side of the web server and
generates dynamic content for the user.

Software version: 5.0.4

PHP Group: Thies C. Arntzen, Stig Bakken, Shane Caraveo, Andi Gutmans,
Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski.3

Database Engine: PostgreSQL
A popular open source database engine and a good contender to MySQL,
PostgreSQL is a powerful, flexible database engine that easily meets many users
demands.

Engine Version: 64

Arduino Coding: Arduino IDE
The Arduino IDE is a simple program that allows programming in a simple version of C and uploads it
to the Arduino board with a serial output monitor.

Software Version: 00185

1
    http://www.pspad.com/
2
    http://getfirebug.com/
3
    http://www.php.net
4
    http://www.postgresql.org/
5
http://www.arduino.cc/

System Design & Presentation – Aron Bury                                                       Page 8
                            Consignment Tracking System

Changing the LCD Output
The code in this solution has been made to be highly reusable and dynamic. To change the code on
the LCD screen, you do not need to modify its internal programming. Instead, open the
“ardunio.php” page and modify the code to get a different result. Documentation is included in the
file on how to change it but as a quick example, if you wanted to display consignment pick up
address, you would write:

Echo “|” . $row->pickup_addressl1 . “ “ . $row->pickup_addressl2 . “|”;

It’s fairly clear what code to change; one does not need a very in-depth understanding of PHP to
modify the page.

Whilst it is definitely possible to retrieve information from other tables, it requires a more in depth
understanding of PHP, SQL and the classes used. I recommend contacting me to perform this change
as I can have it done very quickly.

Hardware
Arduino Mega
                                                 This is the base of the scanner unit, it ties everything
                                                 together. It has 128 kb of flash memory and 8 kb of
                                                 SRAM. The Mega provides power and processing for
                                                 the rest of the device.

                                                The Mega was chosen in place of the more standard
                                                Auduino Duemilnove because it provides more serial
  Figure 6: Arduino Mega                       connections (4 vs 1), has more memory and more
                                               analogue and digital ports.

In the event, the Duemilnove could have been used as work-arounds exist for the lack of serial ports
and the program was not a big as anticipated.

Network Shield
This part mounts on top of the Arduino board and allows
it to connect to the network.

The Ethernet Shield is designed to work with the
“standard” Arduino boards. However, the Arduino Mega
is, without alteration, incompatible with the Ethernet
Shield. The reason for this is that the standard boards
have a Serial Peripheral Interface (SPI) (used by the
Ethernet Shield) on digital pins 10 to 13, whereas the
Mega has a number SPIs located on different pins.

A work-around for this issue exists, involving cutting the        Figure 7: Arduino Network Shield
connections from the shield to pins 10-13 and wiring




System Design & Presentation – Aron Bury                                                             Page 9
                                  Consignment Tracking System

  shields SPI to pins 50-53 on the Mega. This connection can be seen (orange, blue, yellow and brown
  wires) in photos of the completed unit.

  LCD Screen
  This bright, 2x18 screen allows data to be displayed without being connected to an external screen
                                     or a computer.

                                      The display board used was equipped with a serial interface
                                      (simplifying connection to the Arduino) which was connected to
                                      serial port 1 on the Arduino Mega


Figure 8: LCD Screen

  PS/2 Barcode Scanner
                                                        This simple barcode scanner connects via a
                                                        PS/2 connection to the Arduino board and
                                                        provides barcode scanning functionality.

                                                        Unfortunately, PS/2 scanners rely on
                                                        keyboards to provide their clock signals. As a
                                                        result, the scanned used in the project has to
                                                        be attached to a keyboard.
 Figure 9: ps/2 Barcode Scanner

  Power Regulator
              The scanning unit is designed to be used with a 9v plug pack. However, unregulated
              9v power packs frequently rise to about 15v, which presents a serious risk to the
              Arduino, in spite of the in-built power regulator on the board. Consequently, a small
              power regulator board was installed to ensure that a steady 9v was available to the
              circuitry. The on-board regulator further reduced the voltage to 5v.


  Construction
  The following photo illustrates the principal components of the scanner unit.

  The major components can be seen:

      Keyboard and Scanner

      Plug pack

      Power supply regulator

      Arduino Mega

      Ethernet Shield

      LCD Display

  System Design & Presentation – Aron Bury                                                     Page 10
                        Consignment Tracking System




                                                                 The picture on the left
                                                                 illustrates the Ethernet Shield
                                                                 attached to the Arduino Mega
                                                                 with pins 10-13 disconnected.
                                                                 Also illustrated are the
                                                                 connections between the shield
                                                                 and pins 50-53 on the Arduino
                                                                 Mega.




                          The next photo illustrates the connection to the PS/2 scanner (white,
                          yellow, white and grey wires). The small board on top of the shield
                          hosts two pull-up resistors attached to the scanner clock and data lines
                          to ensure that they do not “float” but are
                          either “high” (5 v) or “low” (0v).




System Design & Presentation – Aron Bury                                                 Page 11
                        Consignment Tracking System

                                           This photo illustrates the prototype
                                           connection between the screen and the
                                           Arduino. Connections are to 5v (red clips),
                                           0v (black clips with black wire) and signal
                                           (black clips with blue wire).




System Design & Presentation – Aron Bury                                       Page 12
                         Consignment Tracking System

Acknowledgements
    Ian Storey
    Ian Searle
    RMIT School of Business and logistics




System Design & Presentation – Aron Bury               Page 13
                                           Consignment Tracking System

Appendices

Arduino Code Page (INTE2043_Scanner_PHP.pde)
/*
INTE2043 Barcode Scanner project
 Written by: -Aron Bury
       -Ian Searle
       -Ian Storey
       (Scanner code written by Bejamin Maus)
 Date:03/02/2010
 Description: This code is for the arduinio board the accompanies the
 inventory management system (http://seven.bf.rmit.edu.au/~s3210800/login.php)
 We receive a barcode value from the ardunio board and place it in a variable.
 Once done, we constrcut a GET URL and sne it to the server, which then returns a value.
 */

//Declare extneral libraires
#include <WString.h> //String Manipulation
#include <EthernetDHCP.h> //Ethernet DHCP functions
#include <Ethernet.h>//Ethernet functions

//Declare values used to connect to datbase
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[] = {131,170,198,7}; // seven.bf.rmit.edu.au

Client client(server, 80);

//Scanner variable declerations
int SCAN_ENTER = 0x5a;
int SCAN_BREAK = 0xf0;
int breakActive = 0;
int clockPin = 33; // Clock is only output.
int dataPin = 31; // The data pin is bi-directional
// But at the moment we are only interested in receiving
int ledPin = 13; // When a SCAN_ENTER scancode is received the LED blink
int clockValue = 0;
byte dataValue;
byte scanCodes[10] = {
  0x45,0x16,0x1e,0x26,0x25,0x2e,0x36,0x3d,0x3e,0x46};
char characters[10] = {
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
int quantityCodes = 10;
char buffer[64] = {
};                // This saves the characters (for now only numbers)
int bufferPos = 0;
int bufferLength = 64;

String sCon_id = String(10);
String sURL = String(50);

//Start
void setup()
{
  //Declare Pin numbers
  pinMode(dataPin, INPUT);
  pinMode(clockPin, INPUT);
  pinMode(ledPin, OUTPUT);
  EthernetDHCP.begin(mac);
  Serial.begin(9600);
  Serial1.begin(9600);
  delay(20);
  clearLCDscreen();
  Serial1.print("RMIT Logistics");

}

void loop()
{
  sCon_id = g_GetBarcode();
  //Obtain DHCP Lease
  //Serial.println("Obatining a DHCP Address");

     if (client.connect())
    {
      //Serial.println("connected");
      sURL = "GET /~s3210800/ardunio.php?con_id=";
      sURL.append(sCon_id);
      //Serial.println(sURL);
      client.println(sURL);


System Design & Presentation – Aron Bury                                                   Page 14
                                                Consignment Tracking System
     client.println();
     clearLCDscreen();
     GetResult();
     client.stop();
    }
    else
    {
      Serial.println("connection failed");
    }

}

void GetResult(){
 int printFlag = 0;
 int connectedFlag = 0;
 delay(100);
 if (client.available()) //If the client connects...
 {
   connectedFlag = 1;
   //Serial.println("in Loop");
   char c = client.read(); //Read each character...
   if (client.available() && c == '|') //once it reaches the '|' char
     {
       c = client.read(); //progress to the next char (skip '|')
       while (client.available() && c!= '|') //Continue till the end '|'
       {
         Serial.print(c); //Print character (LOOP)
         Serial1.print(c);
         printFlag = 1;
         c = client.read(); //Read Next (LOOP)
       }
     }
 }

    if (connectedFlag == 0) {
      Serial.println ("Did not connect to database");
      Serial1.print ("Did not connect to database");
      }
    else if (printFlag==0) {
        Serial.print("Item not found: ");
        Serial.println(sCon_id);
        Serial1.print("Item not found: ");
        Serial1.print(sCon_id);
      }

    if (!client.connected())
    {
      Serial.println();
      //Serial.println("disconnecting.");
    }

}

//Scans the Barcode and returns a string
String g_GetBarcode (){
 String sBarcodeNumber = String(10);
 int BarcodeFinished = 0;

    while (BarcodeFinished == 0){

    sBarcodeNumber = "";

    dataValue = dataRead();
    // If there is a break code, skip the next byte
    if (dataValue == SCAN_BREAK) {
    breakActive = 1;
    }
    // Translate the scan codes to numbers
    // If there is a match, store it to the buffer
    for (int i = 0; i < quantityCodes; i++) {
      byte temp = scanCodes[i];
      if(temp == dataValue){
        if(!breakActive == 1){
          buffer[bufferPos] = characters[i];
                  bufferPos++;
        }
      }
    }

    // Print the buffer if SCAN_ENTER is pressed.
    if(dataValue == SCAN_ENTER){


System Design & Presentation – Aron Bury                                      Page 15
                                              Consignment Tracking System
    // Read the buffer
     int i=0;

     if (buffer[i] != 0) {
       while(buffer[i] != 0) {
          sBarcodeNumber.append(buffer[i]);
                   buffer[i] = 0;
                   i++;
        }
       }
       BarcodeFinished = 1;
       bufferPos = 0;
       // Blink the LED
       digitalWrite(ledPin, HIGH);
       delay(300);
       digitalWrite(ledPin, LOW);
    }
    // Reset the SCAN_BREAK state if the byte was a normal one
    if(dataValue != SCAN_BREAK){
      breakActive = 0;
    }
    dataValue = 0;
    }

    return sBarcodeNumber;
}

int dataRead() {
               byte val = 0;
               // Skip start state and start bit
               while (digitalRead(clockPin)); // Wait for LOW.
               // clock is high when idle
               while (!digitalRead(clockPin)); // Wait for HIGH.
               while (digitalRead(clockPin)); // Wait for LOW.
               for (int offset = 0; offset < 8; offset++) {
                              while (digitalRead(clockPin));       // Wait for LOW
                              val |= digitalRead(dataPin) << offset; // Add to byte
                              while (!digitalRead(clockPin));      // Wait for HIGH
               }
// Skipping parity and stop bits down here.
               while (digitalRead(clockPin));         // Wait for LOW.
               while (!digitalRead(clockPin));         // Wait for HIGH.
               while (digitalRead(clockPin));         // Wait for LOW.
               while (!digitalRead(clockPin));         // Wait for HIGH.
               return val;
}
 void clearLCDscreen() {
   Serial1.print(0xFE, BYTE);
   Serial1.print(0x01, BYTE);
 }




System Design & Presentation – Aron Bury                                              Page 16

								
To top