| |

VerySource

 Forgot password?
 Register
Search
View: 10|Reply: 1

The problem of dynamic library call (vb example to delphi)

[Copy link]

4

Threads

12

Posts

13

Credits

Newbie

Rank: 1

Credits
13

 United States

Post time: 2020-3-8 16:30:01
| Show all posts |Read mode
Attendance machine dynamic library description (example about 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

Interface return value definition
100 // Call interface failed
101 // This type of device is not supported
102 // This device does not support this interface
103 // device is not responding
104 // Parameter error
105 // The call was successful
106 // The serial port is not open
107 // Open file error
108 // Communication parameter error, resend
109 // Return value data check error
110 // Create thread error
111 // device is busy

I. IT2100
1. Open the serial port
statement
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. Close the serial port
statement
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


I am now testing under DELPHI:
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;
 pparams = ^ TParams;


var
  Form1: TForm1;


implementation

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

procedure TForm1.Button1Click (Sender: TObject);
var
  p: pparams;
  sType, ret: Integer;
begin
  sType: = 2100;

  new (p);
  p ^ .Port: = edit1.Text;
  p ^ .CtrlID: = edit2.Text;

  ret: = OpenComm (p, sType);
   showmessage (inttostr (ret));


 ret: = CloseComm (p, sType);
 p ^ .CtrlID: = '';
  showmessage (inttostr (ret));
  dispose (p);
 
end;
end.
The result of each test returns 100 (the serial port fails to open and close), which is the case on multiple machines. And the terminal management of the time attendance machine can open the serial port every time.

I don't know what is wrong with my code?
Reply

Use magic Report

4

Threads

12

Posts

13

Credits

Newbie

Rank: 1

Credits
13

 Japan

 Author| Post time: 2020-6-2 11:30:03
| Show all posts
Come on, Comet attendance machine
Reply

Use magic Report

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

Points Rules

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

Quick Reply To Top Return to the list