WriteStruct
This method creates a record with a freely selectable table structure.
Syntax
METHOD WriteStruct : BOOL
VAR_INPUT
hDBID: UDINT;
sTableName: T_MaxString;
pRecord: POINTER TO BYTE;
cbRecord: UDINT;
pColumnNames: POINTER TO ARRAY [0..MAX_DBCOLUMNS] OF STRING(50);
cbColumnNames: UDINT;
END_VAR
Inputs
Name | Type | Description |
---|---|---|
hDBID | UDINT | Indicates the ID of the database to be used. |
sTableName | T_MaxString | Name of the table that is to be read. |
pRecord | POINTER TO BYTE | Address of a structure that is to be logged in a freely selectable table structure. |
cbRecord | UDINT | Length of the structure to be written |
pColumnNames | POINTER TO ARRAY [0..MAX_DBCOLUMNS] OF STRING(50) | Address of the array containing the column name to be filled. |
cbColumnNames | UDINT | Length of the column name array |
Return value
Name | Type | Description |
---|---|---|
WriteStruct | BOOL | Displays the status of the method. Returns TRUE as soon as the method execution is finished, even in the event of an error. |
Sample
This sample shows how to use the method FB_PLCDBWriteEvt.WriteStruct:
VAR
fbPLCDBWrite : FB_PLCDBWriteEvt(sNetID := '', tTimeout := T#5S);
myRecord : ST_Record;
ColumnNames : ARRAY[0..4] OF STRING(50);
systime : GETSYSTEMTIME;
currentTime : T_FILETIME;
tcMessage : I_TcMessage;
END_VAR
TYPE ST_Record :
STRUCT
nID : LINT;
dtTimestamp: DATE_AND_TIME;
sName : STRING;
nSensor1 : LREAL;
nSensor2 : LREAL;
END_STRUCT
END_TYPE
// set Values
systime(timeLoDw => currentTime.dwLowDateTime, timeHiDW => currentTime.dwHighDateTime );
myRecord.dtTimestamp := FILETIME_TO_DT(currentTime);
myRecord.sName := 'MyStructVal';
myRecord.nSensor1 := 12.34;
myRecord.nSensor2 := 102.5;
// set columnnames
ColumnNames[0] := 'ID';
ColumnNames[1] := 'Timestamp';
ColumnNames[2] := 'Name';
ColumnNames[3] := 'Sensor1';
ColumnNames[4] := 'Sensor2';
// Call Functionblock
IF fbPLCDBWrite.WriteStruct(
hDBID:= 1,
sTableName:= 'myTable_Struct',
pRecord:= ADR(myRecord),
cbRecord:= SIZEOF(myRecord),
pColumnNames:= ADR(ColumnNames) ,
cbColumnNames:= SIZEOF(ColumnNames))
THEN
IF fbPLCDBWrite.bError THEN
tcMessage := fbPLCDBWrite.ipTcResult;
nState := 255;
ELSE
nState := 0;
END_IF
END_IF
Result in the database:
ID | Timestamp | Name | Sensor1 | Sensor2 |
---|---|---|---|---|
5 | '2018-01-30 15:23:26' | ‘MyStructVal’ | 12.34 | 102.5 |