У меня есть много типов весов со штрих-кодом, поэтому я хочу отправлять данные о товарах с помощью моей POS-программы. Но когда я искал больше, я знал, что должен использовать этот файл PBusDrv.dll и следовал приведенной ниже документации после того, как попробовал все, что знал, что получил Функция PBusTransferPLUCluster не работает, давая мне {Параметр неверен. (Исключение из HRESULT: 0x80070057 (E_INVALIDARG))}} так что любой может помочь мне решить эту проблему ??
это код
//
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private TPlu ONEPLU;
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi)]
private static extern int PBusConnect(string RefLFZKFileName, string RefCFGFileName, string SerialNO, string CommName, int BaudRate);
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi)]
private static extern int PBusConnectEx(string RefLFZKFileName, string RefCFGFileName, string IPAddr);
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi)]
private static extern int PBusDisConnect(string SerialNO);
[DllImport("PBusDrv.dll", CharSet = CharSet.Ansi)]
private static extern int PBusTransferPLUCluster(ref PPLUCluster PPC);
public struct TPLUCluster
{
public TPlu[] PLU;
}
public struct PPLUCluster
{
public TPLUCluster[] TPLUCluster;
}
public struct TPlu
{
// TPlu=record //PLU data structure
public string Name; //product name, 36 characters
public int LFCode; //Lfcode,1-999999,only way to identify each kind of product
public int Hotkey;
public string Code; //product code,10 digit, used to form barcode
public int BarCode; //barcode type,0-99
public int UnitPrice; //unit price, did not have decimal mode, 0-9999999
public int WeightUnit; //weight unit 0-12
public int Deptment; //department,2 number, used to form barcode
public double Tare; //tare weight, it should within 15Kg after logic conversion
public int ShlefTime; //shelf time,0-365
public int PackageType; //package type,0:normal/ limitative weight mode,1:weight fixed,2:price fixed,3:barcode printer mode
public Double PackageWeight; //package weight/limitative weight, it should within 15Kg after logic conversion
public int Tolerance; //package error tolerance,0-20
public byte Message1; //message 1,0-197
public byte Reserved; //reserved
public string Reserved1; //reserved
public byte Message2; //message 2,0-197
public byte Reserved2; //reserved
public byte MultiLabel; //multi-label,0-255,8 Bit corresponding to A0-D1 respectively
public short Rebate; //rebate,0-99
public int Account; //enter an item in an account, reserved
}
public Form1()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Int64 aa = 1;
string IP = "192.168.1.87"; //lfzkfull.DAT
aa = PBusDisConnect(IP);
aa = PBusConnectEx("C:\\Users\\Royal\\source\\repos\\WindowsFormsApp1\\WindowsFormsApp1\\bin\\Debug\\lfzk.DAT", "C:\\Users\\Royal\\source\\repos\\WindowsFormsApp1\\WindowsFormsApp1\\bin\\Debug\\SYSTEM.CFG", IP);
ONEPLU.Name = "TahaYOU";
ONEPLU.LFCode = 2;
ONEPLU.Code = "10001";// IP;
ONEPLU.BarCode = 7;
ONEPLU.UnitPrice = 60000;
ONEPLU.WeightUnit = 4;
ONEPLU.Deptment = 21;
ONEPLU.Tare = 0;
ONEPLU.ShlefTime = 15;
ONEPLU.PackageType = 0;
ONEPLU.PackageWeight = 0;
ONEPLU.Tolerance = 5;
ONEPLU.Reserved = 0;
ONEPLU.Reserved1 = "";
ONEPLU.Message1 = 0;
ONEPLU.Message2 = 0;
ONEPLU.MultiLabel = 0;
ONEPLU.Rebate = 0;
ONEPLU.Account = 0;
ONEPLU.Hotkey = 2;
TPLUCluster TPLUCluster = new TPLUCluster();
TPLUCluster.PLU = new TPlu[4];
TPLUCluster.PLU[0] = ONEPLU;
ONEPLU.Hotkey = 3;
ONEPLU.LFCode = 3;
TPLUCluster.PLU[1] = ONEPLU;
ONEPLU.Hotkey = 4;
ONEPLU.LFCode = 4;
TPLUCluster.PLU[2] = ONEPLU;
ONEPLU.Hotkey = 5;
ONEPLU.LFCode = 5;
TPLUCluster.PLU[3] = ONEPLU;
TPLUCluster[] TPLUClusterA = new TPLUCluster[1];
TPLUClusterA = new TPLUCluster[1];
TPLUClusterA[0] = TPLUCluster;
PPLUCluster ppc = new PPLUCluster();
ppc.TPLUCluster = TPLUClusterA;
aa = PBusTransferPLUCluster(ref ppc);
aa = PBusDisConnect(IP);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
и это документация
PBusDrv.DLL use explanation
PBusDrv.DLL is a 32 digit dynamic link libraries, mostly is used to download PLU data to Pinncale label scale.
Main Data structure and function: (Delphi syntax. For other languages, please refer to use):
1.Data structure
TPlu=record //PLU data structure
Name: PChar; //product name, 36 characters
LFCode: Longint; //Lfcode,1-999999,only way to identify each kind of product
Code: PChar; //product code,10 digit, used to form barcode
BarCode: Longint; //barcode type,0-99
UnitPrice: Longint; //unit price, did not have decimal mode, 0-9999999
WeightUnit: Longint; //weight unit 0-12
Deptment: Longint; //department,2 number, used to form barcode
Tare: Double; //tare weight, it should within 15Kg after logic conversion
ShlefTime: Longint; //shelf time,0-365
PackageType: Longint; //package type,0:normal/ limitative weight mode,1:weight fixed,
//2:price fixed,3:barcode printer mode
PackageWeight:Double; //package weight/limitative weight, it should within 15Kg after logic conversion
Tolerance: Longint; //package error tolerance,0-20
Message1: Byte; //message 1,0-197
Reserved: Byte; //reserved
Reserved1: Word; //reserved
Message2: Byte; //message 2,0-197
Reserved2: Byte; //reserved
MultiLabel: Byte; //multi-label,0-255,8 Bit corresponding to A0-D1 respectively
Rebate: ShortInt; //rebate,0-99
Account: LongInt; //enter an item in an account, reserved
end;
PPLU=^TPLU;
TPLUCluster=Array[0..3]of TPLU; //one PLU cluster including 4 pcs PLU
PPLUCluster=^TPLUCluster;
THotkeyTable=Array[0..83]of LongInt; //each array element is a PLU lfcode,
//84 pcs element corresponding to 84 pcs PLU
PHotkeyTable=^THotkeyTable;
For detailed explanation, please refer to user manual’s program interface part.
2.Function(suppose label scale sw (LBMNC) is installed under XX directory)
Connect function
Function PBusConnect(RefLFZKFileName:PChar;//lf font list file name,including path,
//usually point to XX\bin\lfzk.dat
//if used character set,point to XX\bin\lfzkfull.dat
RefCFGFileName:PChar; //configuration file name, including path, usually point to //XX\bin\system.cfg
SerialNO:DWord; //label scale serial number, if is Ethernet, please transfer IP address as
//DWord,such as 192.168.0.1 transfer to $C0A80001
CommName:PChar; //equipment name, such as:COM1,COM2,if is Ethernet, it is:IP
BaudRate:Integer //communication speed, set as 0
):Integer;far; external 'PbusDrv.dll';
Function PBusConnectEx(RefLFZKFileName:PChar;// lf font list file name, including path,
//usually point to XX\bin\lfzk.dat
//if use character set,point to XX\bin\lfzkfull.dat
RefCFGFileName:PChar; //configuration file name, including path, usually point to //XX\bin\system.cfg
IPAddr: PChar; //label scale IP address, such as:192.168.0.1
):Integer;far; external 'PbusDrv.dll';
Disconnect function
Function PBusDisConnect(SerialNO: DWord //label scale serial no.
):Integer;far; external 'PbusDrv.dll';
Function PBusDisConnectEx(IPAddr: PChar; //label scale IP address,such as:192.168.0.1
):Integer;far; external 'PbusDrv.dll';
send PLU function
Function PBusTransferPLUCluster(PPC:PPLUCluster //PLU cluster
):Integer;far; external 'PbusDrv.dll';
send Hotkey function
Function PBusTransferHotkey(HotkeyTable:PHotkeyTable; //hotkey list
TableIndex:Integer //hotkey list no., total two list,0 and 1
):Integer;far; external 'PbusDrv.dll';
send message function
Function PBusTransferMessage(Id:Integer; //info code,1~197
PMessage:PChar; //information text
DataLen:Integer //information text length
):Integer;far; external 'PBusDrv.DLL';
transform PLU to character string
Function PBusPLUToStr(LPPLU:PPLU; //PLU data
LPStr:PChar //character string(one line of TXP file), this finger must distribute space.
):Integer;Stdcall;far; external 'PbusDrv.dll';
transform character string to PLU
Function PBusStrToPLU(LPStr:PChar; //character string(one line to TXP file)
LPPLU:PPLU //PLU data
):Integer;Stdcall;far; external 'PbusDrv.dll';
clear all PLU
Function PBusClearPLUData:Integer;Stdcall;far; external 'PBusDrv.dll';
3.Flow
(1) PBusConnect if returned value<0, jump out
|
(2) PBusTransferPLUCluster/PBusTransferHotkey if returned value<0, jump to (4)
|
(3) PBusTransferPLUCluster/PBusTransferHotkey if returned value<0, jump to (4)
|
. if returned value<0, jump to (4)
.
.
(4) PBusDisConnect
4.Examples
Example under Delphi60 catalog is writen with Delphi, could pass test under Delphi6.0. Example under VB60 catalog is written with Visual Basic, could pass test under VB6.0.
Example under VC60 catalog is written with Visual C++, could pass test under VC6.0.
Example under PB65 catalog is written with PowerBuilder, could pass test under PB6.5.
Remarks:
1.Explanation of lf font bank and system parameter
PbusConnect connect function cites two file: lfzk.dat and system.cfg, lfzk.dat is lf font bank character list,store some system setting in system.cfg . We intensively suggest to cite corresponding file under link32 install catalog,to make sure that when Link32 sw modifying system parameter, it could reflect to dynamic link libraries in time。For example:There is a option “lf common font bank usage character set” of link32 system option,after modification of it, this parameter setting will be stored in system.cfg,if PbusConnect connect function cites system.cfg of link32 setting catalog ,the dynamic link libraries will download using new configure, or it will confuse the font bank. Of course, you could place these two file on other places, but must make sure update these two file in time and in-phase.
2.Setting of data align mode of delphi 6 and Delphi 7.
Set delphi6 and delphi7 as below,
Project->Options->Code generation->Record field alignment select 4
If do not want to change default setting (default value is 8) of Delphi data align mode or use Delphi5,could use PBusDrv.DLL of other catalog.