Using VB

The following gives examples of setting up and the code required to use ASI devices with VB. The free version of VB is used and full source code is provided.

Resources: VB code for LCD ASI-LCD.zip
                  VB code for the keypad ASI-KEYPAD.zip
                  Check the datasheet's section and www.byvac.com for prices.

Set Up

For these examples a BV101 is going to be used, the reason for this is that it provides a power supply and also allows the use of multiple devices. The two devices used will be an ASI display and an ASI keypad. Connecting from the BV101 to an ASI device is a straight pin for pin connection thus:

connecting BV101 to LCD via wire connecting bv101 to lcd directly

The above shows a 20x4 line LCD display connected to a BV101 with a wire and directly.

Using VB with a 4 Line display

Download the VB code zip file and unzip to a directory, in the binRelease directory there will be a file called IASI.exe, run this file and you should get the following dialog box:

VB dialog box

  1. Enter the COM port of the BV101 by using the drop down
  2. Press the red closed button and it should turn green to show a connection
  3. Press the 'Connect-UART' button and after 'Wait..' is displayed it should display a>
  4. Now type some text and press send

VB dialogue populated

In the above case 'hello fred' should appear on the display. The reason for using the 'Connect-UART' is that we are using a BV101 that presents itself as a UART would to the LCD display device. If a direct connection to the RS232 com port were used then the 'Connect-232' would be used.

The Code

To look at the code it is best to have VB Express installed although it is possible to see the actual code without. The project file is called 'IASI-a.vbproj', double clicking on this should open up the project. I only intend to look at the ASI related code and most of this is in a module called 'IASI.vb'

Connect

vb code, connect

The first thing to do when connecting to an ASI device is to establish a mutual Baud rate, this is done by sending byte 13 (0x0d) which is generally known as carriage return (CR). Three is usually sufficient to do this. The subroutine will optionally also send a byte with the value of 4, this is done when using the 'Connect-UART' button. The last command sent to the ASI device is a byte with the value of 1. This will tell the ASI device to place its address on the bus, each device will do this in turn and this will take 780ms for a device with an address of 122 ('z'), hence the wait(80) which is in fact 800ms. NOTE that it is important to have a small delay after sending the invert command.

Sout

This writes a byte to the port followed by vbCR which is byte 13. This is important as it terminates the command and is a common mistake to either forget this or send LF+CR instead.

Handshaking

An important part of the code is the handshaking mechanism, as this must be done is software. The protocol is very simple, send a packet to the ASI device and wait for byte 62 (which is '>') to be returned. Ideally in case of errors we only want to wait a certain amount of time otherwise we could be stuck in a loop forever. The code that handles this is SendText:

SendText

vb code for send text

The serial port is set up to receive text in a global variable called textIn and this is handled on an event basis so all we see is the result in the global. The function of Sendtext is to send a packet to the ASI device and wait for a response. The response can be any length of bytes but will be terminated with '>'.

The 'while' loop allows the COM event to fill the 'textIn' global all the time looking for the '>' returned from the ASI device indicating that the command has completed. One hundred milliseconds is allowed for this as the timer is set to count in 10ms intervals. The user can check the returned result an error is indicated if nothing (an empty string) is returned.

Keypad Device BV4505

The keypad is used to illustrate receiving values from an ASI device, this particular device has a default address of 98 ('b') rather then the LCD default of 97 ('a') but the setup is exactly the same.

dialog of keypad connect

Here the button 'Get' uses the keypad commands 'b' to get the number of keys in the buffer and 'g' to get the actual key values. Prior to pressing this button, keys 1,5 and 9 were pressed.

vb code for get value

This time the function Getvalue is used instead of sendtext. The return value from send text, all being well, will contain some values ending with '>'. As the integer i points to the '>' character the value is extracted with mid$.