Herunterladen Diese Seite drucken

Daten Lesen Mit Mtcx Kommando - B&R PC 300 Implementierungsanleitung

Vorschau ausblenden Andere Handbücher für PC 300:

Werbung

Panel PC 300
Implementierungsanleitung

7.2.6 Daten lesen mit MTCX Kommando

Mit dieser Funktion wird ein MTCX Kommando zum Lesen von Daten abgesetzt. Diese Funktion wird in
weiteren Codebeispielen aufgerufen.
// Read data via MTCX command.
//
// Parameters
//
Command
//
[in] Specifies the command code (see MTCX_CMD_x constants).
//
Addr
//
[in] Specifies the address (depends on command).
//
DevNum
//
[in] Specifies the device number (see MTCX_DEVNUM_x constants).
//
Target
//
[in] Specifies the target device (see MTCX_DEV_x constants).
//
Data
//
[out] Points to a buffer that receives the
//
command data. Can be NULL if no data is required.
//
Size
//
[in] Specifies the data size in bytes: 0 to 16.
//
ErrorCode
//
[out] Points to a variable that receives the
//
command error when the function returns with
//
MTCX_FAIL_COMMAND (see MTCX_ERR_x constants).
//
// Return MTCX_OKAY at success and MTCX_FAIL_x at failure.
int MtcxReadCommand(unsigned int Command,
{
int retvalue;
if (Size > MTCX_CMD_DATA_SIZE)
return MTCX_FAIL_PARAM;
// TODO: acquire command synchronization object here
//
(if multiple commands can be requested parallel)
retvalue = MtcxSetCommand(MTCX_DIR_READ, Command, Addr, DevNum, Target, 0, 0);
if (retvalue == MTCX_OKAY)
{
retvalue = MtcxWaitForCommandResponse(ErrorCode);
if (retvalue == MTCX_OKAY)
{
int Port = MTCX_CMD_DATA0_ADDR;
unsigned char *p = (unsigned char *)Data;
while (Size-- > 0)
*p++ = READ_PORT_UCHAR(Port++);
}
MtcxUnlockCommand();
}
// TODO: release command synchronization object here
return retvalue;
}
Listing 11: MtcxReadCommand – Daten lesen mit MTCX Kommando
Die verwendeten Definitionen finden Sie auf Seite 42.
Copyright © B&R - Änderungen vorbehalten
PPC300_Implementierungsanleitung_V1_02.doc
unsigned int Addr,
unsigned int DevNum,
unsigned int Target,
void *Data,
unsigned int Size,
unsigned char *ErrorCode)
Codebeispiele
02.11.09
55/132

Werbung

loading