📄 fms_d16.c
字号:
/* <St> ***********************************************************************
FILENAME : FDS_D16.C
-----------------------------------------------------------------------------
DEVELOPER : Uwe Zeier
PROJEKT : Device Driver for CIF boards
=============================================================================
DISCRIPTION
16 Bit demo program useing a CIF board with an FMS-interface
This source code demonstrates how to run a message transfer.
The program uses board number 0.
=============================================================================
CHANGES
Version Name Date Discription
-----------------------------------------------------------------------------
V 1.001 MY 09.07.99 Changed to 16 BIT
V 1.000 HH 14.05.98 Created from DEMO.c
************************************************************************ <En> */
/* **************************************************************************** */
/* Include */
/* **************************************************************************** */
#include <Windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cifuser.h" /* Include file for 16 Bit driver functions */
#include "rcs_user.h" /* Include file for RCS API definition */
#include "fms_user.h" /* Include file for FMS definition */
#define DPM_ADDRESS 0xCA000000L /* Physical memory address */
#define DPM_SIZE 8 /* Dual Port Memory size */
/* **************************************************************************** */
/* Mainprogram */
/* **************************************************************************** */
int main(int argc, char *argv[] )
{
unsigned short usBoardNumber = 0; /* Board number */
long lBoardAddress = DPM_ADDRESS;
unsigned short usDevState, usHostState;
unsigned short usIdx;
unsigned char abTemp[30]; /* Temporary buffer */
unsigned char abInfo[300]; /* Buffer for various information */
short sRet; /* Return value */
unsigned short usObjIdx = 100;
BOOL fSendAgain;
int iUserKey;
/* Data structure for message based communication */
RCS_MESSAGETELEGRAM_10 tMessage;
/* Load delivered parameter */
for ( usIdx = 1; usIdx < (unsigned short)argc; usIdx++)
{
strupr( argv[usIdx]);
/* Load pointer to DPM */
if ( strncmp( argv[usIdx], "/B:", 3) == 0 )
{
/* Load BoardNumber */
if ( sscanf( argv[usIdx], "/B:%01X", &usBoardNumber) >= MAX_DEV_BOARDS )
{
printf("\nError : wrong BOARD number (0..3)\n");
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Wait for user response */
printf( "\nPress RETURN to continue .... \n");
getchar();
exit(0);
}
}
}
printf( "HILSCHER GmbH - Communication test program \n\n");
printf( "\n*** Open communication driver ***\n");
printf( "*** Board number: %1d ***\n", usBoardNumber);
printf( "*** DPM address : 0xCA000000 ***\n");
printf( "*** DPM size : %1d ***\n\n", DPM_SIZE);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Open the driver */
if ( (sRet = DevOpenDriver(usBoardNumber)) != DRV_NO_ERROR) {
printf( "DevOpenDriver RetWert = %5d \n", sRet );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Initialize board */
} else if ( (sRet = DevInitBoardEx ( usBoardNumber,
(void *)DPM_ADDRESS,
DPM_SIZE)) != DRV_NO_ERROR) {
printf( "DevInitBoard RetWert = %5d \n", sRet );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Read Firmware information field */
} else if ( (sRet = DevGetInfo( usBoardNumber, /* DeviceNumber */
GET_FIRMWARE_INFO, /* InfoArea */
sizeof(FIRMWAREINFO), /* Size of bytes to read */
&abInfo[0])) != DRV_NO_ERROR ) { /* Pointer to user buffer */
printf( "DevGetInfo (GET_FIRMWARE_INFO) RetWert = %5d \n", sRet );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Signal board, application is running */
} else if ( (sRet = DevSetHostState( usBoardNumber, /* DeviceNumber */
HOST_READY, /* Mode */
0L)) != DRV_NO_ERROR ) { /* Pointer to user buffer */
printf( "DevSetHostState (HOST_READY) RetWert = %5d \n", sRet );
} else {
/* Print firmware information */
memcpy ( &abTemp, &abInfo[0], 16);
abTemp[16] = 0;
printf( " FirmwareName: %s\n", &abTemp[0] );
memcpy ( &abTemp, &abInfo[16], 16);
abTemp[16] = 0;
printf( " FirmwareVersion: %s\n", &abTemp[0]);
printf( "\n\n" );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Read mailbox information */
if ( (sRet = DevGetMBXState( usBoardNumber, /* DeviceNumber */
&usDevState, /* Buffer for device state */
&usHostState)) != DRV_NO_ERROR ) {/* Buffer for host state */
/* function error */
printf( "DevGetMBXState RetWert = %5d\n", sRet );
} else {
/* show actual state */
printf( "DevGetMBXState device MBX state = %5d (0=empty, 1=full)\n", usDevState);
printf( "DevGetMBXState host MBX state = %5d (0=empty, 1=full)\n", usHostState);
}
/* Reset board */
sRet = DevReset( usBoardNumber, /* Device number */
WARMSTART, /* Reset mode, Warmstart */
8000L); /* Timeout 8000 ms */
printf( "DevResetBoard RetWert = %5d \n", sRet );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Wait for user response */
printf( "\nPress RETURN to continue .... \n");
getchar();
do {
fSendAgain = FALSE;
/*===========================================================================*/
/* Test message transfer */
/*===========================================================================*/
/* Build a message */
tMessage.rx = ALI;
tMessage.tx = USER;
tMessage.ln = RCS_TELEGRAMHEADER_LEN;
tMessage.nr = 1;
tMessage.a = 0;
tMessage.f = 0;
tMessage.b = TASK_B_11;
tMessage.e = 0x00;
tMessage.device_adr = 1; /* Communication Reference */
tMessage.data_area = 0; /* not used */
tMessage.data_adr = usObjIdx; /* Object Index */
tMessage.data_idx = 0; /* Subindex 0 (0=complete object) */
tMessage.data_cnt = 1; /* Data Count */
tMessage.data_type = TASK_TDT_UINT16; /* Data Type */
tMessage.function = TASK_TFC_READ; /* Read Service */
sRet = DevPutMessage ( usBoardNumber, /* Device Number */
(MSG_STRUC *)&tMessage, /* Pointer to user buffer */
5000L ); /* Timeout */
printf( " DevPutMessage RetWert = %5d \n", sRet );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Wait for user response */
printf( "\nPress RETURN to continue .... \n");
getchar();
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Tray to read a message */
printf( " DevGetMessage Wait for a maximum of %ld ms\n", 20000L );
sRet = DevGetMessage ( 0, /* Device Number */
sizeof(tMessage), /* Users buffer size */
(MSG_STRUC *)&tMessage, /* Pointer to user buffer */
20000L ); /* Timeout */
printf( " DevGetMessage RetWert = %5d \n", sRet );
if ( sRet == DRV_NO_ERROR) {
/* Message available */
printf( " RX: 0x%02X, TX: 0x%02X, LN: 0x%02X, NR: 0x%02X \n",
tMessage.rx,
tMessage.tx,
tMessage.ln,
tMessage.nr );
printf( " A: 0x%02X, F: 0x%02X, B: 0x%02X, E: 0x%02X \n",
tMessage.a,
tMessage.f,
tMessage.b,
tMessage.e );
if ( tMessage.f == 0 ) {
printf( " ALI_OK: No error \n" );
printf( " Object index %d Value %5d \n",
usObjIdx, *(unsigned short*)(&tMessage.d[0]) );
printf( "\n Read again ? (Y/N):" );
iUserKey = getchar();
if ( iUserKey == 'y' || iUserKey == 'Y') fSendAgain = TRUE;
}
else if ( tMessage.f >= 1 && tMessage.f <= ALI_TEMPORARY_ERR ) {
printf( " ALI_TEMPORARY_ERR: Temporary error. Reactivate last service.\n" );
printf( "\n Activate Service Again? (Y/N):" );
iUserKey = getchar();
if ( iUserKey == 'y' || iUserKey == 'Y') fSendAgain = TRUE;
}
else if ( tMessage.f > ALI_TEMPORARY_ERR && tMessage.f <= ALI_RECOVERY_ERR ) {
printf( " ALI_RECOVERY_ERR: Recovery Error. Send abort.\n" );
}
else if ( tMessage.f > ALI_RECOVERY_ERR && tMessage.f <= ALI_MESSGAE_ERR ) {
printf( " ALI_MESSGAE_ERR: Message Error. Check the message.\n" );
}
else {
printf( " Other Error (system error)\n" );
}
} /* endif */
} while (fSendAgain == TRUE);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Wait for user response */
printf( "\nPress RETURN to continue .... \n");
getchar();
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Signal board, application is not running */
if ( (sRet = DevSetHostState( usBoardNumber, /* DeviceNumber */
HOST_NOT_READY, /* Mode */
0L)) != DRV_NO_ERROR ) { /* Pointer to user buffer */
printf( "DevSetHostState (HOST_NOT_READY) RetWert = %5d \n", sRet );
}
printf( "\n*** Close communication driver ***\n\n");
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Close communication */
sRet = DevExitBoard( usBoardNumber); /* Device number */
printf( "DevExitBoard RetWert = %5d \n", sRet );
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Close Driver */
sRet = DevCloseDriver(0);
printf( "DevCloseDriver RetWert = %5d \n", sRet );
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Wait for user response */
printf( "\n\nPress RETURN to end program .... \n");
getchar();
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -