Reading IP Serial numbers
This sample illustrates access to the serial number of the IPCs and the serial number of the IPC's mainboard.
- The serial number of the mainboard can be read via a subindex in module Mainboard in the Configuration Area of the IPC diagnostics. The general function block FB_MDP_ReadElement is used for this purpose
- The serial number of the IPC can be read via index 0xF9F0 in the Device Area of the IPC diagnostics. The general function block FB_MDP_ReadIndex is used for this purpose.
Sample: querying the serial number of a Beckhoff IPC
Enumeration definition
(* central definition of state machine states *)
TYPE E_State :
(
Idle,
ReadSnoMainboardInit,
ReadSnoMainboardProcess,
ReadSnoIPCInit,
ReadSnoIPCProcess
);
END_TYPE
Variable declaration
PROGRAM MAIN
VAR
sAmsNetId : STRING := ''; (* ADS Net ID (local = '') *)
eState : E_State; (* Enum with index for state machine *)
bStart : BOOL := TRUE; (* flag to trigger restart of statemachine *)
sData : STRING; (* data storage for string variable *)
stMDP_Addr : ST_MDP_Addr; (* structure which will include all address parameters *)
(* FB instances *)
fbReadMDPElement : FB_MDP_ReadElement;
fbReadMDPIndex : FB_MDP_ReadIndex;
(* results of execution *)
bError : BOOL; (* error flag *)
nErrID : UDINT; (* last error ID *)
sSerialNoMainboard : STRING; (* buffer for serial number of mainboard *)
sSerialNoIPC : STRING; (* buffer for serial number of IPC *)
END_VAR
Program code
CASE eState OF
Idle:
IF bStart THEN
bStart := FALSE;
eState := ReadSnoMainboardInit; (* initiate first state *
END_IF
(* read serial number of mainboard ************************************************************** *)
ReadSnoMainboardInit:
sData := ''; (* clear data buffer *)
sSerialNoMainboard := ''; (* clear buffer for serial number of mainboard *)
stMDP_Addr.nArea := INT_TO_BYTE(eMDP_Area_ConfigArea); (* set area address to "Config Area" *)
stMDP_Addr.nTableId := 1; (* table ID in index for "mainboard information" *)
stMDP_Addr.nSubIdx := 2; (* subindex in table ID for "serial number" *)
fbReadMDPElement(
bExecute := TRUE,
eModuleType := eMDP_ModT_Mainboard,
stMDP_Addr := stMDP_Addr, (* MDP address structure. Dynamic module ID will be added internally. *)
iModIdx := 0, (* Instance of desired module type (default: 0 = first instance) *)
pDstBuf := ADR(sData),
cbDstBufLen := SIZEOF(sData),
sAmsNetId := sAmsNetId,
);
eState := ReadSnoMainboardProcess;
ReadSnoMainboardProcess:
fbReadMDPElement(bExecute := FALSE);
IF NOT fbReadMDPElement.bBusy THEN
IF fbReadMDPElement.bError THEN
bError := TRUE; (* set error flag *)
nErrID := fbReadMDPElement.nErrID; (* store error id (16#ECA60105 = BIOS or HW does not support this data (here: mainboard data)) *)
eState := Idle;
ELSE (* set parameters for next steps *)
bError := FALSE; (* turn off error flag *)
sSerialNoMainboard := sData; (* store serial number of mainboard in dedicated variable *)
eState := ReadSnoIPCInit;
END_IF
END_IF
(* read serial number of IPC ************************************************************** *)
ReadSnoIPCInit:
sData := ''; (* clear data buffer *)
sSerialNoIPC := ''; (* clear buffer for serial number of IPC *)
fbReadMDPIndex(
bExecute := TRUE,
nIndex := 16#F9F0, (* index: read serial number IPC (-> see docu 'MDP device area') *)
nSubIndex := 0, (* first subdindex (there is only one available for index 16#F9F0) *)
pDstBuf := ADR(sData), cbDstBufLen := SIZEOF(sData),
sAmsNetId := sAmsNetId,
);
eState := ReadSnoIPCProcess;
ReadSnoIPCProcess:
fbReadMDPIndex(bExecute := FALSE);
IF NOT fbReadMDPIndex.bBusy THEN
IF fbReadMDPIndex.bError THEN
bError := TRUE; (* set error flag *)
nErrID := fbReadMDPIndex.nErrID; (* store error id (16#ECA60105 = BIOS or HW does not support this data (here: IPC serial number)) *)
eState := Idle;
ELSE (* set parameters for next steps *)
bError := FALSE; (* turn off error flag *)
sSerialNoIPC := sData; (* store serial number of mainboard *)
eState := Idle;
END_IF
END_IF
END_CASE
Returning of the mainboard serial number instead of the IPC serial number
In older BIOS version (before Q4/2013) the serial number was not stored in the IPC BIOS. In these cases the return value is the serial number of the IPC mainboard. With older Beckhoff Automation Device Driver versions, the return value is also the serial number of the IPC mainboard. The serial number of the IPC mainboard can always be read via the mainboard module.