SV3 is serial version 3 and has some advantages in that it allows many devices over one serial bus, is compatible with I2C and just like I2C the devices all have an address and can be 'discovered'. sv3 applies to both serial and i2c.
Nearly all of the Pichips are controlled in some way by the SV3. This text contains a description of the sv3 class for Python and the class itself.There is just one file required for RPi and two if Windows I2C is to be used. There are in the downloads section. The two files are:
- bv4221_i2c.py # this will only be needed for Windows I2C
Before the sv3 class can be used a 'bus' has to be determined. This can be an I2C bus, 0 or 1 in the PRi examples or it can be a serial bus as referenced by a COM port. The bus can be used with many instances of the sv3 class as the class requires some kind of medium to communicate through.
>>> from sv3A import sv3Bus
There are 4 possible ways to obtain a bus handle:
 bus = getBus(1,'COM14',9600)
 bus = getBus(0,'COM21','115200')
In example  this is simply a serial device connected to the serial com port. The '1' as the first parameter indicates serial. In example  the '0' as the first parameter is I2C. As Windows does not have a native I2C then a BV4221_V2 is used. This requires some setting up and the Baud rate of that device is given as the third parameter.
 bus = getBus(1,'/dev/ttyAMA0',9600)
 bus = getBus(0,'1','')
In example  this is simply the serial port of the RPi, the first parameter '1' indicates serial as opposed to I2C. In example  the first parameter '0' indicates I2C and the second parameter '1' is I2C bus 1, older RPi's used I2C bus 0. The third parameter is not required ans so an empty sting is supplied.
This is the main function to obtain information from the attached device. SDE is serial Data Exchange and it behaves a bit like an SPI command in that data is fed in and data comes out. Mostly the device class will make use of this. As an example to obtain the device ID on a serial bus then the following is used.
s = bus.sde("'aD\r')
This is the same as typing 'aD<ent>' at a terminal, the result will be returned from the device with the address 'a'. This method would normally be called by another class rather than be used directly.
- bus.detect() # returns a list of addresses of all of the devices on the bus
- bus.ID(address) # returns the device id for the given address, 0 on not found
- bus.FW(address) # returns the firmware revision as a list [major,minor]
- bus.list(address) # returns a list comprising [adr,id,fw] or  if address does not exist
- bus.check(address) # returns 1 if address is on bus otherwise 0
- bus.close() # applicable to serial, closes com port
- bus.version() # returns version number of sv3A file
SV3 ClassThe class is initialised with the bus as created by sv3Bus (above) and the address of the device.
sv3 = sv3A.sv3(bus,'h') # example, bus is obtained from above
The sv3 class though would normally be a parent of a device class and so would more likely be initialised thus:
device = p011A.p011(bus,'h')
- sv3.eeWrite(adr,data) # write a single byte (data) to the given EEPROM address (0 to 255)
- sv3.eeRead(start,length) # reads and returns a list starting at EEPROM address start for length number of bytes
- sv3.ID() # returns the device id as an integer
- sv3.FW() # returns the firmware as a list [major, minor] of type string
- sv3.reset() # software reset