🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #153706

Posnet ThermalService.dll przy pomocy JNA, jak to zrobic?

#153706
From: 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
Technical Details
Message-ID: <e8a11341-dc00-4aae-9a28-21f6a398165e@ci3g2000vbb.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!wsisiz.edu.pl!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!newsfeed.pionier.net.pl!news.glorb.com!kr7no9209119pbb.0!news-out.google.com!s9ni37311pbb.0!nntp.google.com!kr7no9209116pbb.0!postnews.google.com!ci3g2000vbb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
Received: by 10.66.74.228 with SMTP id x4mr3665033pav.24.1355189483162;        Mon, 10 Dec 2012 17:31:23 -0800 (PST)
MIME-Version: 1.0
Received: by 10.49.96.196 with SMTP id du4mr3739084qeb.37.1355189482753; Mon, 10 Dec 2012 17:31:22 -0800 (PST)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!wsisiz.edu.pl!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!newsfeed.pionier.net.pl!news.glorb.com!kr7no9209119pbb.0!news-out.google.com!s9ni37311pbb.0!nntp.google.com!kr7no9209116pbb.0!postnews.google.com!ci3g2000vbb.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.java
Date: Mon, 10 Dec 2012 17:31:22 -0800 (PST)
Complaints-To: groups-abuse@google.com
Injection-Info: ci3g2000vbb.googlegroups.com; posting-host=89.75.71.3; posting-account=7FEzGwoAAACTB5SCpa6artQc8Y_84sVN
NNTP-Posting-Host: 89.75.71.3
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0,gzip(gfe)
Message-ID: <e8a11341-dc00-4aae-9a28-21f6a398165e@ci3g2000vbb.googlegroups.com>
Subject: Posnet ThermalService.dll przy pomocy JNA, jak to zrobic?
From: norbi771 <nn@tronix.pl>
Injection-Date: Tue, 11 Dec 2012 01:31:23 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit