rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Public Attributes | Private Attributes | List of all members
rlHilscherCIF Class Reference

#include <rlhilschercif.h>

Collaboration diagram for rlHilscherCIF:
Collaboration graph
[legend]

Public Member Functions

 rlHilscherCIF ()
 
virtual ~rlHilscherCIF ()
 
int open ()
 
int close ()
 
int devGetMessage (int timeout)
 
int devPutMessage (int timeout)
 
int devExchangeIO (int sendOffset, int sendSize, unsigned char *sendData, int receiveOffset, int receiveSize, unsigned char *receiveData, int timeout)
 
int devOpenDriver ()
 
int devInitBoard ()
 
int devGetInfo (int info)
 
int devSetHostState (int mode)
 
int devPutTaskParameter ()
 
int devReset ()
 
int devExitBoard ()
 
int devCloseDriver ()
 
void printFirmwareInfo ()
 

Public Attributes

int debug
 
unsigned short usBoardNumber
 
unsigned short usDevState
 
unsigned short usHostState
 
unsigned char abInfo [300]
 
ASC_PARAMETER aParameter
 
IOINFO tIoInfo
 
RCS_MESSAGETELEGRAM_10 tMessage
 
rlMutex mutex
 

Private Attributes

int isOpen
 

Detailed Description

This class is for data access to Hilscher CIF cards
like PROFIBUS ...
It uses the driver provided by Hilscher and has access to it's dual ported RAM.
Attention: In order to use this class on Linux as normal user you have to set
chmod ugoa+rw /dev/cif

Definition at line 38 of file rlhilschercif.h.

Constructor & Destructor Documentation

rlHilscherCIF::rlHilscherCIF ( )

Definition at line 24 of file rlhilschercif.cpp.

{
debug = 0;
isOpen = 0;
usBoardNumber = 0; // Board number, 0-3
// Fill in protokoll parameters
aParameter.bScl = 1; /* Interface number */
aParameter.bRtsControl = 0; /* Bus handling */
aParameter.bBaudrate = 10; /* Baud rate */
aParameter.bDataBits = 8; /* Number of data bits */
aParameter.bStopBits = 1; /* Number of stop bits */
aParameter.bParityBit = 1; /* Parity */
aParameter.bMode = 1; /* Interface mode */
aParameter.bEndMode = 0; /* Stop mod */
aParameter.bCheckMode = 0; /* Checksum mode */
aParameter.bCheckArea = 0; /* Checksum area */
aParameter.bFilterMode = 0; /* Character filter mode */
aParameter.usFilterCharacter = 0; /* Characters */
aParameter.usTelTimeout = 1000; /* Telegram timeout */
aParameter.usStartTimeout = 0; /* Start timeout */
aParameter.usCharTimeout = 0; /* Character timeout */
aParameter.bRetries = 0; /* Retray number */
aParameter.bErrorLed = 1; /* Error LED */
aParameter.bTelStartLen = 0; /* Length of telegram start */
aParameter.bTelStart[0] = 0; /* Telegram beginning */
aParameter.bTelEndLen = 0; /* Length of telegram end */
aParameter.bTelEnd[0] = 0; /* Telegram end */
aParameter.bTelAckLen = 0; /* Length of ACK telegram */
aParameter.bTelAck[0] = 0; /* ACK telegramm */
aParameter.bTelNackLen = 0; /* Length of NAK telegram */
aParameter.bTelNack[0] = 0; /* NAK telegram */
aParameter.bTelDeviceLen = 0; /* Length of the device telegram */
tMessage.rx = 0x0ff;
}
rlHilscherCIF::~rlHilscherCIF ( )
virtual

Definition at line 61 of file rlhilschercif.cpp.

{
if(isOpen) close();
}

Member Function Documentation

int rlHilscherCIF::close ( )

Definition at line 81 of file rlhilschercif.cpp.

{
int ret;
isOpen = 0;
if((ret = devSetHostState(HOST_NOT_READY)) != DRV_NO_ERROR) return ret;
ret = devCloseDriver();
return ret;
}
int rlHilscherCIF::devCloseDriver ( )

Definition at line 198 of file rlhilschercif.cpp.

{
isOpen = 0;
#ifdef RLUNIX
int ret = DevCloseDriver();
#else
int ret = DevCloseDriver(usBoardNumber);
#endif
if(debug) printf( "DevCloseDriver ret=%d\n", ret);
return ret;
}
int rlHilscherCIF::devExchangeIO ( int  sendOffset,
int  sendSize,
unsigned char *  sendData,
int  receiveOffset,
int  receiveSize,
unsigned char *  receiveData,
int  timeout 
)

Definition at line 260 of file rlhilschercif.cpp.

{
if(isOpen == 0)
{
printf("rlHilscherCIF::devExchangeIO ERROR device is not open\n");
return -1;
}
// Run ExchangeIO
int ret = DevExchangeIO(usBoardNumber,
(unsigned short) sendOffset,
(unsigned short) sendSize,
sendData,
(unsigned short) receiveOffset,
(unsigned short) receiveSize,
receiveData,
timeout);
if(ret != DRV_NO_ERROR)
{
if(debug) printf("DevExchangeIO ret=%d timeout\n", ret);
}
else
{
// Data exchange is done, print some information
if(debug && sendSize >= 4 && receiveSize >= 4)
{
printf(" ExchangeIO data:\n"
" Send data: Receive data\n");
printf(" byte 0 : %d byte 0 : %d\n", sendData[0],receiveData[0]);
printf(" byte 1 : %d byte 1 : %d\n", sendData[1],receiveData[1]);
printf(" byte 2 : %d byte 2 : %d\n", sendData[2],receiveData[2]);
printf(" byte 3 : %d byte 3 : %d\n", sendData[3],receiveData[3]);
}
}
return ret;
}
int rlHilscherCIF::devExitBoard ( )

Definition at line 191 of file rlhilschercif.cpp.

{
int ret = DevExitBoard(usBoardNumber);
if(debug) printf("DevExitBoard ret=%d \n", ret);
return ret;
}
int rlHilscherCIF::devGetInfo ( int  info)

Definition at line 113 of file rlhilschercif.cpp.

{
if(info == GET_FIRMWARE_INFO)
{
int ret = DevGetInfo(usBoardNumber,
GET_FIRMWARE_INFO,
sizeof(FIRMWAREINFO),
&abInfo[0]);
if(debug) printf("DevGetInfo(GET_FIRMWARE_INFO) ret=%d\n", ret);
return ret;
}
if(info == GET_IO_INFO)
{
// Read the mode of the IO-Communication, 0 = MODE UNKNOWN
int ret = DevGetInfo(usBoardNumber, // DeviceNumber
GET_IO_INFO, // InfoArea
sizeof(IOINFO), // Size of bytes to read
&tIoInfo); // Pointer to user buffer
if(debug)
{
printf("DevGetInfo (IOINFO) ret=%d \n", ret);
printf("ExchangeIO information\n"
" IO-Communication mode : %d\n"
" IO-COM bit : %d\n"
" IO-Count : %ld\n",
tIoInfo.bIOExchangeMode, tIoInfo.bComBit, tIoInfo.ulIOExchangeCnt);
if(tIoInfo.bIOExchangeMode == 0)
{
printf( " --- IO-Communication NOT AVAILABLE ---\n");
}
else
{
printf( " --- IO-Communication AVAILABLE ---\n");
// Test if IO-Communication is running
if(tIoInfo.bComBit == 0)
{
printf(" IO-Communication is not running, so all function\n"
" returning an error !\n");
}
}
}
return ret;
}
printf("rlHilscherCIF::devGetInfo() unknown info\n");
return -1;
}
int rlHilscherCIF::devGetMessage ( int  timeout)

Definition at line 210 of file rlhilschercif.cpp.

{
if(isOpen == 0)
{
printf("rlHilscherCIF::devGetMessage ERROR device is not open\n");
return -1;
}
if(tMessage.rx == 0x0ff)
{
printf("rlHilscherCIF::devGetMessage() ERROR you have to set tMessage first\n");
return -1;
}
if(debug) printf("rlHilscherCIF::devGetMessage() timeout=%d", timeout);
int ret = DevGetMessage(usBoardNumber, // Device Number
sizeof(tMessage), // Users buffer size
(MSG_STRUC *)&tMessage, // Pointer to user buffer
(long) timeout); // Timeout
if(debug) printf("DevGetMessage ret=%d\n", ret);
if(ret == DRV_NO_ERROR)
{
// Message available
if(debug) printf( " RX: 0x%02X, TX: 0x%02X, LN: 0x%02X, NR: 0x%02X\n",
tMessage.nr);
if(debug) printf( " A: 0x%02X, F: 0x%02X, B: 0x%02X, E: 0x%02X\n",
}
return ret;
}
int rlHilscherCIF::devInitBoard ( )

Definition at line 102 of file rlhilschercif.cpp.

{
#ifdef RLUNIX
int ret = DevInitBoard(usBoardNumber);
#else
int ret = DevInitBoard(usBoardNumber,NULL);
#endif
if(debug) printf("DevInitBoard ret=%d\n",ret);
return ret;
}
int rlHilscherCIF::devOpenDriver ( )

Definition at line 90 of file rlhilschercif.cpp.

{
isOpen = 1;
#ifdef RLUNIX
int ret = DevOpenDriver();
#else
int ret = DevOpenDriver(usBoardNumber);
#endif
if(debug) printf("DevOpenDriver ret=%d\n",ret);
return ret;
}
int rlHilscherCIF::devPutMessage ( int  timeout)

Definition at line 245 of file rlhilschercif.cpp.

{
if(isOpen == 0)
{
printf("rlHilscherCIF::devPutMessage ERROR device is not open\n");
return -1;
}
if(debug) printf("rlHilscherCIF::devPutMessage() timeout=%d", timeout);
int ret = DevPutMessage(usBoardNumber, // Device Number
(MSG_STRUC *)&tMessage, // Pointer to user buffer
timeout); // Timeout
if(debug) printf("DevPutMessage ret=%d\n", ret);
return ret;
}
int rlHilscherCIF::devPutTaskParameter ( )

Definition at line 170 of file rlhilschercif.cpp.

{
// Write parameters to communication board
int ret = DevPutTaskParameter(usBoardNumber, // Device number
1, // Protokoll task number
sizeof(aParameter), // Lenght of bytes
&aParameter ); // Pointer to data buffer
if(debug) printf("DevPutTaskParameter ret=%d (Interface number 1)\n", ret);
return ret;
}
int rlHilscherCIF::devReset ( )

Definition at line 181 of file rlhilschercif.cpp.

{
// Reset board so it can take the parameters
int ret = DevReset((unsigned char) usBoardNumber, // Device number
(unsigned short) WARMSTART, // Reset mode, Warmstar
(unsigned long) 8000L); // Timeout 8000 ms
if(debug) printf("DevResetBoard ret=%d\n", ret);
return ret;
}
int rlHilscherCIF::devSetHostState ( int  mode)

Definition at line 161 of file rlhilschercif.cpp.

{
int ret = DevSetHostState(usBoardNumber,
mode,
0L);
if(debug) printf("DevSetHostState mode=%d ret=%d\n", mode, ret);
return ret;
}
int rlHilscherCIF::open ( )

Definition at line 66 of file rlhilschercif.cpp.

{
int ret;
isOpen = 1;
if((ret = devOpenDriver()) != DRV_NO_ERROR) return ret;
if((ret = devInitBoard()) != DRV_NO_ERROR) return ret;
if((ret = devGetInfo(GET_FIRMWARE_INFO)) != DRV_NO_ERROR) return ret;
if((ret = devSetHostState(HOST_READY)) != DRV_NO_ERROR) return ret;
if(debug) printf("cif.open() success\n");
return ret;
}
void rlHilscherCIF::printFirmwareInfo ( )

Definition at line 298 of file rlhilschercif.cpp.

{
unsigned char abTemp[30]; // Temporary buffer
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]);
}

Member Data Documentation

unsigned char rlHilscherCIF::abInfo[300]

Definition at line 66 of file rlhilschercif.h.

ASC_PARAMETER rlHilscherCIF::aParameter

Definition at line 67 of file rlhilschercif.h.

int rlHilscherCIF::debug

Definition at line 43 of file rlhilschercif.h.

int rlHilscherCIF::isOpen
private

Definition at line 74 of file rlhilschercif.h.

rlMutex rlHilscherCIF::mutex

Definition at line 71 of file rlhilschercif.h.

IOINFO rlHilscherCIF::tIoInfo

Definition at line 68 of file rlhilschercif.h.

RCS_MESSAGETELEGRAM_10 rlHilscherCIF::tMessage

Definition at line 69 of file rlhilschercif.h.

unsigned short rlHilscherCIF::usBoardNumber

Definition at line 64 of file rlhilschercif.h.

unsigned short rlHilscherCIF::usDevState

Definition at line 65 of file rlhilschercif.h.

unsigned short rlHilscherCIF::usHostState

Definition at line 65 of file rlhilschercif.h.


The documentation for this class was generated from the following files: