ASI Library for the Arduino

This class is common to all ASI devices. These devices share a common command set and it is presented in the following methods. The class can be used stand alone but it is normally incorporated into a specific device class. When incorporated in this way the methods here are available for use.

Methods Inherited from Bserial

handshake(uint8_t rtsPin, uint8_t ctsPin)
putch(char c)
unsigned char puts(char *s)
unsigned char buffer()
char getch()

ASI(rxPin, txPin)

The constructor provides a connection to BSerial.


Initialises the connected devices by sending 3 carriage returns and inverting the output which is required for this serial interface. The device on the bus will not work properly without this method being called.

resetall(char *dev, char max)

This will reset all of the devices on the bus regardless of their address.

devices(char *dev, char max)

Returns a list of device addresses on the bus as a string. This can be very useful for checking what should be on there or be used in an automated system. The method requires a buffer to put the devices in, max is the size of the buffer. As an example if there are three devices on the bus with addresses a, k and p then the returned string would be “a>k>p>”

The above commands will work on all of the devices attached to the bus. The following commands require a device address as they refer to a particular device. So that more than one device can be referred, all the following commands require DEVadr which is a character representing the device address, i.e. ‘a’.

char wait(char *inp, char term, char max)

When a command is sent to the ASI device, in most cases the device will return with a prompt ‘>’. Because of this it is easy to tell when the ASI device is ready for another command. This method will wait for a particular character in the input stream (term) and return when it receives it. There is also a timeout of about 1 second if the character is never received. This version will return all of the characters received from sending the command to receiving the ‘term’. To safeguard the buffer max should be set to the size of the provided buffer. As an example to get the version of an ASI device the command is “aV\r”, assuming the device address is ‘a’. To capture this with the wait method:
wait(b, ‘>’, 5);

The buffer b will now have a string in it that represents the version.

char wait()

This is as above but will always wait for ‘>’ and it throws away any received bytes.

changeaddress(char DEVadr, char newadr)

Changes the device address. The change is stored in EEPROM so do not do this each time the software starts, it only needs doing once.

eepromwrite(char DEVadr, char addr, char *s)

Writes a string of bytes to the EEPROM, the string should be 0 terminated. This does mean that 0 cannot be written to the EEPROM. The command is primarily intended for text.

ackoff(char DEVadr)

Turns the ACK mechanism off – this is not recommended as without it this library will not work.

erroroff(char DEVadr)

Turns off error reporting. The library still works with this switched on.

eepromread(char DEVadr, char addr, char bytes, char *read, char max)

Reads the EEPROM at a given address for the specified number of bytes into a supplied buffer. Max is the size of the buffer that has been supplied.

deviceid(char DEVadr, char *id)

Returns the device ID, useful for automatically identifying which address belongs to which device. The value returned is a number. For example the BV4108 returns 4108. This is returned as a string in ‘id’. The size of the string buffer supplied should be at least 5 bytes.

macro(char DEVadr, char mon)

This turns on or off the macro which will be run at start up, see the datasheet for the device for more information about this. setting ‘mon’ to 1 will deactivate the macro, setting it to 0 will deactivate it.

reset(char DEVadr)

Resets the device

version(char *s)

Puts the firmware version as a sting in the supplied buffer. The size of the string buffer supplied should be at least 5 bytes.

Baud Rate - Example

The baud rate is simply a delay and for this software serial class there is no need to fix it at a standard rate. For whatever reason the baud rate on the Arduino and the target system may vary. If reliability is a problem then adjust the rate up or down. To help with this use this small program:

#include <BSerial.h>

#define rxPin 5
#define txPin 4

BSerial bs(rxPin, txPin);

void setup()  {

void loop() {
char b[10];
unsigned long j;
  for(j=8000;j<11000;j+=40) {
  while(1); // stop

Connect a terminal up to pins 4 and 5 in this case, set eh Baud rate 9600, run the program and watch the output. Initially rubbish should be displayed but then a series of numbers then rubbish again. To get the optimum Baud rate take the first and last number that was printed out okay and average it. In the example on this system this was:
(9100 + 10200) / 2 = 9650<

So the best baud rate would be 9650, so 9600 is well within the range. This is just testing the output. The input will follow closely but at higher baud rates only the output may work.

Simple Echo

 bs.puts("\nReady ");
 while(1) {
   if(c!=-1) bs.putch(c);

When connected to a terminal the above will echo back any character typed. getch() return -1 if there are no keys in the buffer. The buffer() methods could also be used instead to see the number of characters waiting.

ASI Example

To try this you will of course need an ASI device connected to pins 4 and 5 of the Arduino. Change the example if you wish to use other pins. See the [[ByVac] web site and relevant data sheets for more information about ASI devices.

The only method that will sow anything without becoming device specific is getting the addresses of the devices connected to the bus as follows:

#include <BSerial.h>
#include <ASI.h>

#define rxPin 5
#define txPin 4

ASI asi(rxPin, txPin);

void setup()  {
  Serial.begin(9600); // to show results from example

void loop() {
char b[20];
  Serial.print("\nDevices ");
  while(1); // stop

For this to work an ASI device has to be connected as above and also a terminal should be connected to the TX and RX (UART) pins. If two devices are connected with addresses a,b then the output is: Devices