Hi,
I am trying to use a RTC DS1340 module on my Raspberry. As a starting point I use the code Erel supplied with the jPi4J library in post 3.
I checked using Terminal commands that the device is working correctly. The hwclock -r command gives the correct date and time.
Up till now the program looks as follows:
The libraries used are:
JavaObject
jCore
jPi4J
jSerial
When I run the progtram I get the following log:
Program started.
Program started
Error occurred on line: 51 (Main)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at b4j.example.main._write(main.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:591)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:224)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMetho
dAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.io.IOException: Error writing to /dev/i2c-1 at address 0x44. Got -20001.
at com.pi4j.io.i2c.impl.I2CDeviceImpl.write(I2CDeviceImpl.java:79)
... 21 more
Some questions:
1) Does somebody know what I am doing wrong?
2) How can I check whether GetBus and GetDevice are successfull?
3) Were can I find what the various methods really do?
I know that there are other means to configure this device. But this device is only used for testing purposes to understand i2c, as the final i2c device, a voltage/ current meter, has not yet arrived.
Harry
I am trying to use a RTC DS1340 module on my Raspberry. As a starting point I use the code Erel supplied with the jPi4J library in post 3.
I checked using Terminal commands that the device is working correctly. The hwclock -r command gives the correct date and time.
Up till now the program looks as follows:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim bus1 As JavaObject = GetBus(1)
Dim device1 As JavaObject = GetDevice(bus1, 68)
Dim binair As Byte
Dim bcd As Byte
Dim data() As Byte
data=Array As Byte(0x31,0x32,0x33,0x34,0x35,0x36,0x37)
Dim startpoint As Int
Dim number As Int
End Sub
Sub AppStart (Args() As String)
Log("Program started")
startpoint=0
number=7
Write(device1, 0) 'used to set the register to read from
Read2(device1,data,startpoint,number)
StartMessageLoop
End Sub
'Bus methods
Sub GetBus(BusNumber As Int) As JavaObject
Dim factory As JavaObject
Return factory.InitializeStatic("com.pi4j.io.i2c.I2CFactory").RunMethodJO("getInstance", Array As Object(BusNumber))
End Sub
Sub GetDevice(bus As JavaObject, Address As Int) As JavaObject
Return bus1.RunMethodJO("getDevice", Array As Object(Address))
End Sub
Sub CloseBus (bus As JavaObject)
bus1.RunMethod("close", Null)
End Sub
'Device methods
Sub Read(device As JavaObject) As Int
Return device1.RunMethod("read", Null)
End Sub
Sub Read2 (device As JavaObject, Buffer() As Byte, Offset As Int, Size As Int) As Int
Return device1.RunMethod("read", Array As Object(Buffer, Offset, Size))
End Sub
Sub Write(device As JavaObject, b As Byte)
device1.RunMethod("write", Array As Object(b))
End Sub
Sub Write2(device As JavaObject, Buffer() As Byte, Offset As Int, Size As Int)
device1.RunMethod("write", Array As Object(Buffer, Offset, Size))
End Sub
Sub bin2bcd(val As Byte)
bcd=val+6*(val/10)
End Sub
Sub bcd2bin(val As Byte)
binair=val-6*(Bit.UnsignedShiftRight(val,4))
End Sub
The libraries used are:
JavaObject
jCore
jPi4J
jSerial
When I run the progtram I get the following log:
Program started.
Program started
Error occurred on line: 51 (Main)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at b4j.example.main._write(main.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:591)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:224)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMetho
dAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.io.IOException: Error writing to /dev/i2c-1 at address 0x44. Got -20001.
at com.pi4j.io.i2c.impl.I2CDeviceImpl.write(I2CDeviceImpl.java:79)
... 21 more
Some questions:
1) Does somebody know what I am doing wrong?
2) How can I check whether GetBus and GetDevice are successfull?
3) Were can I find what the various methods really do?
I know that there are other means to configure this device. But this device is only used for testing purposes to understand i2c, as the final i2c device, a voltage/ current meter, has not yet arrived.
Harry