Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java ME - Raspberry - I2C - Combined message

HarrySattFeb 3 2016 — edited Feb 3 2016

Hi there

I am trying to get the RPi 2 working with combined messages. for that I use

public class I2CCombinedMessage extends java.lang.Object

The I2CCombinedMessage

class allows for constructing a combined message. A combined message may be constituted of at least two reads and/or writes to one or more I2C slaves. A combined message starts with a START bit and ends with a STOP bit. But each of read and write messages constituting the combined message following the very first of these messages starts with a REPEATED START bit (one that is not preceded by a STOP bit).

With this codelet I am able to send the commands with this command but there are still STOP bits send. This should not happen. From bash on the RPi this REPEATED START works fine.

Someone an idea?

regards, Harald.

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package i2c.test001;

import javax.microedition.midlet.MIDlet;

import java.io.IOException;

import java.nio.ByteBuffer;

import jdk.dio.DeviceManager;

import jdk.dio.i2cbus.I2CDevice;

import jdk.dio.i2cbus.I2CDeviceConfig;

import jdk.dio.i2cbus.I2CCombinedMessage;

/**

*

* @author hsattm72

*/

public class I2CTest001 extends MIDlet {

        private final int BUS_ID = 1;

        private final int CFG_ADDRESS = 0x1D;

        private final int ADDRESS_SIZE = 7;

        private final int CLOCK_FREQUENCY = 100000;

       

    // register addresses for MMA8452Q

        private final int WHO_AM_I = 0x0D;

       

    @Override

    public void startApp() {

        System.out.println("*********************");

        System.out.println("* I2C Sample start  *");       

        System.out.println("*********************");   

   

        I2CDeviceConfig config = new I2CDeviceConfig.Builder()

                .setControllerNumber(BUS_ID)

                .setAddress(CFG_ADDRESS, ADDRESS_SIZE)

                .setClockFrequency(CLOCK_FREQUENCY)

                .setInputBufferSize(20)

                .setOutputBufferSize(20)

                .build();

        I2CDevice i2c = null;

       

        try {

            i2c = DeviceManager.open(config);

            // read the WHO_AM_I register

            ByteBuffer temp = ByteBuffer.allocateDirect(1);

            byte[] cmd = new byte[1];

            cmd[0] = 0x0d;

            I2CCombinedMessage msg = i2c.getBus().createCombinedMessage();

            msg.appendWrite(i2c, ByteBuffer.wrap(cmd) );

            msg.appendRead(i2c, temp);

            int[] transfer = msg.transfer();

           

            System.out.println("ID = " + transfer[0]);           

        } catch (Exception ex) {

            System.out.println(ex.toString());

        }

        finally {

            // close the device

            if( i2c != null) {

                try {

                    i2c.close();

                } catch( IOException ex) {

                    System.out.println(ex.toString());                   

                }

            }

        }

    }

   

    @Override

    public void destroyApp(boolean unconditional) {

        System.out.println("*********************");

        System.out.println("*  I2C Sample end   *");       

        System.out.println("*********************");  

    }

}

Comments

Gaz in Oz

By not showing all your code, it is difficult to say what you have done wrong. Post a VERY SIMPLE and SHORT complete example that shows what you are trying to do and how you are trying to do it...

The actual Oracle error ORA-00904 suggests that the query sqlalchemy is throwing to the Oracle database contains a non-existent column name, not an issue with a date or timestamp.

Add debug your code and output to screen the actual query sqlalchemy is trying to send to the database.

As a general tip, use sqlplus to test out "stuff". If you don't already have it on your machine, you can download Oracle instantclient and tools from here:

https://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html

With basic or basic-light and sqlplus installed you can run the above sqlalchemy  debug output query in an Oracle client, connected to the database with the same credentials, and see exactly what line and where the error is occurring. Yo can also "describe" the table you are trying to insert into, or select from, or what ever.

Here's a very simple example sqlplus session with a simple SELECT query failing, to give you an idea of how you would start to debug your above error in sqlplus:

$ sqlplus gaz/gaz@host:port/service_name

...

SQL> select col1,

  2         dummy

  3  from   dual;

select col1,

       *

ERROR at line 1:

ORA-00904: "COL1": invalid identifier

SQL> describe dual

Name                          Null?    Type

----------------------------- -------- --------------------

DUMMY                                  VARCHAR2(1)

SQL> l

  1  select col1,

  2         dummy

  3* from   dual

SQL> 1

  1* select col1,

SQL> c/col1,//

  1* select

SQL> l

  1  select

  2         dummy

  3* from   dual

SQL> /

D

-

X

1 row selected.

SQL>

1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 2 2016
Added on Feb 3 2016
0 comments
2,562 views