Delphi, VB – SAIA PLC communication library.

Saia Communications library written with C++ language and contains functions for complete control of the Saia PLC. Functions are separated for two levels: primary and higher level where user can call complete dialogues with all communication settings.

Source of the SAIA dll version 1.4  and example of the Delphi application:


Data types of variables needed for Delphi application:

Saia DLLs for use with other programming languages need to translate the header-file SCommDll.h (should be delivered with the DLL,  SCommDll.h is located in include directory). First need create delphi unit  and define all type of variables used in Saia Dlls.

– Define type variables:


MyPChar       =  Array[0..63] of Char;
TReserved     =  Array[0..83] of Byte;

CWORD         =  word;
CDWORD        =  Cardinal;
CSHORT        =  SmallInt;
CBOOL         =  LongBool;
CCHAR         =  MyPChar;
pPcdConn      = ^Cardinal;

– Define “request station” :

REQSTATION =  record  //Complete station number information
  SbusStation  :   CWORD; //S-Bus station number
  FdlStation   :   CWORD; //Profi-S-Bus station number
  TcpPort      :   CWORD; //Tcp port number
  IpAddress    :   CDWORD;//Ip address<nl>format "" = 0x01020304

– Define “PCDOPENDATA” record of variables:


PCDOPENDATA  =  record

Port       :  CSHORT; //Port number TAPI,RAS,COMx, SOCKET
Device     :  CSHORT; //COM port number or Socket Port
bPguMode   :  CBOOL;  //TRUE=using PGU mode (S-BUS/P800)
SbusMode   :  CDWORD; //S-BUS mode:
Protocol   :  CDWORD; //Type of protocol
BaudRate   :  CDWORD; //110..38400
TsDelay    :  CDWORD; //S-BUS training sequence delay, mS
TnDelay    :  CDWORD; //S-BUS turnaround time, mS
Timeout    :  CDWORD; //S-BUS turnaround time, mS
BreakLen   :  CDWORD; //S-BUS break length in chars, PCD_BREAK mode
UartFifoLen:  CDWORD; //Number of characters in UART Fifo buffer (to wait for RTS)
bDontClose :  CBOOL;  //Do not close the port
bPortOpen  :  CBOOL;  //The port is open
bConnected :  CBOOL;  //The port is connected with the function PcdConnectChannel

dwType     :  CDWORD; //Channel type
Channel    :  CCHAR;  //Channel name 'PGU'
Section    :  CCHAR;  //Name of the section in INI file or Registry
ModeToTry  :  CDWORD; //Mode to connect
Cpu        :  CDWORD; //CPU number: 0..6
bAutoStn   :  CBOOL;  //TRUE=send "read S-BUS station" telegram
Retry      :  CDWORD; //Retry count, default = 3

//for TAPI, RAS or Socket
DeviceName :  CCHAR;  //TAPI, RAS or Socket IP Address device name.

//TAPI connection
bUseModem  :  CBOOL;  //Use dialing (TAPI modem).
bAutoAnswer:  CBOOL;  //Open the TAPI port in AutoAnswer mode.
PhoneNumber:  CCHAR;  //Phone number for TAPI or RAS dialing.
CountryCode:  CDWORD; //Country code (Switzerland 41).
AreaCode   :  CDWORD; //Area code (Morat 26).
Location   :  CCHAR;  //Location name.
bUseDialing:  CBOOL;  //Use dialing (translate phonenumb.)
DialRetry  :  CDWORD; //Number of retry when dialinBues flag

//Bues Connection
bBues      :  CBOOL;     //Bues flag

//password dialog box parent window
hPWDlgParentWnd:  HWND;//Parent window for password dialog box

ReqStation :  REQSTATION; //ReqStation  :  REQSTATION;
SrcSap     :  CSHORT;     //Source service access point for Profi-S-Bus communication
DstSap     :  CSHORT;     //Destination service access point for Profi-S-Bus  commun.
BDstSap    :  CSHORT;     //Broadcast Destination service access point for Profi-S-Bus
Reserved   :  TReserved;  //Reserved for future extension

– Variables :

  lpDataType  =     Array [0..49] of Cardinal;
  lpDataDB    =     Array [0..1005] of Cardinal;
  mOpenData    :    PCDOPENDATA;
  lpData       :    lpDataType;
  lpDB         :    lpDataDB;
  PcdConn      :    Cardinal;
  respons      :    integer;
  lpLength     :    lpDataType;

– Calling functions from dynamic-link library.

To use the functions of the Saia DLLs  need to use the stdcall convention.  This tells the compiler the rules that apply for setting up the stack, pushing arguments and getting a return value. With this convention, the caller (that’s Delphi) has to remove the parameters from the stack when the call returns.

All library functions can be divided into functional groups:

– Initialization and exit functions:

function PcdInitInterface():boolean;stdcall;
  external 'ScommDll.dll' name 'PcdInitInterface';

function PcdComUnloadDrv(unload:boolean):integer;stdcall;
  external 'ScommDll.dll' name 'PcdComUnloadDrv';

procedure PcdExitInterface;stdcall;
  external 'ScommDll.dll' name 'PcdExitInterface';

– Communication settings.

function PcdRdChanSetupFromIni( szIniName ,
  stdcall; external 'ScommDll.dll' name 'PcdRdChanSetupFromIni';

function PcdWrChanSetupToIni (szIniName, szAppName:MyPChar;
  const lpOpenData:pPCDOPENDATA):integer;stdcall;
  external 'ScommDll.dll' name 'PcdWrChanSetupToIni';

function PcdConnectionDialog(hParentWnd:HWND;
  external 'ScommUsr.dll' name 'PcdConnectionDialog';

function PcdChannelList(hParentWnd:HWND;
  external 'ScommUsr.dll' name 'PcdChannelList';

– Connection functions:

function PcdConnectChannel(lpPcdConn:pPcdConn;
  lpOpenData:pPCDOPENDATA; dwFlags : Cardinal;
  external 'ScommDll.dll' name 'PcdConnectChannel';

function PcdDisconnectChannel(PcdConn ,  dwFlags:Cardinal;
  external 'ScommDll.dll' name 'PcdDisconnectChannel';

Exchange data:

function PcdRdRTC(PcdConn:Cardinal; Typ:Char; Address,
  Count:Cardinal; lpData:lpDataType):integer;stdcall;
  external 'ScommDll.dll' name 'PcdRdRTC';

function PcdWrRTC(PcdConn:Cardinal; Typ:Char; Address,
  Count:Cardinal; lpData:lpDataType):integer;stdcall;
  external 'ScommDll.dll' name 'PcdWrRTC';

function PcdRdIOF(PcdConn:Cardinal; Typ:Char; Address,
  Count:Cardinal; lpData:PChar):integer;stdcall;
  external 'ScommDll.dll' name 'PcdRdIOF';

function PcdWrOF (PcdConn:Cardinal; Typ:Char; Address,
  Count:Cardinal; lpData:PChar):integer;stdcall;
  external 'ScommDll.dll' name 'PcdWrOF';

function PcdMessage(Status:integer):PChar;stdcall;
  external 'ScommDll.dll' name 'PcdMessage';

function PcdRdText(PcdConn:Cardinal; Number:Cardinal;
  lpLength:lpDataType; lpData:PChar):integer;stdcall;
  external 'ScommDll.dll' name 'PcdRdText';

function PcdRdTextChar(PcdConn:Cardinal; Number,
  Offset:Cardinal; lpLength:lpDataType; lpData:PChar):integer;
  stdcall; external 'ScommDll.dll' name 'PcdRdTextChar';

function PcdWrTextChar(PcdConn:Cardinal; Number, Offset,
  Size:Cardinal; lpszText:PChar):integer;stdcall;
  external 'ScommDll.dll' name 'PcdWrTextChar';

– Sources of the Delphi en VB6 modules.

Delphi_source VS_source
– Examples:

SAIA dll with Delphi example.

SAIA dll with VB6 example.


One Response to “Delphi, VB – SAIA PLC communication library.”

  1. Kenan SATIR Says:

    Good information. Thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: