I2c need help

Hellocould anyone help me with this?I have 3 classes I2cDriver, I2cHardware, I2cTerminal. I have to write a class with method which should take a computer temperature, and draw a curve of this temperature and time.
[235 byte] By [Makaulea] at [2007-11-27 6:07:33]
# 1
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#drawArc(int,%20int,%20int,%20int,%20int,%20int)
suparenoa at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 2
i want to know how to get temperature?
Makaulea at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 3
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
CeciNEstPasUnProgrammeura at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 4
but i don't need to use c++
Makaulea at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 5

> Hello

> could anyone help me with this?

>

> I have 3 classes I2cDriver, I2cHardware, I2cTerminal.

> I have to write a class with method which should take

> a computer temperature, and draw a curve of this

> temperature and time.

Can I assume these I2C classes are already written?

If so its a fair asumption that they can be used to access parameters in an I2C device.

However I can only assume so much because my telepathic powers are being blocked by Charles Xavier in order to prevent me from ruling you puny mortals in this dimension and so can get no further info on the classes I2cDriver, I2cHardware, I2cTerminal.

ScarletPimpernela at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 6

[nobr]I2cDriver

public class I2cDriver {

/**********************************************************************/

/*ATTRIBUTES*/

/**********************************************************************/

private static final int TEMPO = 0;

private I2cHardware ihw;

/**********************************************************************/

/*CONSTRUCTORS*/

/**********************************************************************/

public I2cDriver(I2cHardware ihw)

{

this.ihw = ihw;

}

/**********************************************************************/

/*METHODES*/

/**********************************************************************/

// monter SDA

private void sda_h()

{

ihw.sda_h();

}

private void sda_l()

{

ihw.sda_l();

}

private void scl_h()

{

ihw.scl_h();

}

private void scl_l()

{

ihw.scl_l();

}

private boolean read_sda()

{

return ihw.read_sda();

}

private boolean read_scl() // n'est utile que pour tester si le bus est libre

{

return ihw.read_scl();

}

private void startI2c() throws Exception

{

delay(TEMPO);

sda_h();

delay(TEMPO);

scl_h();

delay(TEMPO);

int countdown = 10;

while ( !read_sda() || !read_scl()) {

delay(100);

countdown--;

if (countdown == 0)

throw new Exception("Echec de la prise de controle du bus."); //Failure of the takeover of the bus.

}

delay(TEMPO);

sda_l();

delay(TEMPO);

scl_l();

delay(TEMPO);

sda_h();

}

private void stopI2c() throws Exception

{

delay(TEMPO);

sda_l();

delay(TEMPO);

scl_h();

delay(TEMPO);

sda_h();

delay(TEMPO);

}

private void clock() throws Exception

{

delay(TEMPO);

scl_l();

delay(TEMPO);

scl_h();

delay(TEMPO);

scl_h();

delay(TEMPO);

scl_h();

delay(TEMPO);

scl_l();

}

private boolean write_octet(int o) throws Exception

{

int result;

scl_l();

for(int cpt=7; cpt>=0 ; cpt--)

{

result = o & (1<<cpt); // (><<cpt)?

if(result!=0)

sda_h();

else

sda_l();

clock();

}

return getAck();

}

private int read_octet()

{

int result=0;

for(int cpt=0; cpt<8 ; cpt++)

{

scl_l();

delay(TEMPO);

scl_h();

delay(TEMPO);

result <<= 1;

if(read_sda())

result++;

}

return 255-result;

}

private boolean getAck() throws Exception

{

boolean etat = false;

scl_l();

delay(TEMPO);

sda_h();

delay(TEMPO);

scl_h();

delay(TEMPO);

scl_h();

delay(TEMPO);

etat = read_sda();

scl_l();

delay(TEMPO);

return !etat;

}

private void giveAck() throws Exception

{

sda_l();

clock();

sda_h();

}

private void giveNack() throws Exception

{

sda_h();

delay(TEMPO);

scl_h();

delay(TEMPO);

scl_l();

delay(TEMPO);

sda_h();

}

private void delay(int nsec)

{

try

{

Thread.sleep (0,nsec);

}

catch (InterruptedException e)

{

}

}

public synchronized void init()

{

sda_h();

scl_h();

}

public synchronized int read(int add) throws Exception

{

int vec[] = readOctets(1,add);

return vec[0];

}

/**

* Cette m閠hode permet de lire une suite d'octets sur la carte voulue.

* <br>

* @param octets Vecteur d'octets qui stockera le r閟ultat.

* @param add Adresse de la carte utilis閑.

* @see I2cDriver#read(int add)

* @throws I2cException Si la carte ne se reconna顃 pas.

*/

public synchronized int[] readOctets(int n, int add) throws Exception

{

int octets[]= new int[n];

boolean ok = false;

while (!ok){

try{

startI2c();

delay(TEMPO);

// Bit 0 = 1 (LECTURE)

add |=1;

if (!write_octet(add))

{

stopI2c();

throw new Exception("readOctets : address error while reading.");

}

octets[0]=read_octet();

for(int cpt=1; cpt<octets.length; cpt++)

{

giveAck();

octets[cpt]=read_octet();

}

giveNack();

stopI2c();

ok = true;

}catch(Exception e){}

}

return octets;

}

public synchronized void write(int valeur, int add) throws Exception

{

int vec[] = new int[1];

vec[0]=valeur;

writeOctets(vec, add);

}

public synchronized void writeOctetsSansStop(int[] octets, int add) throws Exception

{

boolean ok = false;

while (!ok){

try{

startI2c();

delay(TEMPO);

//Bit 0 = 0 (ECRITURE)

add &= 0xfe;

if (!write_octet(add))

{

stopI2c();

throw new Exception("WriteOctets : address error while writing.");

}

for(int cpt=0; cpt><octets.length; cpt++)

{

if (!write_octet(octets[cpt]))

{

stopI2c();

throw new Exception("WriteOctets : write error.");

}

}

//stopI2c();

ok = true;

}catch(Exception e){}

}

}

public synchronized int[] writeAndReadOctet(int octet, int add) throws

Exception

{

int vect[] = new int[1];

vect[0] = 255-octet;

writeOctetsSansStop(vect, add);

int[] result = readOctets(1, add);

return result;

}

public synchronized void writeOctets(int[] octets, int add) throws Exception

{

boolean ok = false;

while (!ok){

try{

startI2c();

delay(TEMPO);

//Bit 0 = 0 (ECRITURE)

add &= 0xfe;

if (!write_octet(add))

{

stopI2c();

throw new Exception("WriteOctets : address error while writing.");

}

for(int cpt=0; cpt><octets.length; cpt++)

{

if (!write_octet(octets[cpt]))

{

stopI2c();

throw new Exception("WriteOctets : write error.");

}

}

stopI2c();

ok = true;

}catch(Exception e){}

}

}

public String getVersion(){

return ("0.0.1");

}

}

I2cHardware

import java.util.*;

import javax.comm.*;

/**

* La classe I2cHardware permet l'impl閙entation du protocole I睠 gr鈉e au port s閞ie.

* elle commande l'interface electronique entre le port s閞ie et le bus i2c

* elle simule l'existance d'un bus i2c sur l'ordinateur ?l'aide du port s閞ie.

*/

public class I2cHardware {

private static CommPortIdentifier portId;

private static Enumeration portList;

private SerialPort serialPort = null;

public I2cHardware(String s) throws Exception {

System.out.println("starting I2cHardware...");

portList = CommPortIdentifier.getPortIdentifiers();

portId = null;

while (portList.hasMoreElements() && serialPort == null) {

portId = (CommPortIdentifier) portList.nextElement();

System.out.println("****"+ portId.getName());

if (s.indexOf(portId.getName())!=-1){

try

{

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)

{

serialPort = (SerialPort) portId.open("Temperature", 2000);

serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

serialPort.disableReceiveThreshold();

serialPort.disableReceiveTimeout();

}

}

catch (PortInUseException pe)

{

throw new Exception("Port " + s + " is already used by " + pe.currentOwner);

}

catch (Exception e)

{

System.out.println("initialisation of i2c Driver failed");

e.printStackTrace();

portId = null;

}

}

}//while

if (serialPort == null)

System.out.println("Port not found");

else System.out.println("driver i2c initialised on " + portId.getName());

}//constructor

/* cablagesda-out = RTS, scl-out = DTR, sda-in = CTS, scl-in = DSR */

// SDA up

public synchronized void sda_h()

{

serialPort.setRTS(true);

}

// SDA down

public synchronized void sda_l()

{

serialPort.setRTS(false);

}

//SCL up

public synchronized void scl_h()

{

serialPort.setDTR(true);

}

//SCL down

public synchronized void scl_l()

{

serialPort.setDTR(false);

}

public synchronized boolean read_sda()

{

return serialPort.isCTS();

}

public synchronized boolean read_scl() // only used to test if the bus is free

{

return serialPort.isDSR();

}

}

I2cTerminal

public class I2cTerminal {

private I2cDriver i2cDriver;

private int adresseCarte;

public I2cTerminal(I2cDriver driver, int adr)

{

adresseCarte = adr;

i2cDriver = driver;

}

public void envoyerOctet(int octet) throws Exception

{

i2cDriver.write(octet,adresseCarte);

}

public int recevoirOctet() throws Exception

{

return i2cDriver.read(adresseCarte);

}

public int[] envoyerEtRecevoirOctet(int octet) throws Exception

{

return i2cDriver.writeAndReadOctet(octet, adresseCarte);

}

public void envoyerOctets(int octet[]) throws Exception

{

for (int i=0; i><octet.length; i++) octet[i] = (255-octet[i]);

i2cDriver.writeOctets(octet, adresseCarte);

}

public int[] recevoirOctets(int n) throws Exception

{

int[] result = i2cDriver.readOctets(n, adresseCarte);

return result;

}

public String getI2cDriverVersion()

{

return i2cDriver.getVersion();

}

}

i have to write one more java class called DS75.java in this file must by that method which get computer temperature.>[/nobr]

Makaulea at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 7
I can now see from these classes that the I2C interface is being built using the handshake lines of a COM port.You do seem to have this problem with volunteering relevant information.Am I now to assume from the name of the class that you are using a Dallas DS75 temperature
ScarletPimpernela at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 8
so could you help me?
Makaulea at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 9
> so could you help me?I probably could if you were not so unwilling to specify the problem sufficiently.
ScarletPimpernela at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 10
please help me! i really need help.
Makaulea at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 11
while (true) {us.print("WTF is the problem? We aren't psychic!");makaule.print("Please help me!");}
hunter9000a at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 12
> please help me! i really need help.I asked wether you were using the DS75 or not, you still have not repliedYou are beyond help!
ScarletPimpernela at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 13
> > please help me! i really need help.> > I asked wether you were using the DS75 or not, you> still have not replied> > You are beyond help!But Magneto! The keys to the DS75 could help you put an end to Cerebro once and for
cotton.ma at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 14
yes i am using DS75.
Makaulea at 2007-7-12 16:58:42 > top of Java-index,Java Essentials,Java Programming...
# 15
I have to write a method which would took a temperature of computer and using this temperature and time then the value was taked draw a graph (curve).
Makaulea at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 16
i have to use these classes
Makaulea at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 17
> i have to use these classesOkay. What exactly do you need help with? Specifically?
cotton.ma at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 18
how to write that method
Makaulea at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 19
> how to write that methodWhich method?
cotton.ma at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 20
> > how to write that method> > Which method?The one that does all the thing.
ScarletPimpernela at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 21

> > > how to write that method

> >

> > Which method?

>

> The one that does all the thing.

Don't you think this should be in more than just one method? *

So which part of that for-now-one method? The communication part or the drawing part?

* - yes I know but it seems like this will be more productive

cotton.ma at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 22
communication part
Makaulea at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 23
> communication partWell I would suggest you find a manual or other such API documentation as might exist for the DS75. Have you found such a thing?
cotton.ma at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 24
no. i have only DS75 Digital Thermometer and Thermostat
Makaulea at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 25
> no. i have only DS75 Digital Thermometer and> ThermostatWell best to get googling for documentation then.
cotton.ma at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 26
Throws in a frikkin bone http://datasheets.maxim-ic.com/en/ds/DS75.pdf
ScarletPimpernela at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 27
i have not very much time :(
Makaulea at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 28
> i have not very much time :(That's bad.
cotton.ma at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 29
> i have not very much time :(I'm not surprized if it takes an hour and a half to confirm a question regarding what IC you are using.
ScarletPimpernela at 2007-7-21 21:42:54 > top of Java-index,Java Essentials,Java Programming...
# 30
>Throws in a frikkin bone> http://datasheets.maxim-ic.com/en/ds/DS75.pdfI already have this but i dont understand how to write
Makaulea at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 31
> >Throws in a frikkin bone> > > http://datasheets.maxim-ic.com/en/ds/DS75.pdf> > I already have this but i dont understand how to writeClear the read/write bit in the address byte
ScarletPimpernela at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 32
i dont understand
Makaulea at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 33
> i dont understandWhat dont you understand?, how to write to the IIc bus or how to write to a register in the DS75?anticipating another vague answer...
ScarletPimpernela at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 34
both. i am not very good in java but i have to create this program
Makaulea at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 35
You need to go back to whoever assigned this to you and ask for guidance, you dont understand Java, I2C or the DS75 so you dont have a good starting point.
ScarletPimpernela at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 36

> You need to go back to whoever assigned this to you

> and ask for guidance, you dont understand Java, I2C

> or the DS75 so you dont have a good starting point.

Or here's another idea. What if? He wrote a method which would look at the temperature of the computer and using this temperature and time draw a graph (curve)?

cotton.ma at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 37
This is that i want cutton.m
Makaulea at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 38
so nobody can't help?
Makaulea at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 39

> so nobody can't help?

By now you should know that no one will write this code for you. That is cheating and will not help you to learn to code (which supposedly is why you are taking a programming course in the first place). I suggest you study the info in the link supplied and try to understand as much as possible. I also recommend that you take breaks from this every now and then to write some code. Write it as if you already know how to get the temp of the computer, and you can always plug this functionality in later when / if you do figure this out. THEN if you have specific questions about your code or specific questions about the chip specs, ask them.

If you keep asking for general nonspecific help, I'm afraid that all you'll be doing is spinning your wheels and providing entertainment for those of us reading this board. Now go do some work, and good luck.

/P

petes1234a at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...
# 40

There is a DS75 class framework

public class DS75 extends I2cTerminal {

public DS75(I2cDriver driver, int adr){

super(driver, adr);

}

public double getTemp(){

//some code

i2cDriver.writeAndReadOctet(octet, adr);

}

public static void main(String[] args){

DS75 ds75 = new DS75(new I2cDriver(new I2cHardware("COM1")), 0x90);

System.out.println(ds75.getTemp());

System.out.println(i2cDriver.getVersion());

}

}

then i want to compile it com[iler always showing errors. what is wrong?

Makaulea at 2007-7-21 21:42:59 > top of Java-index,Java Essentials,Java Programming...