NI DAQ – VB 6 – Analog In and out

Academics, Web & Code No Comments

This is one of the pieces of code I wrote for National instruments – data acquisition device. Again… unformatted uncommented code. Sorry!!!

The need:

Some high end academic need. Basically a combination of analog inputs gives an analog out.

The Setup ( a lot of unedited text from my report):

The system consists of hardware inputs and outputs (analog) which are interfaced with the PC using the DAQ (NI USB 6008 module). Controlling the system is a software program written in Visual basic 6. The program interacts with a database(access) to read and write values.

The data acquisition system is a National Instruments USB-6008 that has 4 Analog inputs, 2 analog outputs and 12 digital I/O lines. The kit comes with NI-DAQmx driver software and LabVIEW Signal Express software. The system can be programmed using  ANSI C and visual basic 6 (VB 6). Ref. Appendix 1 for detailed specification sheet for the NI USB-6008 DAQ

The hardware consists of

  • Toggle Switch (DEV1/AI0)
  • Push buttons (DEV1/AI1, DEV1/AI2)

The buttons indicate operations (steps of a task)

  • LED lights in serial with resistor (DEV1/AO1, DEV1/AO0)

The lights indicate success or failure of task

Read the rest of this entry »

Email verification using tokens – CakePHP

Web & Code 6 Comments

I recently wrote a code for an email verification system using cakephp. Well, before you use it there are few things. This is written by a cake noob so may not be the best there is. I have not written it as a general stand alone piece of code. So its need modifications for use. And I am a sucker when it comes to commenting and formatting my code so please dont mind. My thanks to Edward and the CakePhP Google Groups. And finally cake rocks!!!

cheers

Database Table

A basic user table with the following columns

id - primary key and auto increment
username
email
password
[...]
tokenhash*
activate *

*columns with which we are concerned with

Controller code

<?php
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
var $components = array('Email');
[...]
function register() {
if (!empty($this->data)) {
$this->User->data = $this->data;
$hash=sha1($this->data['User']['username'].rand(0,100));
//Create Token using form data and random number to ensure its unique and cannot be replicated
$this->User->data['User']['tokenhash']=$hash;
if ( $this->User->validates()) {
$this->User->save($this->data);
//Save all form data including the tokenhash
$ms='Click on the link below to complete registration ';
$ms.='www.sitename.com/users/verify/t:'.$hash.'/n:'.$this->data['User']['username'].'';
$ms=wordwrap($ms,70);
//create mail body
$this->Email->from = 'yourName <email>';
$this->Email->to=$this->data['User']['email'];
$this->Email->subject = 'Confirm Registration for Niwiki - reg.';
$this->Email->send($ms);
//send mail
$this->Session->setFlash('Please Check your email for validation Link');
$this->redirect('/users/login');
exit;
}
}
}

Read the rest of this entry »

© 2009, Nikhil Hullur | Entries RSS Comments RSS