Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden. Du solltest ein Upgrade durchführen oder ein alternativer Browser verwenden.
ich habe von einem Messgerät eine Header Datei mit diesem Auszug:
Java:
typedef struct
{
uint32_t bufferId;
uint32_t frameIndex; /* stream position of first frame in buffer */
uint32_t numberOfSources;
uint32_t numberOfFrames;
uint32_t flags; /* OR'ed stream buffer flags */
} SA_SI_DataBufferInfo;
typedef struct
{
SA_SI_DataBufferInfo info;
uint8_t **data; // pointer to pointer-array(s): data --> [ptr1,...,ptrN],
// where ptr<i> --> uint8[]
} SA_SI_DataBuffer;
SA_SI_AcquireBuffer(SA_SI_Handle handle,unsigned int bufferId,const SA_SI_DataBuffer **buffer);
Welchen Java Datentyp nehme ich jetzt für den Buffer, bzw. die data Variable in der struct?
Ich habe es jetzt schon mit PointerByReference und DataBuffer probiert, aber entweder bin ich zu doof, das richtig einzusetzen oder es sind nicht die richtigen Datentypen. Vielleicht kann mir da jemand weiter helfen?
So, ich habe das .h File mit dem jnaerator übersetzt, jedoch hänge ich tatsächlich daran fest das übersetzte so anzuwenden.
Also, ich habe u.a. folgende Klassen (von jnaerator erzeugt):
Java:
public class SA_SI_DataBuffer extends Structure<SA_SI_DataBuffer, SA_SI_DataBuffer.ByValue, SA_SI_DataBuffer.ByReference > {
/** C type : SA_SI_DataBufferInfo */
public SA_SI_DataBufferInfo info;
/**
* pointer to pointer-array(s): data --> [ptr1,...,ptrN],<br>
* C type : uint8_t**
*/
public PointerByReference data;
public SA_SI_DataBuffer() {
//super();
}
protected List<? > getFieldOrder() {
return Arrays.asList("info", "data");
}
/**
* @param info C type : SA_SI_DataBufferInfo<br>
* @param data pointer to pointer-array(s): data --> [ptr1,...,ptrN],<br>
* C type : uint8_t**
*/
public SA_SI_DataBuffer(SA_SI_DataBufferInfo info, PointerByReference data) {
super();
this.info = info;
this.data = data;
}
public SA_SI_DataBuffer(Pointer peer) {
super();
}
protected ByReference newByReference() { return new ByReference(); }
protected ByValue newByValue() { return new ByValue(); }
protected SA_SI_DataBuffer newInstance() { return new SA_SI_DataBuffer(); }
public static SA_SI_DataBuffer[] newArray(int arrayLength) {
return Structure.newArray(SA_SI_DataBuffer.class, arrayLength);
}
public static class ByReference extends SA_SI_DataBuffer implements Structure.ByReference {
public ByReference(){}
public ByReference(Pointer p) {super(p); read(); }
};
public static class ByValue extends SA_SI_DataBuffer implements Structure.ByValue {
};
}
Java:
public class SA_SI_Event extends Structure<SA_SI_Event, SA_SI_Event.ByValue, SA_SI_Event.ByReference > {
public int type;
/** C type : field1_union */
public field1_union field1;
/** <i>native declaration : line 230</i> */
public static class field1_union extends Union<field1_union, field1_union.ByValue, field1_union.ByReference > {
/** error code if the event type is an error event */
public int error;
/** id of a buffer if the event has a buffer parameter */
public int bufferId;
/** an event parameter sent from the device (meaning depends on type) */
public int devEventParameter;
/** C type : uint8_t[24] */
public byte[] unused = new byte[24];
public field1_union() {
super();
}
/** @param unused C type : uint8_t[24] */
public field1_union(byte unused[]) {
super();
if ((unused.length != this.unused.length))
throw new IllegalArgumentException("Wrong array size !");
this.unused = unused;
setType(byte[].class);
}
/** @param error_or_bufferId_or_devEventParameter error code if the event type is an error event, or id of a buffer if the event has a buffer parameter, or an event parameter sent from the device (meaning depends on type) */
public field1_union(int error_or_bufferId_or_devEventParameter) {
super();
this.devEventParameter = this.bufferId = this.error = error_or_bufferId_or_devEventParameter;
setType(Integer.TYPE);
}
public field1_union(Pointer peer) {
super();
}
protected ByReference newByReference() { return new ByReference(); }
protected ByValue newByValue() { return new ByValue(); }
protected field1_union newInstance() { return new field1_union(); }
public static field1_union[] newArray(int arrayLength) {
return Union.newArray(field1_union.class, arrayLength);
}
public static class ByReference extends field1_union implements Structure.ByReference {
};
public static class ByValue extends field1_union implements Structure.ByValue {
};
};
public SA_SI_Event() {
//super();
}
protected List<? > getFieldOrder() {
return Arrays.asList("type", "field1");
}
/** @param field1 C type : field1_union */
public SA_SI_Event(int type, field1_union field1) {
super();
this.type = type;
this.field1 = field1;
}
public SA_SI_Event(Pointer peer) {
super();
}
protected ByReference newByReference() { return new ByReference(); }
protected ByValue newByValue() { return new ByValue(); }
protected SA_SI_Event newInstance() { return new SA_SI_Event(); }
public static SA_SI_Event[] newArray(int arrayLength) {
return Structure.newArray(SA_SI_Event.class, arrayLength);
}
public static class ByReference extends SA_SI_Event implements Structure.ByReference {
};
public static class ByValue extends SA_SI_Event implements Structure.ByValue {
};
}
Und über die DLL des Messgerätes gibt es diesen Funktionsaufruf
Java:
/**
* @brief Acquires a stream buffer for reading data.<br>
* @param handle Handle to the device.<br>
* @param bufferId Stream buffer ID.<br>
* @param[out] buffer Pointer to the stream data buffer.<br>
* As long as the buffer is acquired, the caller may read data from the buffer.<br>
* The buffer must be ready before it can be acquired, which will be signaled by<br>
* a streambuffer-ready event.<br>
* Original signature : <code>SA_SI_Error SA_SI_AcquireBuffer(SA_SI_Handle, unsigned int, const SA_SI_DataBuffer**)</code><br>
* <i>native declaration : line 526</i>
*/
int SA_SI_AcquireBuffer(int handle, int bufferId, ByReference buffer[]);
Ich versuche diese Klassen zusammen mit der Funktion aquireBuffer auszuführen, allerdings bekomme ich nichts zurück. Es wird immer ein leerer Buffer zurückgegeben.
Java:
SA_SI_Event ev = new SA_SI_Event();
int result = SA_SI_WaitForEvent(ihandle, ev, timeout);
if (result != SA_SI_OK) return result;
if (ev.type == SA_SI_STREAMBUFFER_READY_EVENT)
{
// get buffer data
picoscale.SA_SI_DataBuffer dataBuffer = new picoscale.SA_SI_DataBuffer();
result = SA_SI_AcquireBuffer(ihandle, ev.field1.bufferId, dataBuffer.castToReferenceArray());
if (result != SA_SI_OK) return result;
...
}
Ich habe schon eine ganze Reihe an verschiedenen Dingen ausprobiert, aber leider klappt nichts davon.
Das Datenfeld von dataBuffer ist leider immer leer, obwohl das Gerät Werte erzeugt und schickt, da ja auch das Streamready event reinpurzelt.
Der originale C++ Code dazu sieht im übrigen so aus, falls das weiter hilft.
C++:
SA_SI_Event ev;
unsigned int result = SA_SI_WaitForEvent(handle,&ev,timeout);
if (result != SA_SI_OK)
return result;
if (ev.type == SA_SI_STREAMBUFFER_READY_EVENT)
{
// get buffer data
const SA_SI_DataBuffer *pBuffer;
result = SA_SI_AcquireBuffer(handle,ev.bufferId,&pBuffer);
if (result != SA_SI_OK)
return result;
...
}
Ich hänge jetzt schon seit einiger Zeit daran und komme leider nicht weiter. Ich hoffe jemand von euch hat eine Idee, wie man mit diesen Datentypen richtig umgeht.