Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Multiple i2C Devices with VB


  • Please log in to reply
3 replies to this topic

#1 mimtarsden

mimtarsden

    New Member

  • Members
  • Pip
  • 8 posts

Posted 07 February 2012 - 11:49 PM

Hi All,

Has anyone successfully managed to get more than one I2C device communicating on the same bus with VB?

I thought i could just attach them in parallel and they would just work, however it appears that I2Cdevice actually means I2CBus and you can instantiate only once or you get an exception.

I found some C# code here on the forums (http://forums.netdui..._4156#entry4156) and translated it to VB, but am being frustrated by a couple of errors I can't seem to work out.

Part of the code requires a SyncLock

Public Class I2CBus
        Implements IDisposable
        Private Shared _instance As I2CBus = Nothing
        Private Shared ReadOnly LockObject As Object

        Public Shared Function GetInstance() As I2CBus
            SyncLock LockObject
                If _instance Is Nothing Then
                    _instance = New I2CBus()
                End If
                Return _instance
            End SyncLock
        End Function


However, I get an error, though I can't see anything wrong with the code;

"Error 1 Requested operation is not available because the runtime library function 'Microsoft.VisualBasic.CompilerServices.ObjectFlowControl.CheckForSyncLockOnValueType' is not defined."

So I created a Dummy class called 'Object1' and used that for the lock object and the error goes away, but then when I try and compile I get;

An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll

At the point where the new I2C device instance is created...

Public Sub New()
            Me._slaveDevice = New I2CDevice(New I2CDevice.Configuration(0, 0))
        End Sub

I think it may be my workaround of creating a dummy class as an object but i'm not sure

Any Help will be graciously received.

#2 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 08 February 2012 - 01:48 PM

Hi, I don't know if this is any use but I have two accelerometers connected using the Love electronics libs written in c#. What I did was to compile the resource lib into a dll and reference it in my vb project. this allows multiple I2C devices connected at the same time using the SharedI2CDevice method. The source is available from Love electronics. If all that fails then attached is my compilation Attached File  LoveElectronics.Resources.zip   38.76KB   37 downloads of their dll for you to use. Cheers Pete.
I was going to change the world, then I discovered Netduino.
The world will have to wait.

#3 mimtarsden

mimtarsden

    New Member

  • Members
  • Pip
  • 8 posts

Posted 08 February 2012 - 11:38 PM

Pete, Cheers for that it was just what I was looking for. I had to convert the source to VB as I needed to write an array and the .dll would only allow a single byte to be written at a time. It works perfectly Much appreciated! Thanks.

#4 rhamer

rhamer

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationMelbourne Australia

Posted 29 February 2012 - 10:49 PM

Could either of you guys post some code with the LoveElectronics DLL as compiled by BainesBunch. I'm having a brain fade and cant get the syntax right. So far I have added a reference to the DLL, Imported LoveElectronics.Resources, but cant seem to get any further. Cheers Rohan




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.