B4J Question Trying to read CPU info on RPI

Gary Miyakawa

Active Member
Licensed User
Longtime User
Ok, I'm trying to read the CPU Serial number (RPI) with this code but keep getting "Invalid Argument" when it trys to perform the ReadList. I've tried all the "reads" and get the same thing.

B4X:
sub ReadCPUInfo As String
    Dim list1 As List
    list1 = File.ReadList("/proc", "cpuinfo")
End Sub

This code works fine reading the CPU Temp.

Any ideas/suggestions would be greatfully appreciated !

Gary M
 

Gary Miyakawa

Active Member
Licensed User
Longtime User
This is what I get from the logs.

Waiting for debugger to connect...
Program started.

Error occurred on line: 40 (Main)
java.io.IOException: Invalid argument
at java.io.FileInputStream.available(Native Method)
at java.io.BufferedInputStream.read(BufferedInputStream.java:353)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at anywheresoftware.b4a.objects.streams.File$TextReaderWrapper.ReadLine(File.java:563)
at anywheresoftware.b4a.objects.streams.File$TextReaderWrapper.ReadList(File.java:604)
at anywheresoftware.b4a.objects.streams.File.ReadList(File.java:244)
at b4j.example.main._readcpuinfo(main.java:136)
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:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
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:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Looks like it doesn't behave exactly like a file stream.

Before switching to jShell, try this:
B4X:
Dim in As InputStream
Dim jo As JavaObject
in = jo.InitializeNewInstance("java.io.FileInputStream", Array(File.Combine("/proc", "cpuinfo"))) 'create an unbuffered stream
Dim out As OutputStream
out.InitializeToBytesArray(0)
File.Copy2(in, out)
Dim output() As Byte = out.ToBytesArray
Log(BytesToString(output, 0, output.Length, "ascii"))
 
Upvote 0

Gary Miyakawa

Active Member
Licensed User
Longtime User
Erel,

As usual, you have the right answer right off the bat ! It works perfectly.

What was the problem using my method ?

Thank you !

Gary Miyakawa
 
Upvote 0
Top