I2C Based Scripts  
  BV4205-LM35
BV4205-ADC
BV4206-gpio
BV4218-lcd+key
PCF8591

 

 

 
     
  IASI Based Scripts  
  BV4103 - LCD
BV4102 - Matrix
BV4113 - Motor

 

 
     
  Problems  
  Trouble Shooting

 

 
     
 
  Browser  
 

 
     
  VB Scripts for COM Devices  
 

Introduction

This section has been designed to illustrate the possibilities of using BV products with a PC via a web browser. This is made possible by the use of VBScript, other languages could of course be used but VBScript (VBS) is very simple, can be used with many Microsoft applications and is powerful enough to be useful.

The scripts described here can also be used as stand alone or within applications other than a browser, Word or Excel for example. Imagine a data logger that directly inputs data to Excel? Control the Central heating from Word? All of the scripts are copyright free and can be used and modified how you like.

For the scripts on the left hand menu to work the browser must be capable of running VBScript, Firefox for example will not work without a plug-in. If you have problems running the scripts see the trouble shooting page.

All of the code is contained within the relevant htm page, use 'view source' to use and modify the scripts.

 
     
  VB Script and the COM Port  
 

There are lots of choices when accessing the outside world from a PC, these include the printer port, the COM port, USB, Network and dedicated PC card. Unfortunately none of these were intended as a general purpose input output port. The printer port comes close but that is obsolete on some machines.

The best answer is to use a protected USB device, this has lots of advantages such as it can power other devices, it is reasonably standard and best of all it can be connected to the PC without any modifications. A protected device should be used if it is intended to use the USB power supply, although the internals of a PC will protect against a short circuit on the USB bus, it is not guaranteed and so the device needs its own protection.

ByVac supplies two protected devices, the BV4221 which will interface to I2C devices and the BV412 that will interface with IASI devices or any device that uses TTL 5V logic compatible signals. The IASI devices can in fact connect directly to the PC COM port if required. The BV412 will be available May 2008.

Both of the above devices use a circuit from www.ftdichip.com The reason for using this is that the drivers are widely available and can be used for most operating systems. The latest (VCP) drivers should be obtained from this site.

What makes all of this possible is the ActiveX COM port control provided by Microsoft for their operating system. At the beginning of the script is a variable called MSComm, this is set to the COM object when a port is opened by:

Set MSComm = CreateObject("MSCommLib.MSComm")

Everything else, the scripts and code rely on this and that is the reason why this code will only work in a browser or application capable of using the above. This means that IE Explorer will work and Firefox will not without a suitable plug-in.

 
     
  Using The BV4221 with VBScript  
 

The BV4221 is a USB to I2C(see box) translator or it could be called a terminal. Commands sent to the BV4221 are translated into I2C. The BV4221 acts as an I2C master. For example "s 3 p" means send a start condition using the default I2C device address, send a byte with the value of 3 and then send a stop condition. Another example is "s-20 r g-3 p" This means send a start condition to a device with the address of 20, send a restart condition using address 21, get 3 bytes from the slave and then send a stop condition.

The key to understanding how this works is by knowing that the BV4221 behaves as a COM device, in other words when the driver is installed it will become a COM port and any applications that use a COM port can use this device, HyperTerminal for example. In fact to get to grips with the device and any I2C hardware it is connected to BV Terminal is recommended. The scripts and code presented here assume that you have already got the device working and connected to some I2C hardware, the BV4221 comes with a datasheet.

NOTE: VBS does not seem to like COM ports with high numbers, as Windows simply increases the COM port number for every new device defined it can get out of hand, this file explains how to change the COM port number of a particular device.
 

 
     
  Browser Based Scripts  
 

The htm applications will not work directly off of a web site, they must be downloaded to your PC and run from there. There will be one or more warnings about security, this is because VBScript can be dangerous if run from an untrusted source. You will get security warnings that you will have to accept in order for the scripts to run properly. Also the scripts will only run in a browser capable of running VBScript, this is Microsoft's IE.

This text and the whole of this mini site is provided in a zip file to download, it should be unzipped to a local directory and this file should be opened using IE. This file is called "index.htm" Note the links are provided in here and they will open the various files but they will not run the VBScript from the web server.

  • PCF8591.htm This file is a simple demonstration for using the Philips A to D, D to A converter
  • BV4218-lcd+key This is a demonstration for using the BV4218 which is an LCD and keypad interface, it also has a routine for setting up the keys
  • BV4205-ADC.htm The BV4205 is a 20 pin DIL IC, 10 bit A to D converter
  • BV4205-LM35 This uses the A to D chip connected to an analogue LM35 temperature gauge, it will read out the temperature in degrees Celsius.
  • BV4206-gpio.htm This demonstrates the i/o and timing capability of the BV4206. The PWM capability was not added but could be very easily.

The above files contain within them an explanation of what is going on but basically at the top of the file is the VBScript that communicates with the BV4221. Only a handful of routines are needed for this and can be re-used in any application.

The next section after the VB functions and subroutines is the events section. This is the part that mostly changes from file to file as it responds to the different inputs from the HTML forms.
 

 
     
  VB Scripts for COM Device's