Übersicht

KS8000: Overview

Overview

The "Beckhoff KS8000 Communication Library" provides functions with which it is easily possible to communicate with Beckhoff BK8x00 Bus Couplers via a serial PC interface.

Specification

KS8000 permits access to the input and output process image of the BK8xxx Bus Coupler via the serial PC interface. Through each serial PC interface it is possible to establish communication with a BK8100 coupler (RS 232) or up to 99 BK8000 couplers (RS 485). Such communication transfers the whole of the input and output process image. The duration of the communication therefore depends on the size of the process image, or in other words on the number and type of terminals attached.

(Measurement: RS232 coupler, 38400 baud, process image 1 word results in about 6 ms. With 15 words, the result is about 20 ms).

It is also possible to alter the coupler's watchdog time.


Lieferumfang

KS8000: Overview

What is included

  • KS8000 ActiveX components:

    \Bin\BkcomOCX.ocx
    \Bin\BkcomOCX.tlb

    The "KS8000 ActiveX Components" can be employed by any programming language that functions in accordance with the specifications of the Component Object Model (COM) from Microsoft: VC++, Visual Basic, Borland C++ Builder, Delphi, Java ...

  • KS8000-DLL: Standard C-DLL for use under VC++.

    \Bin\BkcomDLL.dll
    \Bin\BkcomDLL.h
    \Bin\BkcomDLL.lib

  • LabView-VI-DLL:

    \Bin\BkcomLV.dll

    Labview Templates:
    \LabView Template\Close-BkComLV.vi
    \LabView Template\Open-BkComLV.vi
    \LabView Template\ReadWrite-BkComLV.vi
    \LabView Template\Read-BkComLV.vi

    The LabVIEW graphical programming system from National Instruments supports the creation of applications without the need to write large amounts of program text. Programming is achieved through the selection, insertion and linking of graphical symbols into what are known as block diagrams, using a mouse. LabVIEW programs are called virtual instruments, or VI for short.

In addition to the documentation itself, extensive examples for C++, Visual Basic, Borland C++ Builder and Delphi are available.


BKxBaudrate

Specifies the baud rate for the communication

Type

Long

Value range

  • Baud_9600 = 9600 baud
  • Baud_19200 = 19200 baud
  • Baud_38400 = 38400 baud (default setting)

Comments

The other communication parameters are specified as 8 data bits, 1 stop bit and even parity, and cannot be changed.

The BK8x00 Bus Couplers adjust themselves automatically to the specified baud rate. It is possible that the Bus Coupler will require 4 communication attempts to synchronise itself to the correct baud rate.


BKxTyp

KS8000: Properties

BKxType

Specifies the type of the Bus Coupler.

Type

Long

Value range

  • (1) BKxType_RS485 = 1 (coupler with RS485 communication) (default setting)
  • (2) BKxType_RS232 = 2 (coupler with RS232 communication)

Comments

It is necessary to set this property in order to ensure correct data exchange. The Bx8000 couplers operate via the RS485 interface, while all the other couplers use RS232.

IMPORTANT NOTE FOR Bx8000 (RS485):

We strongly recommend the use of an RS-485 PC interface card – or an external converter – that performs automatic switching of the send and receive directions. In this case the BkxTyp is to be set to BKxType_RS232 = 2 (coupler with RS232 communication).


BKx_CommPort

KS8000: Properties

BKxCommPort

Specifies the serial PC interface via which communication with the couplers will take place.

Type

Long

Value range

COM port 1-8 (default is 2)


BKxPortOpen

KS8000: Properties

BKxCommPort

Opens / closes the serial interface.

Type

Boolean

Value range

  • True = COM port open
  • False = COM port closed

Comments

It is only possible to access the property at run-time.

The OCX generates an exception if an attempt is made to open an interface that is not physically present, or if it is already occupied by another process.


BKxTimeout

Specifies the waiting time for the response telegram from the coupler.

Type

Long

Value range

Time in ms


BK8xProcSyncReadReq

The BK8xProcSyncReadReq method is a call for synchronous communication to read the entire input process image of a BK8x00 Bus Coupler. The size of the process image depends on the number and type of terminals plugged into the coupler.

BkcomComErr BK8xProcSyncReadReq (
    long lMultiPoint,
    long lStatus,
    long cwRecLength,
    long lpRecBuff
);

Parameters

lMultiPoint
[in]
(1..99) Specifies the recipient
lStatus
[out]
(1..99) Coupler status (see Appendix)

cwRecLength
[out]
Number of words read (a word in a long value) from offset 0 in the input process image

lpRecBuff
[in, out]
Receive buffer, long (array)

Return Values

BKcomComErr
Return code (see Appendix)

Example

Dim lRet as long, lMultiPoint as long, lStatus as Long, cwRecLength as long
Dim RecBuff(255) as long

lmultiPoint = 11 ' ZielStation 11
LRet = Bkcom1.BK8xProcSyncReadReq( lMultiPoint, lStatus, cwRecLength, RecBuff(0))

' RecBuff(0) contains input word [0] from the coupler
' RecBuff(1) contains input word [1] from the coupler
' RecBuff(2) contains input word [2] from the coupler


BK8xProcSyncReadWriteReq

The BK8xProcSyncReadWriteReq method is a call for synchronous communication to write the entire output process image and to read the entire input image of a BK8x00 Bus Coupler. The size of the process image read depends on the number and type of terminals plugged into the coupler. The entire process output image MUST be written. It is not possible to write a partial segment. The transmit and receive buffers are of type LONG (32 bits), although only the low word is transmitted to or from the coupler (see example below).

BkcomComErr BK8xProcSyncReadWriteReq (
    long lMultiPoint,
    long lStatus,
    long cwSendLength,
    long lpSendBuff,
    long cwRecLength,
    long lpRecBuff
);

Parameters

lMultiPoint
[in]
(1..99) Specifies the recipient
lStatus
[out]
(1..99) Coupler status (see Appendix)

cwSendLength
[in]
Number of words to be written (a word in a long value) from offset 0 in the process output image

lpSendBuff
[in, out]
Receive buffer, long (array)

cwRecLength
[out]
Number of words read (a word in a long value) from offset 0 in the input process image

lpRecBuff
[in, out]
Receive buffer, long (array)

Return Values

BKcomComErr
Return code (see Appendix)

Beispiel

Dim lRet as long, lMultiPoint as long, lStatus as Long, cwRecLength as long, cwSendLength as long
Dim RecBuff(255) as long
Dim SendBuff(255) as long

lmultiPoint = 11 ' Destination station 11

SendBuff(0) = 1 ' Output word [0] on the coupler is set to 1
SendBuff(1) = &H55 ' Output word [1] on the coupler is set to &H55
SendBuff(2) = &HAAEE ' Output word [2] on the coupler is set to &HAAEE

LRet = Bkcom1.BK8xProcSyncReadWriteReq( lMultiPoint, lStatus, cwSendLength, SendBuff(0),cwRecLength, RecBuff(0))

' RecBuff(0) contains input word [0] from the coupler
' RecBuff(1) contains input word [1] from the coupler
' RecBuff(2) contains input word [2] from the coupler


BK8xWatchDogReadReq

The BK8xWatchDogReadReq method is a call for synchronous communication to read the set watchdog time on the destination coupler selected by <lMultiPoint>.

BkcomComErr BK8xWatchDogReadReq(
    long lMultiPoint,
    long WatchDog
);

Parameters

lMultiPoint
[in]
(1..99) Specifies the recipient
WatchDog
[out]
WatchDog in ms

Return Values

BKcomComErr
Return code (see Appendix)

Example

Dim lRet as long
Dim lValue as long

LRet = BkcomOCX1.BK8xWatchDogReadReq(11,lValue)

' the variable <lValue> contains the watchdog time for station 11


BK8xWatchDogWriteReq

The BK8xWatchDogWriteReq method is a call for synchronous communication to set a new watchdog time on the destination coupler selected by <MultiPoint>.

This method leads to a restart of the coupler (a reboot). Only after this has the coupler adopted the new watchdog time.

The coupler should first have synchronised to the correct baud rate. This means that it is possible that 4 communication attempts may have to take place first to establish the synchronisation.

BkcomComErr BK8xWatchDogWriteReq(
    long lMultiPoint,
    long WatchDog
);

Parameters

lMultiPoint
[in]
(1..99) Specifies the recipient
WatchDog
[in]
WatchDog in ms

Parameters

Return Values

BKcomComErr
Return code (see Appendix)

Example

Dim lRet as long

LRet = BkcomOCX1.BK8xWatchDogWriteReq(11, 2000)

' The watchdog time for station 11 is set to 2000ms. The coupler boots.


Einbinden des KS8000-OCX in Visual Basic

KS8000: Linking OCX into applications

Linking the OCX into Visual Basic

The KS8000 ActiveX Control can be used in Visual Basic.

For this purpose, you must select the command 'Components...' under the 'Project' menu in Visual Basic, and then mark the 'Beckhoff KS8000 ActiveX Control' entry.

The KS8000 ActiveX Control then appears in the Visual Basic toolbox (bottom right).


Einbinden des KS8000-OCX in Delphi und C++Builder

KS8000: Linking OCX into applications

Linking the OCX into Delphi and C++Builder

In order to be able to link the KS8000-OCX into Delphi or C++ Builder applications you must first link the KS8000-OCX into the Delphi or C++ Builder component palette. This requires you to select the command Import ActiveX... from the Components menu, and then to mark the entry Beckhoff KS8000: BKcomOCX ActiveX Control in the dialogue box.

Then confirm with Install and OK. The package must then be re-compiled.

The ActiveX component is registered after successful compilation. When closing the package the changes must be saved.

The new component then appears in the ActiveX Components palette of Delphi or C++ Builder.

In order to be able to use the ActiveX component, you must drag it onto a form.


Übersicht Beispiele

KS8000: Examples

Summary of examples

Description | Language | Source text
Example 1: Demonstration of the methods | Visual Basic 5.0 | OcxSample01.exe
Example 2: Synchronous reading of the process input image | Delphi 5.0 | OcxSample02.exe
Example 3: Synchronous write/read of the process images | Delphi 5.0 | OcxSample03.exe
Example 4: Read/set the coupler watchdog time | Delphi 5.0 | OcxSample04.exe
Example 5: Synchronous reading of the process input image | C++Builder 5.0 | OcxSample05.exe
Example 6: Synchronous write/read of the process images | C++Builder 5.0 | OcxSample06.exe
Example 7: Read/set the coupler watchdog time | C++Builder 5.0 | OcxSample07.exe
Example 8: Demonstration of all methods | C++Builder 5.0 | OcxSample08.exe


Demo der Methoden (VB)

KS8000: Examples

VB: Demonstration of the methods

The VB demonstration shows the linking of the KS8000-OCX into a Visual Basic project, together with the use of properties and methods.

Unpack the example program 'VB: Demonstration of Methods'


Delphi: Synchrones Lesen der Prozeßeingangsdaten

KS8000: Examples

Delphi: Synchronous reading of process input data

Task

The coupler's process input image is to be read from the Windows application. The coupler is fitted with a digital input terminal and a digital output terminal (e.g. KL1104 and KL2114). Each terminal has 4 inputs and 4 outputs. Station address 11 is set by the rotary switches on the coupler.

Description

The following properties (parameters) for communication with the coupler are set in the event function FormCreate(): BKxBaudrate, BKxTyp, BKxTimeout, BKxCommPort. The communication port is opened by setting the property BKxPortOpen to true. In the event function OnDestroy(), the communication port is closed by setting the property BKxPortOpen to false.

By activating the button on the form, the event function OnReadButtonClick() is called. In this event function, the method BK8xPorcSyncReadRea() is used to read the whole of the coupler's process input image (real) synchronously, and to display it as text on the form. In our example the actual length of the coupler's process input data is 4 bits. The parameter cbReadLength determines the actual length of the process input data of the coupler as the number of complete words.

Delphi program

procedure TForm1.FormCreate(Sender: TObject);
begin
BKcomOCX1.BKxBaudrate := Baud_38400;
BKcomOCX1.BKxTyp := BKxType_RS485;
BKcomOCX1.BKxTimeout := 1000;
BKcomOCX1.BKxCommPort := 2;
BKcomOCX1.BKxPortOpen := true;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
BKcomOCX1.BKxPortOpen := false;
end;

procedure TForm1.OnReadButtonClick(Sender: TObject);
var
nMultiPoint :integer;
nStatus :integer;
nRet :integer;
ReadBuffer :Array[0..254] of integer;
cbReadLength :integer;
begin
nMultiPoint := 11;
cbReadLength := 1;

nRet := BKcomOCX1.BK8xProcSyncReadReq( nMultiPoint, nStatus, cbReadLength, ReadBuffer[0] );
DataLabel.Caption :='Retval:' + IntToStr( nRet ) +
' MultiPoint:' + IntToStr( nMultiPoint ) +
' nStatus:' + IntToStr( nStatus ) +
' cbReadLength:' + IntToStr( cbReadLength ) +
' ReadBuffer[0]=' + IntToStr( ReadBuffer[0] );
end;

Unpack the example program 'Synchronous Reading of the Process Input Data'


Delphi: Synchrones Lesen/Schreiben der Prozeßabbilder

KS8000: Examples

Delphi: Synchronous read/write of the process images

Task

The coupler's process input image is to be read from the Windows application whilst at the same time setting the coupler's process output image. The coupler is fitted with a digital input terminal and a digital output terminal (e.g. KL1104 and KL2114). Each terminal has 4 inputs and 4 outputs. Station address 11 is set by the rotary switches on the coupler.

Description

The following properties (parameters) for communication with the coupler are set in the event function FormCreate(): BKxBaudrate, BKxTyp, BKxTimeout, BKxCommPort. The communication port is opened by setting the property BKxPortOpen to true. In the event function OnDestroy(), the communication port is closed by setting the property BKxPortOpen to false.

By activating the button on the form, the event function OnReadWriteButtonClick() is called. In this event function, the method BK8xProcSyncReadWriteReq() reads the whole of the coupler's process input image into an array of integer values, and at the same time the process output image is filled with new values from another array. The values of the parameters transferred are displayed as text on the form. The parameters cbWriteLength and cbReadLength determine the actual lengths of the two process images in multiples of the word length. In our case the true length of the process images is 4 bits in each case, which is why the two parameters are set to 1.

Delphi program

procedure TForm1.FormCreate(Sender: TObject);
begin
BKcomOCX1.BKxBaudrate := Baud_38400;
BKcomOCX1.BKxTyp := BKxType_RS485;
BKcomOCX1.BKxTimeout := 1000;
BKcomOCX1.BKxCommPort := 2;
BKcomOCX1.BKxPortOpen := true;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
BKcomOCX1.BKxPortOpen := false;
end;

procedure TForm1.OnReadWriteButtonClick(Sender: TObject);
var
nMultiPoint :integer;
nStatus :integer;
nRet :integer;
ReadBuffer :Array[0..254] of integer;
cbReadLength :integer;
WriteBuffer :Array[0..254] of integer;
cbWriteLength :integer;
begin
nMultiPoint := 11;
cbReadLength := 1;
cbWriteLength := 1;
WriteBuffer[0]:= $F;

nRet := BKcomOCX1.BK8xProcSyncReadWriteReq( nMultiPoint, nStatus, cbWriteLength, WriteBuffer[0], cbReadLength, ReadBuffer[0] );
DataLabel.Caption :='Retval:' + IntToStr( nRet ) +
' MultiPoint:' + IntToStr( nMultiPoint ) +
' nStatus:' + IntToStr( nStatus ) +
' cbWriteLength:' + IntToStr( cbWriteLength ) +
' WriteBuffer[0]=' + IntToStr( WriteBuffer[0] ) +
' cbReadLength:' + IntToStr( cbReadLength ) +
' ReadBuffer[0]=' + IntToStr( ReadBuffer[0] );
end;

Unpack the example program 'Synchronous Reading/Writing of the Process Images'.


Delphi: Lesen/Setzen der Koppler-Watchdogzeit

KS8000: Examples

Delphi: Read/set the coupler watchdog time

Task

The coupler's current watchdog time is to be read from the Windows application, and a new, user-specific watchdog time (500 milliseconds) can be set. Station address 11 is set by the rotary switches on the coupler.

Description

The following properties (parameters) for communication with the coupler are set in the event function FormCreate(): BKxBaudrate, BKxTyp, BKxTimeout, BKxCommPort. The communication port is opened by setting the property BKxPortOpen to true. In the event function OnDestroy(), the communication port is closed by setting the property BKxPortOpen to false.

By activating the Watchdog Read button on the form, the event function OnWatchdogReadButtonClick() is called. In this event function the method BK8xWatchDogReadReq() is used to read the coupler's current watchdog time and to display it as text on the form. The Watchdog Write button can be used to set a new, user-specific watchdog time. This involves calling the event function OnWatchdogWriteButtonClick() and the method BK8xWatchDogWriteReq(). After this the coupler carries out a reset.

Delphi program

procedure TForm1.FormCreate(Sender: TObject);
begin
BKcomOCX1.BKxBaudrate := Baud_38400;
BKcomOCX1.BKxTyp := BKxType_RS485;
BKcomOCX1.BKxTimeout := 1000;
BKcomOCX1.BKxCommPort := 2;
BKcomOCX1.BKxPortOpen := true;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
BKcomOCX1.BKxPortOpen := false;
end;

procedure TForm1.OnWatchdogReadButtonClick(Sender: TObject);
var
nMultiPoint :integer;
nRet :integer;
nWatchdog :integer;
begin
nMultiPoint := 11;
nRet := BKcomOCX1.BK8xWatchDogReadReq( nMultiPoint, nWatchdog );
DataLabel.Caption :='Retval:' + IntToStr( nRet ) +
' MultiPoint:' + IntToStr( nMultiPoint ) +
' Watchdog:' + IntToStr( nWatchdog ) + 'ms';
end;

procedure TForm1.OnWatchdogWriteButtonClick(Sender: TObject);
var
nMultiPoint :integer;
nRet :integer;
nWatchdog :integer;
begin
nMultiPoint := 11;
nWatchdog :=500;
nRet := BKcomOCX1.BK8xWatchDogWriteReq( nMultiPoint, nWatchdog );
DataLabel.Caption :='Retval:' + IntToStr( nRet ) +
' MultiPoint:' + IntToStr( nMultiPoint ) +
' Watchdog:' + IntToStr( nWatchdog ) + 'ms';
end;

Unpack the example program 'Read/set the coupler watchdog time'.


C++Builder: Synchrones Lesen der Prozeßeingangsdaten

KS8000: Examples

C++Builder: Synchronous reading of process input data

Task

The coupler's process input image is to be read from the Windows application. The coupler is fitted with a digital input terminal and a digital output terminal (e.g. KL1104 and KL2114). Each terminal has 4 inputs and 4 outputs. Station address 11 is set by the rotary switches on the coupler.

Description

The following properties (parameters) for communication with the coupler are set in the event function FormCreate(): BKxBaudrate, BKxTyp, BKxTimeout, BKxCommPort. The communication port is opened by setting the property BKxPortOpen to true. In the event function OnDestroy(), the communication port is closed by setting the property BKxPortOpen to false.

By activating the button on the form, the event function OnReadButtonClick() is called. In this event function, the method BK8xPorcSyncReadRea() is used to read the whole of the coupler's process input image (real) synchronously, and to display it as text on the form. In our example the actual length of the coupler's process input data is 4 bits. The parameter cbReadLength determines the actual length of the process input data of the coupler as the number of complete words.

C++ Builder Program

void __fastcall TForm1::FormCreate(TObject *Sender)
{
BKcomOCX1->BKxBaudrate = Baud_38400;
BKcomOCX1->BKxTyp = BKxType_RS485;
BKcomOCX1->BKxTimeout = 1000;
BKcomOCX1->BKxCommPort = 2;
BKcomOCX1->BKxPortOpen = true;
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
BKcomOCX1->BKxPortOpen = false;
}

void __fastcall TForm1::OnReadButtonClick(TObject *Sender)
{
long nMultiPoint = 11;
long nStatus;
long nRet;
long ReadBuffer[255];
//ReadBuffer[0] == Coupler Output Word[0]
//ReadBuffer[1] == Coupler Output Word[1]
//ReadBuffer[2] == Coupler Output Word[2]
long cbReadLength = 1;

nRet = BKcomOCX1->BK8xProcSyncReadReq( nMultiPoint, &nStatus, &cbReadLength, &ReadBuffer[0] );
DataLabel->Caption ="Retval:" + IntToStr( nRet ) +
" MultiPoint:" + IntToStr( nMultiPoint ) +
" nStatus:" + IntToStr( nStatus ) +
" cbReadLength:" + IntToStr( cbReadLength ) +
" ReadBuffer[0]=" + IntToStr( ReadBuffer[0] );
}

Unpack the example program 'Synchronous Reading of the Process Input Data'


C++Builder: Synchrones Lesen/Schreiben der Prozeßabbilder

KS8000: Examples

C++Builder: Synchronous read/write of the process images

Task

The coupler's process input image is to be read from the Windows application whilst at the same time setting the coupler's process output image. The coupler is fitted with a digital input terminal and a digital output terminal (e.g. KL1104 and KL2114). Each terminal has 4 inputs and 4 outputs. Station address 11 is set by the rotary switches on the coupler.

Description

The following properties (parameters) for communication with the coupler are set in the event function FormCreate(): BKxBaudrate, BKxTyp, BKxTimeout, BKxCommPort. The communication port is opened by setting the property BKxPortOpen to true. In the event function OnDestroy(), the communication port is closed by setting the property BKxPortOpen to false.

By activating the button on the form, the event function OnReadWriteButtonClick() is called. In this event function, the method BK8xProcSyncReadWriteReq() reads the whole of the coupler's process input image into an array of integer values, and at the same time the process output image is filled with new values from another array. The values of the parameters transferred are displayed as text on the form. The parameters cwWriteLength and cwReadLength determine the actual lengths of the two process images in multiples of the word length. In our case the true length of the process images is 4 bits in each case, which is why the two parameters are set to 1.

C++ Builder Program

void __fastcall TForm1::FormCreate(TObject *Sender)
{
BKcomOCX1->BKxBaudrate = Baud_38400;
BKcomOCX1->BKxTyp = BKxType_RS485;
BKcomOCX1->BKxTimeout = 1000;
BKcomOCX1->BKxCommPort = 2;
BKcomOCX1->BKxPortOpen = true;
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
BKcomOCX1->BKxPortOpen = false;
}

void __fastcall TForm1::OnReadWriteButtonClick(TObject *Sender)
{
long nMultiPoint = 11;
long nStatus;
long nRet;
long ReadBuffer[255];
long cwReadLength = 1;
//ReadBuffer[0] == Coupler Output Word[0]
//ReadBuffer[1] == Coupler Output Word[1]
//ReadBuffer[2] == Coupler Output Word[2]
long WriteBuffer[255];
//WriteBuffer[0] == Coupler Input Word[0]
//WriteBuffer[1] == Coupler Input Word[1]
//WriteBuffer[2] == Coupler Input Word[2]
long cwWriteLength = 1;

//Set Data to Send:
WriteBuffer[0]=0xF;

nRet = BKcomOCX1->BK8xProcSyncReadWriteReq( nMultiPoint, &nStatus, cwWriteLength, &WriteBuffer[0], &cwReadLength, &ReadBuffer[0] );
DataLabel->Caption ="Retval:" + IntToStr( nRet ) +
" MultiPoint:" + IntToStr( nMultiPoint ) +
" nStatus:" + IntToStr( nStatus ) +
" cbWriteLength:" + IntToStr( cwWriteLength ) +
" WriteBuffer[0]=" + IntToStr( WriteBuffer[0] ) +
" cbReadLength:" + IntToStr( cwReadLength ) +
" ReadBuffer[0]=" + IntToStr( ReadBuffer[0] );
}

Unpack the example program 'Synchronous Reading/Writing of the Process Images'.


C++Builder: Lesen/Setzen der Koppler-Watchdogzeit

KS8000: Examples

C++Builder: Read/set the coupler watchdog time

Task

The coupler's current watchdog time is to be read from the Windows application, and a new, user-specific watchdog time (1100 milliseconds) can be set. Station address 11 is set by the rotary switches on the coupler.

Description

The following properties (parameters) for communication with the coupler are set in the event function FormCreate(): BKxBaudrate, BKxTyp, BKxTimeout, BKxCommPort. The communication port is opened by setting the property BKxPortOpen to true. In the event function OnDestroy(), the communication port is closed by setting the property BKxPortOpen to false.

By activating the Watchdog Read button on the form, the event function OnWatchdogReadButtonClick() is called. In this event function the method BK8xWatchDogReadReq() is used to read the coupler's current watchdog time and to display it as text on the form. The Watchdog Write button can be used to set a new, user-specific watchdog time. This involves calling the event function OnWatchdogWriteButtonClick() and the method BK8xWatchDogWriteReq(). After this the coupler carries out a reset.

C++ Builder Program

void __fastcall TForm1::FormCreate(TObject *Sender)
{
BKcomOCX1->BKxBaudrate = Baud_38400;
BKcomOCX1->BKxTyp = BKxType_RS485;
BKcomOCX1->BKxTimeout = 1000;
BKcomOCX1->BKxCommPort = 2;
BKcomOCX1->BKxPortOpen = true;
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
BKcomOCX1->BKxPortOpen = false;
}

void __fastcall TForm1::OnWatchdogReadButtonClick(TObject *Sender)
{
long nMultiPoint = 11;
long nRet;
long nWatchdog;
nRet = BKcomOCX1->BK8xWatchDogReadReq( nMultiPoint, &nWatchdog );
DataLabel->Caption ="Retval:" + IntToStr( nRet ) +
" MultiPoint:" + IntToStr( nMultiPoint ) +
" Watchdog:" + IntToStr( nWatchdog ) + "ms";
}

void __fastcall TForm1::OnWatchdogWriteButtonClick(TObject *Sender)
{
long nMultiPoint = 11;
long nRet;
long nWatchdog = 1100;
nRet = BKcomOCX1->BK8xWatchDogWriteReq( nMultiPoint, nWatchdog );
DataLabel->Caption ="Retval:" + IntToStr( nRet ) +
" MultiPoint:" + IntToStr( nMultiPoint ) +
" Watchdog:" + IntToStr( nWatchdog ) + "ms";
}

Unpack the example program 'Read/set the coupler watchdog time'.


C++Builder: Demo aller Methoden

KS8000: Examples

C++Builder: Demonstration of all methods

This example involves a more extensive application with which all the available methods can be exercised and tested.

Description

Configure the port number and the MultiPoint address (station address) before you test the available functions. In order to be able to access the coupler's process image, the port must first be opened. The Cyclic ReadWrite ON button can be used to access the coupler's process images cyclically. The method BK8xProcSyncReadWriteReq() is here called cyclically by a multimedia timer.

Unpack the example program 'Demonstration of All Methods'.


Datentypen

KS8000: Reference

Data Types

BkComData

Fully describes a communication port that is either to be opened or that is already open, giving the data handle, baud rate, port number, timeout and BK8x00 type.

struct BkComData{
    HANDLE hCommPort;
    Long nBaudrate;
    Long nPortNum;
    Long nTimeout;
    Long nBKxTyp;
};

Example 1:

// Common initialisation
BkComData tBkComObject = { NULL, Baud_38400, 1l, 2000l, BKxType_RS232 };

Example 2:

// Individual initialisation
BkComData tBkComObject;
tbkComObject.hCommPort = NULL;
tBkComObject.nBaudrate = Baud_38400;
tBkComObject.nPortNum = 1L; 	// COM 1
tBkComObject.nTimeout= 2000l; 	// 2000ms
tBkComObject.nBKxTyp = BKxType_RS232; // BK8100


OpenBkComPort

Opens the serial interface in the manner specified by the structure object.

void OpenBkComPort(
    BkComData *pAnBkCom
);

Parameters

pAnBKCom
[in]
Specifies the COM port and the communication parameters

Example

#include "BkComDll.h"

BkComData tBkComObject = { NULL, Baud_38400, 1l, 2000l, BKxType_RS232 };

if (OpenBkComPort(&tBkComObject) == ComErrNo)
{
// Port has been opened

}

Remark

The settings are specified in the function. Other than the specified baud rate, the other communication parameters are specified as 8 data bits, 1 stop bit and even parity, and cannot be changed.

The BK8x00 Bus Couplers adjust themselves automatically to the specified baud rate. Four attempts at data communication may be needed for this.

The data handle pAnBkCom->hCommPort is set in the function.


CloseBkComPort

Closes the serial interface in the manner specified by the structure object.

void CloseBkComPort(
    BkComData *pAnBkCom
);

Parameters

pAnBKCom
[in]
Specifies the COM port and the communication parameters

Example

#include "BkComDll.h"

BkComData tBkComObject;

// Port is open
CloseBkComPort(&tBkComObject);

Remark

The data handle pAnBkCom->hCommPort is closed and set to null in the function.


BK8xProcSyncReadReq

This is a call for synchronous communication to read the entire input process image of a BK8x00 Bus Coupler.

long BK8xProcSyncReadReq (
    BkComData *pAnBKCom,
    long lMultiPoint,
    long FAR* lStatus,
    long FAR* cwRecLength,
    long FAR* lpRecBuff
);

Parameters

pAnBKCom
[in]
Specifies the COM port and the communication parameters
lMultiPoint
[in]
(1..99) Specifies the recipient
lStatus
[out]
(1..99) Coupler status (see Appendix)

cwRecLength
[out]
Number of words read (a word in a long value) from offset 0 in the input process image

lpRecBuff
[in, out]
Receive buffer, long (array)

Return Values

long
Return code (see Appendix)

Example

#include "BkComDll.h"

BkComData tBkComObject;
long nStatus, nRecLength;long lRecBuf[255];

// Port is open

{ // Process data of the BK8x00 with Multipoint number 2..
if (BK8xProcSyncReadReq( &tBkComObject,
2l,
&nStatus,
&nRecLength,
lRecBuf) == ComErrNo)

// is now in the receive buffer 'lRecBuf'}

Remark

Cf. BK8xProcSyncReadReq for the KS8000-OCX.


BK8xProcSyncReadWriteReq

This is a call for synchronous communication to write the entire output process image and to read the entire input image of a BK8x00 Bus Coupler. The size of the process image read depends on the number and type of terminals plugged into the coupler.

The entire process output image MUST be written. It is not possible to write a partial segment. The transmit and receive buffers are of type Long (32 bits), although only the low word is transmitted to or from the coupler. (see also the KS8000-OCX example)

long BK8xProcSyncReadWriteReq (
    BkComData *pAnBKCom,
    long lMultiPoint,
    long FAR* lStatus,
    long FAR* cwSendLength,
    long FAR* lpSendBuff,
    long FAR* cwRecLength,
    long FAR* lpRecBuff
);

Parameters

pAnBKCom
[in]
Specifies the COM port and the communication parameters
lMultiPoint
[in]
(1..99) Specifies the recipient
lStatus
[out]
(1..99) Coupler status (see Appendix)

cwSendLength
[in]
Number of words to be written (a word in a long value) from offset 0 in the process output image

lpSendBuff
[in]
Transmit buffer, long (array)

cwRecLength
[out]
Number of words read (a word in a long value) from offset 0 in the input process image

lpRecBuff
[in, out]
Receive buffer, long (array)

Return Values

long
Return code (see Appendix)

Example

#include "BkComDll.h"

BkComData tBkComObject;
long nStatus, nSendLength, nRecLength;long lSendBuf[20], lRecBuf[20];

// Port is open

{ // Process data of the BK8x00 with Multipoint number 2..
if (BK8xProcSyncReadWriteReq( &tBkComObject,
2l,
&nStatus,
&nSendLength,
lSendBuf, &nRecLength,
lRecBuf) == ComErrNo)

// is now in the receive buffer 'lRecBuf'}

// The data from 'lSendBuf' is now in the process image

Remark

Cf. BK8xProcSyncReadWriteReq for the KS8000-OCX.


Einbinden der KS8000-DLL in C++

KS8000: Linking the DLL into applications

Linking the DLL in C++

Necessary files

You require the following files to develop the programs:

  • BkComDLL.dll - dynamic function library
  • BkComDLL.lib - link library for the BkComDLL.dll
  • BkComDLL.h – Declarations of the BkCom functions

The files are located in the 'KS8000-Installations\BIN' directory.

Provide the directory for *.h and *.lib files

In the Developer Studio it is necessary to select the command 'Options' under the 'Tools' menu. Select the 'Directories' tab. Under 'Show directories for:' you can enter the path you want to use. Select the 'Include files' option.

Entering the path for header files

There is an empty box at the end of the 'Directories:' list. Click here with the mouse in order to enter the path for the header files.

Entering the path for libraries

Now select the option 'Library files' under 'Show directories for:'. At the end of the list, enter the path to BkComDLL.lib.

Adding BkComDLL.lib to the project

After you have created a project, you must make BkComDLL.lib known to the linker. For this purpose, select the file view of the project.

Choose the 'Settings' command in the 'Project' menu. Select the 'Link' tab.

Add BkComDLL.lib to 'Object/library modules:'.


Beispiel

KS8000: Examples

Example

// BkComExample.cpp : Defines the entry point for the console application.
//
#include "BkComDll.h"

int main()
{
    long nStatus, nSendLength, nRecLength;
    long lSendBuf[20], lRecBuf[20], lRet; int idy, idx;
    char msg[30];

    // Handle , Baudrate 38400, COM 1, 2000ms Timeout, BK8100,
    BkComData aBkComObj = { NULL, Baud_38400, 2l, 2000l, BKxType_RS232 };

    if (!OpenBkComPort(&aBkComObj))
    {
        nSendLength = 1; 		// write one process image word
        nRecLength = 1;		// read first process image word
        // Generate running light
        for (idy = 0; idy <= 1000; idy++)
        {
            for(idx = 0; idx <= 20; idx++)
            {
                lSendBuf[idx] = lSendBuf[idx] + 1;
                if (lSendBuf[idx] > 10000)
                    lSendBuf[idx] = 0;
            }
            // Multipoint = 2
            lRet = BK8xProcSyncReadWriteReq(	&aBkComObj,
                            2l,
                            &nStatus,
                            nSendLength,
                            lSendBuf,
                            &nRecLength,
                            lRecBuf);
            if (lRet != 0)
            {
                sprintf(msg, "\nFehler: %ld\n", lRet);
                MessageBox(NULL, msg, "Read Write COM-Port", MB_OK |MB_ICONEXCLAMATION);
            }
        }
    }
    CloseBkComPort(&aBkComObj);
    return 0;
}

Unpack the example code 'VC++: KS8000 DLL - Synchronous writing/reading of the process data'


BK8xProcSyncReadWriteReq

KS8000

Overview

LabVIEW

The LabVIEW graphical programming system from National Instruments supports the creation of applications without the need to write large amounts of program text. Programming is achieved through the selection, insertion and linking of graphical symbols into what are known as block diagrams, using a mouse. LabVIEW programs are called virtual instruments, or VI for short.

More extensive information on use and programming can be found in the LabVIEW manuals.

SubVI – LabVIEW Subroutines

The LabVIEW subroutine concept allows one VI to be linked into another VI as a so-called SubVI. It is important to note the arbitrary possibilities for creating hierarchies, there being no quantitative limit on the nesting depth of VIs. Thus a SubVI can itself contain any number of other SubVIs.

SubVIs are analogous to the subroutines of classical programming languages, and can both receive values and return them (parameterisation).

When using them in a VI it must be noted, that SubVIs of the same name always represent just one instance, regardless of the number and location of VIs into which it is linked as a SubVI. This means that such linked SubVIs are in fact merely references to one original VI, and therefore has only one data region available to it.

If a SubVI needs to remember particular data or states, it is therefore necessary that each such SubVI is copied under a new name before linking. This procedure must be followed when using the BkComLV VIs in your own VIs.

The BkComLV VIs

The BkComLV consists of four independent VIs:

  • Open-BkComLV
  • Close-BkComLV
  • Read-BkComLV
  • ReadWrite-BkComLV

It is easy to make use of these VIs as SubVIs in your own VI, thus linking in the BkCom DLL functionality from a LabVIEW program.

More detailed information on the mode of operation and area of application of the BkCom DLL is found in the help files for KS8000-Ocx.

The BkComLV DLL supplied should be installed for the operation of BkComLV.


Einbinden der LabView-DLL in LabView

KS8000

Linking the LabView DLL in LabView

The general procedure for creating a LabVIEW VI including a BkComLV-VI is illustrated in what follows.

  • Depending on the number of communication ports which are to be opened, the Open-BkComLV and Close-BkComLV VIs must be copied correspondingly often, renaming them in accordance with their purpose. Original copies are located in the 'KS8000-Install\LabView' directory.
  • Depending on the number of read and write functions to be located in the process images of BK8x00 Bus Couplers, the corresponding number of copies of the 'Read-BkComLV' and 'Read Write-BkComLV' VIs must be made, renamed again in accordance with their purpose.
  • From the function palette, using 'Select User VI', select the copied BkComLV VI and place it into your own block diagram.
  • Create suitable LabVIEW variables (controls and indicators) on the front panel of your own VI (see the BkComLV-VI input and output data), and wire them to the nodes of the BkComLV SubVI.


Open-BkComLV

KS8000: KS8000LV Reference

Open-BkComLV-VI

Opens the serial interface.

The Open-BkComLV.vi opens the given communication port and returns a handle to it.

Input data

Baud rate
Long Control
Value range { 9600, 19200, 38400 }
CommPort
Long Control
Value range { 1, : , n }
Timeout
Long Control
Time in milliseconds, value range { 0, N }
BkxTyp
Long Control
Konstante: BkxTyp = { 1, // BK8000 2 // BK8100 }

Remark: All input parameters are required.

Output data

BkcomHandle - Long Indicator
Value range: BkcomHandle – unique number <> 0


Close-BkComLV

KS8000: KS8000LV Reference

Close-BkComLV-VI

Closes the serial interface.

The Close-BkComLV.vi closes the given communication port.

Input data

BkcomHandle - Long Indicator
Value range: BkcomHandle – unique number <> 0

Remark: All input parameters are required.

Output data

None


Read-BkComLV

KS8000: KS8000LV Reference

Read-BkComLV-VI

Reads process data from the serial interface.

Read-BkComLV.vi is a call for synchronous communications to read out the entire input process image of a BK8x00 Bus Coupler.

The size of the process image depends on the number and type of terminals plugged into the coupler. Although the receive buffer is of type long (32 bits), the coupler only transfers data in the low word (see also the BkComOCX example).

Input data

Multipoint
Long Control
Value range: Station address of the Bus Coupler
Status
Long Control
Value range: irrelevant, standard value 0
Record length
Long Control
Value range: irrelevant, standard value 0
Record buffer
One-dimensional array of long controls
Value range: irrelevant, standard value 0

ControlsBkcomHandle
Long Control
Value range: BkcomHandle – unique number <> 0

ControlReturnValue
Long Control
Value range: irrelevant, standard value 0

Remark:
Irrelevant means that the value supplied has no effect on the function. It is however necessary to supply it, in order to make the type and size known, so that the output data are returned correctly.

Output data

Multipoint copy
Long Indicator
Value range: Station address of the Bus Coupler
Status (written)
Long Indicator
Value range: State of the Bus Coupler
Record length (Written)
Long Indicator
Value range: Number of process data items read
Record buffer (Written)
One-dimensional array of long indicators
Value range: Process values read

ControlsBkcomHandle copy
Long Indicator
Value range: BkcomHandle – unique number <> 0 which must originate from an open BkComLV.vi

ControlReturnValue (written)
Long Indicator
Value range: 0 OK, ... <> 0 error


ReadWreite-BkComLV

KS8000: KS8000LV Reference

ReadWrite-BkComLV-VI

Writes and reads process data through the serial interface.

Read Write-BkComLV.vi is a call for synchronous communications to write the whole output process image and to read out the entire input process image of a BK8x00 Bus Coupler. The size of the process image read depends on the number and type of terminals plugged into the coupler.

The entire process output image MUST be written. It is not possible to write a partial segment.

Although the send and receive buffers are of type long (32 bits), the coupler only transfers data in/from the low word (see also the BkComOCX example).

Input data

Multipoint
Long Control
Value range: Station address of the Bus Coupler
Status
Long Control
Value range: irrelevant, standard value 0
Send length
Long Control
Value range: Number of words to be written (a word in a long value) from offset 0 in the process output image
Transmit buffer
One-dimensional array of long controls
Value range: Data words to be sent
Record length
Long Control
Value range: irrelevant, standard value 0
Record buffer
One-dimensional array of long controls
Value range: irrelevant, standard value 0

ControlsBkcomHandle
Long Control
Value range: BkcomHandle – unique number <> 0

ControlReturnValue
Long Control
Value range: irrelevant, standard value 0

Remark:
Irrelevant means that the value supplied has no effect on the function. It is however necessary to supply it, in order to make the type and size known, so that the output data are returned correctly.

Output data

Multipoint copy
Long Indicator
Value range: Station address of the Bus Coupler
Status (written)
Long Indicator
Value range: State of the Bus Coupler
Record length (Written)
Long Indicator
Value range: Number of process data items read
Record buffer (Written)
One-dimensional array of long indicators
Value range: Process values read

ControlsBkcomHandle copy
Long Indicator
Value range: BkcomHandle – unique number <> 0 which must originate from an open BkComLV.vi

ControlReturnValue (written)
Long Indicator
Value range: 0 OK, ... <> 0 error


Beispiele

KS8000: Examples

Examples

General

In preparation, one or two Bk8x00 Bus Couplers with at least 3 digital output terminals (e.g. KL2012) must be inserted. More input terminals can, optionally, be plugged in behind. The Bus Couplers are to be connected to the COM port(s). The correct port number and the station number of the couplers (Multipoint) must be entered into the example VI.

All examples are started from LabVIEW by 'Run' (Ctrl+r), and are properly ended by turning the program switch to 'End'.

If the test is successful, a 'running light' effect is to be seen at the output terminals. Signals asserted at the input terminals must lead to an alteration in the values in the corresponding record buffer arrays.

The following examples are available:

Description Source text
Example 1:

Running light effect runs through a communication port, a Bus Coupler in a VI: BkcomLVCompleteSubVI.vi

 OnePort
Example 2:

Running light effect runs through two communication ports, two Bus Couplers in a VI: DblBKcomLVCompleteSubVI.vi.

 TwoPort
Example 3:

The effect operates via two communication ports, two Bus Couplers in two VIs to be opened simultaneously: BKcomLVCompleteSubVI_1.vi and BKcomLVCompleteSubVI_2.vi.

 OneAndOnePort


Anhang

KS8000:

Appendix

BkComBkxType

enum BkComBKxType
{
    BkxType_RS485 = 1, // BK8000
    BkxType_RS232 = 2 // BK8100
};

BkComBaud

enum BkComBaud
{
    Baud_9600 = 9600,
    Baud_19200 = 19200,
    Baud_38400 = 38400
};

BkComErr

enum BkComErr
{
    ComErrNotImplemented = -1,	// Function is not implemented
    ComErrNo = 0,		// No error
    ComErrTimeout1 = 1,	// Timeout: no reaction from the coupler
    ComErrTimeout2 = 2,	// Timeout: No complete communication with the coupler
    ComErrCRC = 3,		// Incorrect checksum in communication
    ComErrTargetNr = 4,
    ComErrTableNr = 5,
    ComErrOffset = 6,
    ComErrDataLength = 7,
    ComErrMultipoint = 8,
    ComErrDataBuff = 9,
    ComErrStartPattern = 10,	// Incorrect telegram header in coupler response telegram
    ComErrSendTel = 11,	// Error during writing to serial PC interface
    ComErrIdent = 12,
    ComErrRegResponse = 13,	// The error flag is set in the coupler's response telegram
    ComErrHexFileFault = 14,
    ComErrChecksumFault = 15,
    ComErrAddressMappingFault = 16,
    ComErrFaultInByte = 17,
    ComErrWrongAck = 18,
    ComErrWrongBtlAck = 19,
    ComErrReadBackFault = 20
};

Coupler status

Bit	0 : Terminal bus error
Bit	1 : Configuration error
Bit	2 :
Bit	3 :
Bit	4 : Output process data: error in the length to be written
Bit	5 :
Bit	6 :
Bit	7 :