📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
edtdev: TEdit;
Label1: TLabel;
edtsrv: TEdit;
Label2: TLabel;
edtnum: TEdit;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
function GetModuleInformation:LPCTSTR;stdcall;external 'SimplePCConnect.dll';
function InitializePCConnect(nInitializeStatus:dword):BOOL;stdcall;external 'SimplePCConnect.dll';
procedure UninitializePCConnect;stdcall;external 'SimplePCConnect.dll';
function OpenPCConnect(nDeviceNumber:dword;lpszLicence:LPCTSTR;lpszSCA:LPCTSTR):BOOL;stdcall;external 'SimplePCConnect.dll';
function ReopenPCConnect(nDeviceNumber:dword):BOOL;stdcall;external 'SimplePCConnect.dll';
procedure ClosePCConnect(nDeviceNumber:dword);stdcall;external 'SimplePCConnect.dll';
function GetAuthorization(nDeviceNumber:dword):BOOL;stdcall;external 'SimplePCConnect.dll';
function DetectPCConnect(nDeviceNumber:dword):BOOL;stdcall;external 'SimplePCConnect.dll';
procedure SetStatusReceiptRequested(bStatusReceiptRequested:BOOL);stdcall;external 'SimplePCConnect.dll';
procedure SetRejectDuplicated(bRejectDuplicated:BOOL);stdcall;external 'SimplePCConnect.dll';
procedure SetProtocolIdentification(bProtocolIdentification:Byte);stdcall;external 'SimplePCConnect.dll';
function SetUTF8Content(lpszContent:LPCTSTR;bImmediateDisplay:BOOL):BOOL;stdcall;external 'SimplePCConnect.dll';
function Set7BitContent(lpszContent:LPCTSTR):BOOL;stdcall;external 'SimplePCConnect.dll';
function SetBinaryContent(lpszContent:LPCTSTR;bHeaderIndication:BOOL):BOOL;stdcall;external 'SimplePCConnect.dll';
procedure ClearContent;stdcall;external 'SimplePCConnect.dll';
function SendContent(nDeviceNumber:dword;lpszTerminalAddress:LPCTSTR):BOOL;stdcall;external 'SimplePCConnect.dll';
function ReceiveContent(nDeviceNumber:dword;lpszTerminalAddress:LPSTR;
lpszContent:LPSTR):BOOL;stdcall;external 'SimplePCConnect.dll';
function GetStatus(nDeviceNumber:dword):integer;stdcall;external 'SimplePCConnect.dll';
var
Form1: TForm1;
open:Boolean;
info:pchar;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
devnum:dword;
begin
devnum:=strtoint(edtdev.Text);
if not open then
begin
if not DetectPCConnect(devnum) then showmessage('不支持AT命令');
if (devnum>255) or (devnum<0) then showmessage('设备号超出范围');
if not OpenPCConnect(devnum,pchar('243BABCF4269AAD2E2461F3C84B946F6'),pchar(edtsrv.Text)) then
showmessage('打开设备失败')
else open:=true;
If not GetAuthorization(devnum) Then showmessage('未授权');
SetStatusReceiptRequested(true);
SetProtocolIdentification(0);
if not SetUTF8Content(pchar(memo1.Text),false) then
showmessage('设置中文短信失败');
end;
if not SendContent(devnum,pchar(edtnum.Text)) then
case GetStatus(devnum) of
1:showmessage('串口设备失效');
2:showmessage('AT指令执行成功');
3:showmessage('AT指令执行错误');
4:showmessage('GSM网络执行指令错误');
5:showmessage('硬件设备错误');
end
else showmessage('发送成功');
if open then
begin
ClosePCConnect(devnum);
open:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitializePCConnect(0);
open:=false;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if open then
begin
ClosePCConnect(strtoint(edtdev.Text));
freemem(info);
end;
UninitializePCConnect;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -