🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.java
1 messages
1 total messages Started by norbi771 Tue, 11 Dec 2012 01:31
Posnet ThermalService.dll przy pomocy JNA, jak to zrobic?
#153706
Author: norbi771
Date: Tue, 11 Dec 2012 01:31
241 lines
8602 bytes
Witam grupę.
Potrzebuję w JAVIE oprogramować dostęp do drukarki fiskalnej POSNET.
Posnet dostarcza DLLkę pod windows (i działanie tego kodu tylko w
windows mnie zadowala). Niestety nie umiem dogadać się z drukarką gdy
mam do niej wysłać dane dotyczące pozycji na paragonie.

Do komunikacji z DLLką dobieram się przy pomocy JNA.
Podstawowa komunikacja działa mi OK, problem pojawia się jednak gdy
mam wysłać do drukarki pozycję  paragonu.

Z danych nagłówkowych opisujących tę bibliotekę wyciągnąłem:

typedef void * LPVOID;
typedef int ( *tTYPE_TRANSL_FUNC )( LPVOID, char * );
typedef struct
{
  tTYPE_TRANSL_FUNC TypeTranslFuncPtr;	/* conversion function pointer
*/
	LPVOID ParamValuePtr;   /* buffer address */
} tEXTERNAL_NUMERIC;

typedef struct
{
	BYTE					Pi;
	BYTE					Pr;
	char *					Name;
	tEXTERNAL_NUMERIC		Quantity;
	char *					Vat;
	tEXTERNAL_NUMERIC		Price;
	tEXTERNAL_NUMERIC		Gross;
	tEXTERNAL_NUMERIC		Discount;
} tLBTRSLN_PARAMS_INT;

/*
	LBTRSLN - parameters
*/
typedef struct
{
	BYTE					Pi;
	BYTE					Pr;
	char *					Name;
	tEXTERNAL_NUMERIC		Quantity;
	char						Vat;
	tEXTERNAL_NUMERIC		Price;
	tEXTERNAL_NUMERIC		Gross;
	tEXTERNAL_NUMERIC		Discount;
} tLBTRSLN_PARAMS;

pozostaje to przerobić na JNA:

Aktualnie mam tak:

package thermalservicelibrary;
import com.sun.jna.Callback;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;

public interface ThermalServiceLibraryLibrary extends Library {
	public static final String JNA_LIBRARY_NAME =
"ThermalServiceLibrary";
	public static final NativeLibrary JNA_NATIVE_LIB =
NativeLibrary.getInstance(ThermalServiceLibraryLibrary.JNA_LIBRARY_NAME);
	public static final ThermalServiceLibraryLibrary INSTANCE =
(ThermalServiceLibraryLibrary)Native.loadLibrary(ThermalServiceLibraryLibrary.JNA_LIBRARY_NAME,
ThermalServiceLibraryLibrary.class);
	public static class tEXTERNAL_NUMERIC extends Structure {
		/// conversion function pointer
		public ThermalServiceLibraryLibrary.tTYPE_TRANSL_FUNC
TypeTranslFuncPtr;
		/// buffer address
		public Pointer ParamValuePtr;
		public tEXTERNAL_NUMERIC() {
			super();
			initFieldOrder();
		}
		protected void initFieldOrder() {
			setFieldOrder(new String[]{"TypeTranslFuncPtr", "ParamValuePtr"});
		}
		public
tEXTERNAL_NUMERIC(ThermalServiceLibraryLibrary.tTYPE_TRANSL_FUNC
TypeTranslFuncPtr, Pointer ParamValuePtr) {
			super();
			this.TypeTranslFuncPtr = TypeTranslFuncPtr;
			this.ParamValuePtr = ParamValuePtr;
			initFieldOrder();
		}
		public static class ByReference extends tEXTERNAL_NUMERIC implements
Structure.ByReference {

		};
		public static class ByValue extends tEXTERNAL_NUMERIC implements
Structure.ByValue {

		};
	};
	public static class tLBTRSLN_PARAMS_INT extends Structure {
		public byte Pi;
		public byte Pr;
		public Pointer Name;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Quantity;
		public Pointer Vat;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Price;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Gross;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Discount;
		public tLBTRSLN_PARAMS_INT() {
			super();
			initFieldOrder();
		}
		protected void initFieldOrder() {
			setFieldOrder(new String[]{"Pi", "Pr", "Name", "Quantity", "Vat",
"Price", "Gross", "Discount"});
		}
		public tLBTRSLN_PARAMS_INT(byte Pi, byte Pr, Pointer Name,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Quantity, Pointer Vat,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Price,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Gross,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Discount) {
			super();
			this.Pi = Pi;
			this.Pr = Pr;
			this.Name = Name;
			this.Quantity = Quantity;
			this.Vat = Vat;
			this.Price = Price;
			this.Gross = Gross;
			this.Discount = Discount;
			initFieldOrder();
		}
		public static class ByReference extends tLBTRSLN_PARAMS_INT
implements Structure.ByReference {

		};
		public static class ByValue extends tLBTRSLN_PARAMS_INT implements
Structure.ByValue {

		};
	};
	public static class tLBTRSLN_PARAMS extends Structure {
		public byte Pi;
		public byte Pr;
		public Pointer Name;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Quantity;
		public byte Vat;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Price;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Gross;
		public ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Discount;
		public tLBTRSLN_PARAMS() {
			super();
			initFieldOrder();
		}
		protected void initFieldOrder() {
			setFieldOrder(new String[]{"Pi", "Pr", "Name", "Quantity", "Vat",
"Price", "Gross", "Discount"});
		}
		public tLBTRSLN_PARAMS(byte Pi, byte Pr, Pointer Name,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Quantity, byte Vat,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Price,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Gross,
ThermalServiceLibraryLibrary.tEXTERNAL_NUMERIC Discount) {
			super();
			this.Pi = Pi;
			this.Pr = Pr;
			this.Name = Name;
			this.Quantity = Quantity;
			this.Vat = Vat;
			this.Price = Price;
			this.Gross = Gross;
			this.Discount = Discount;
			initFieldOrder();
		}
		public static class ByReference extends tLBTRSLN_PARAMS implements
Structure.ByReference {

		};
		public static class ByValue extends tLBTRSLN_PARAMS implements
Structure.ByValue {

		};
	};
	public interface tTYPE_TRANSL_FUNC extends Callback {
		int apply(Pointer LPVOID1, Pointer charPtr1);
	};
}

samo dodanie linii paragonu

   public int SendDetails(byte Pr, String Name, Integer Qty, byte Vat,
float Price, float Gross, float Discount) {

        lineNumber++;

        tLBTRSLN_PARAMS params;

        IntByReference _Qty = new IntByReference(Qty);
        FloatByReference _Price = new FloatByReference(Price);
        FloatByReference _Gross = new FloatByReference(Gross);
        FloatByReference _Discount = new FloatByReference(Discount);

        Pointer _Name = new Memory(Name.length()+1);
        _Name.setString(0, Name);

            params = new ThermalServiceLibraryLibrary.tLBTRSLN_PARAMS(
               lineNumber,
               (byte)0,
               _Name,
               new tEXTERNAL_NUMERIC(null, _Qty.getPointer()),
               Vat,
               new tEXTERNAL_NUMERIC(null, _Price.getPointer()),
               new tEXTERNAL_NUMERIC(null, _Gross.getPointer()),
               new tEXTERNAL_NUMERIC(null, _Discount.getPointer())
               );


        return ThermalServiceLibraryLibrary.INSTANCE.LBTRSLN(params);
    }


problem pojawia się tu:
               new tEXTERNAL_NUMERIC(null, _Qty.getPointer()),
                                                      ^^^^^^^^

Zgodnie z dokumentacją:

typedef struct
{
  tTYPE_TRANSL_FUNC TypeTranslFuncPtr;	/* conversion function pointer
*/
	LPVOID ParamValuePtr;   /* buffer address */
} tEXTERNAL_NUMERIC;

I nie mam pojęcia jak ten wskaźnik TypeTranslFuncPtr stworzyć i jak go
użyć.

Czy ktos będzie uprzejmy mi pomóc?
Z góry dziękuję za pomoc


Norbert
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads