Herunterladen Diese Seite drucken

B&R PC 300 Implementierungsanleitung Seite 53

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

Werbung

Panel PC 300
Implementierungsanleitung
}
// Lock command interface.
if (! MtcxLockCommand())
return MTCX_FAIL_LOCKED;
// Write command data.
if (Data && Size)
{
int Port = MTCX_CMD_DATA0_ADDR;
unsigned char *p = (unsigned char*)Data;
while (Size-- > 0)
WRITE_PORT_UCHAR(Port++, *p++);
}
// Write command parameters.
param.Dir = Dir;
param.Command = Command;
param.Addr = Addr;
param.DevNum = DevNum;
param.Target = Target;
WRITE_PORT_ULONG(MTCX_CMD_PARAM_ADDR, *(unsigned long*)&param);
return MTCX_OKAY;
}
// Read the command status and error code.
//
// Parameters
//
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, MTCX_WORKING if the
// command interface is busy and MTCX_FAIL_x at failure.
int MtcxGetCommandStatus(unsigned char *ErrorCode)
{
int retvalue;
unsigned char regbyte;
regbyte = READ_PORT_UCHAR(MTCX_CMD_STATUS_ADDR + 1); // read byte 1 only
retvalue = MTCX_WORKING;
switch (((MTCX_CMD_STATUS_REG_BYTE1*)&regbyte)->Status)
{
case 0x01:
retvalue = MTCX_OKAY;
break;
case 0x03:
retvalue = MTCX_FAIL_COMMAND;
break;
}
*ErrorCode = READ_PORT_UCHAR(MTCX_CMD_STATUS_ADDR); // read byte 0 only
return retvalue;
}
// Wait for command response.
//
// Parameters
//
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 MtcxWaitForCommandResponse(unsigned char *ErrorCode)
{
int retvalue;
Copyright © B&R - Änderungen vorbehalten
PPC300_Implementierungsanleitung_V1_02.doc
Codebeispiele
02.11.09
53/132

Werbung

loading