12 messages in net.java.dev.jna.usersRe: [jna-users] problem with useMemory()
FromSent OnAttachments
evgeni shafranMay 27, 2008 11:46 pm 
Paul LoyMay 28, 2008 2:04 am 
evgeni shafranMay 28, 2008 2:21 am 
Paul LoyMay 28, 2008 3:05 am 
Paul LoyMay 28, 2008 3:07 am 
evgeni shafranMay 28, 2008 3:36 am 
Paul LoyMay 28, 2008 3:40 am 
Paul LoyMay 28, 2008 3:44 am 
evgeni shafranMay 28, 2008 3:50 am 
Paul LoyMay 28, 2008 3:52 am 
Paul LoyMay 28, 2008 3:55 am 
evgeni shafranMay 28, 2008 3:57 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] problem with useMemory()Actions...
From:Paul Loy (kete@gmail.com)
Date:May 28, 2008 3:07:39 am
List:net.java.dev.jna.users

^^ sorry, it's up there isn't it...

The structure looks fine to me. Where are you getting the pointer from? It may be that your function call is incorrect.

On Wed, May 28, 2008 at 10:21 AM, evgeni shafran <yavj@gmail.com> wrote:

tnx, i works now, but it still return junk, i think it because i didnt build the structure right, my c structure is: *

typedef * *enum*

{

IDLE,

PREALARM,

ALARM,

ALERT,

TAPE

} State;

*

typedef * *struct*

{

*int* size;

*bool* valid;

*bool* active;

*bool* signal;

State state;

*int* last_write_index;

*int* last_read_index;

time_t last_image_time;

*int* last_event;

*int* action;

*int* brightness;

*int* hue;

*int* colour;

*int* contrast;

*int* alarm_x;

*int* alarm_y;

*char* control_state[256];

} SharedData;

and because i didnt know how to translate enum i translated it to int my java struc look like this: public class SharedData extends Structure { public int size; public boolean valid; public boolean active; public boolean signal; public int state; public int last_write_index; public int last_read_index; public int last_image_time; public int last_event; public int action; public int brightness; public int hue; public int colour; public int contrast; public int alarm_x; public int alarm_y; public byte[] control_state= new byte[256]; @Override protected void useMemory(Pointer m) { super.useMemory(m); super.read(); } }

please tell me what i need to fix here. tnx in advense

On Wed, May 28, 2008 at 12:04 PM, Paul Loy <kete@gmail.com> wrote:

Don't you have to then call super.read(); ?

On Wed, May 28, 2008 at 7:46 AM, evgeni shafran <yavj@gmail.com> wrote:

hey, i trying to get structure from shared memory. the code compiles but it dont actualy reads from memory

import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.Structure;; /** Simple example of native library declaration and usage. */ public class test { static Pointer sharedMemPointer ; static SharedData sd; public interface CLibrary extends Library{ CLibrary INSTANCE = (CLibrary) Native.loadLibrary( "c", CLibrary.class);

void printf(String format, Object... args); Pointer shmat(int shmid, final Pointer shmaddr, int shmflg); int shmget(int key, int size, int shmflg);

}

public static void main(String[] args) { ConnectToMemmory();

} public static void ConnectToMemmory() { sd= new SharedData(); int memId = CLibrary.INSTANCE.shmget((0x7a6d2000&0xffffff00)|28,36497932 , 00001000|0777); sharedMemPointer = CLibrary.INSTANCE.shmat(memId, null, 0); sd.useMemory(sharedMemPointer); System.out.println(sd.toString()); }

public static byte[] getByteRGBbyIndex(int indexID) { int arraySize=352*288*3;// shuld be taken from db return sharedMemPointer.getByteArray(arraySize*indexID, arraySize); } }

import com.sun.jna.Pointer; public class SharedData extends Structure { enum State { IDLE, PREALARM, ALARM, ALERT, TAPE } public int size; public boolean valid; public boolean active; public boolean signal; public int state; public int last_write_index; public int last_read_index; public int last_image_time; public int last_event; public int action; public int brightness; public int hue; public int colour; public int contrast; public int alarm_x; public int alarm_y; public byte[] control_state= new byte[256]; @Override protected void useMemory(Pointer m) { super.useMemory(m); } @Override protected void useMemory(Pointer m, int offset) { super.useMemory(m, offset); } }

why dont it reads from memory?

--------------------------------------------- Paul Loy pa@keteracel.com http://www.keteracel.com/paul