| |

VerySource

 Forgot password?
 Register
Search
View: 783|Reply: 3

dll parameter contains structure, how to call

[Copy link]

4

Threads

12

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-2-16 18:30:01
| Show all posts |Read mode
The dynamic library call description of the attendance machine is vb
 
Explanation: All functions only accept two parameters
Parameter one: Params structure
Parameter 2: A value indicating the type of hardware, value [30, 60, 2000, 2100, 2200, 2300, 2600]
 
Params structure definition
Public Type Params
       Port As String * 3 // Serial port number, [1 ~ 255]
       CtrlID As String * 3 // device number, [1 ~ 127]
       Params As String * 1024 // Input: The parameter table passed to the device for processing. Multiple parameters are separated by semicolons and terminated with semicolons.
                                                     // Output: Interface return value
End Type
 
1. 1. Open the serial port
Declaration
Public Declare Function OpenComm Lib "CM60.dll" (ByRef lParam As Params, ByVal sType As Integer) As Integer
Call example
dim p as Params
dim sType as Integer
dim ret as Long
 
sType = 2100
p.Port = "001" ‘Open serial port one
p.CtrlID = "001" ‘device number is 1
 
ret = OpenComm (p, sType)
select case ret
           case 100 ‘Open failed
case 105 ‘Successful opening of serial port
                       case else
       end select
 
2. 2. Close the serial port
Declaration
Public Declare Function CloseComm Lib "CM60.dll" (ByRef lParam As Params, ByVal sType As Integer) As Integer
Call example
Dim p as Params
Dim sType as Integer
Dim ret as Long
 
sType = 2100
p.Port = ”001” ‘Close the serial port
p.CtrlID = ”” ‘device number ignored
 
ret = CloseComm (p, sType)
select case ret
           case 100 ‘Failed to close the serial port
           case 105 ‘Successful closing of the serial port
           case else
end select
 
 
How do I call two or two examples in Delphi?
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-19 10:15:01
| Show all posts
// Structure type declaration
type
  TParams = Record
    Port: String [3]
    CtrlID: String [3] // Device number, [1 ~ 127]
    Params: String [1024]
  end
// Function declaration
function OpenComm (var lParam: Params, sType: Integer): Integer; external CM60.dll name 'OpenComm';
function CloseComm (var lParam: Params, sType: Integer): Integer; external CM60.dll name 'CloseComm';

//transfer:
var
  p: TParams;
  sType, ret: Integer;
begin
  sType: = 2100;
  p.Port: = '001';
  p.CtrlID: = '001';
  ret: = OpenComm (p, sType);
  case ret of
    100: ShowMessage ('Failed to open');
    105: ShowMessage ('Successfully opened the serial port');
  end;
  p.Port: = '001';
  p.CtrlID: = '';
  ret: = CloseComm (p, sType);
  case ret of
    100: ShowMessage ('Failed');
    105: ShowMessage ('Success');
  end;
end;
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-28 19:00:01
| Show all posts
Come late, help top
Reply

Use magic Report

4

Threads

12

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

 Author| Post time: 2020-4-28 21:15:02
| Show all posts
Thank you, the call is successful, but I do n’t know why I ca n’t adjust the serial port, always return 100

unit Ukq;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class (TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click (Sender: TObject);
  
  private
    {Private declarations}
  public
    {Public declarations}
  end;

type
  TParams = Record
    Port: String [3];
    CtrlID: String [3]; // Device number, [1 ~ 127]
    Params: string [250];
  end;

var
  Form1: TForm1;


implementation

{$ R * .dfm}
function OpenComm (var lParam: tParams; sType: Integer): Integer; stdcall; external 'CM60.dll';
function CloseComm (var lParam: tParams; sType: Integer): Integer; stdcall; external 'CM60.dll';

procedure TForm1.Button1Click (Sender: TObject);
var
  p: TParams;
  sType, ret: Integer;
begin
  sType: = 2100;
  p.Port: = edit1.text;
  p.CtrlID: = edit2.Text;
  ret: = OpenComm (p, sType);
    showmessage (inttostr (ret));


  ret: = CloseComm (p, sType);
   p.CtrlID: = '';
    showmessage (inttostr (ret));
 
end;
end.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list