rllib  1
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::rlHilscherCIF ( )

Definition at line 24 of file rlhilschercif.cpp.

25 {
26  debug = 0;
27  isOpen = 0;
28  usBoardNumber = 0; // Board number, 0-3
29 
30  // Fill in protokoll parameters
31  aParameter.bScl = 1; /* Interface number */
32  aParameter.bRtsControl = 0; /* Bus handling */
33  aParameter.bBaudrate = 10; /* Baud rate */
34  aParameter.bDataBits = 8; /* Number of data bits */
35  aParameter.bStopBits = 1; /* Number of stop bits */
36  aParameter.bParityBit = 1; /* Parity */
37  aParameter.bMode = 1; /* Interface mode */
38  aParameter.bEndMode = 0; /* Stop mod */
39  aParameter.bCheckMode = 0; /* Checksum mode */
40  aParameter.bCheckArea = 0; /* Checksum area */
41  aParameter.bFilterMode = 0; /* Character filter mode */
42  aParameter.usFilterCharacter = 0; /* Characters */
43  aParameter.usTelTimeout = 1000; /* Telegram timeout */
44  aParameter.usStartTimeout = 0; /* Start timeout */
45  aParameter.usCharTimeout = 0; /* Character timeout */
46  aParameter.bRetries = 0; /* Retray number */
47  aParameter.bErrorLed = 1; /* Error LED */
48  aParameter.bTelStartLen = 0; /* Length of telegram start */
49  aParameter.bTelStart[0] = 0; /* Telegram beginning */
50  aParameter.bTelEndLen = 0; /* Length of telegram end */
51  aParameter.bTelEnd[0] = 0; /* Telegram end */
52  aParameter.bTelAckLen = 0; /* Length of ACK telegram */
53  aParameter.bTelAck[0] = 0; /* ACK telegramm */
54  aParameter.bTelNackLen = 0; /* Length of NAK telegram */
55  aParameter.bTelNack[0] = 0; /* NAK telegram */
56  aParameter.bTelDeviceLen = 0; /* Length of the device telegram */
57 
58  tMessage.rx = 0x0ff;
59 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64
ASC_PARAMETER aParameter
Definition: rlhilschercif.h:67
RCS_MESSAGETELEGRAM_10 tMessage
Definition: rlhilschercif.h:69

◆ ~rlHilscherCIF()

rlHilscherCIF::~rlHilscherCIF ( )
virtual

Definition at line 61 of file rlhilschercif.cpp.

62 {
63  if(isOpen) close();
64 }

Member Function Documentation

◆ close()

int rlHilscherCIF::close ( )

Definition at line 81 of file rlhilschercif.cpp.

82 {
83  int ret;
84  isOpen = 0;
85  if((ret = devSetHostState(HOST_NOT_READY)) != DRV_NO_ERROR) return ret;
86  ret = devCloseDriver();
87  return ret;
88 }
int devSetHostState(int mode)

◆ devCloseDriver()

int rlHilscherCIF::devCloseDriver ( )

Definition at line 198 of file rlhilschercif.cpp.

199 {
200  isOpen = 0;
201 #ifdef RLUNIX
202  int ret = DevCloseDriver();
203 #else
204  int ret = DevCloseDriver(usBoardNumber);
205 #endif
206  if(debug) printf( "DevCloseDriver ret=%d\n", ret);
207  return ret;
208 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64

◆ devExchangeIO()

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.

263 {
264  if(isOpen == 0)
265  {
266  printf("rlHilscherCIF::devExchangeIO ERROR device is not open\n");
267  return -1;
268  }
269  // Run ExchangeIO
270  int ret = DevExchangeIO(usBoardNumber,
271  (unsigned short) sendOffset,
272  (unsigned short) sendSize,
273  sendData,
274  (unsigned short) receiveOffset,
275  (unsigned short) receiveSize,
276  receiveData,
277  timeout);
278  if(ret != DRV_NO_ERROR)
279  {
280  if(debug) printf("DevExchangeIO ret=%d timeout\n", ret);
281  }
282  else
283  {
284  // Data exchange is done, print some information
285  if(debug && sendSize >= 4 && receiveSize >= 4)
286  {
287  printf(" ExchangeIO data:\n"
288  " Send data: Receive data\n");
289  printf(" byte 0 : %d byte 0 : %d\n", sendData[0],receiveData[0]);
290  printf(" byte 1 : %d byte 1 : %d\n", sendData[1],receiveData[1]);
291  printf(" byte 2 : %d byte 2 : %d\n", sendData[2],receiveData[2]);
292  printf(" byte 3 : %d byte 3 : %d\n", sendData[3],receiveData[3]);
293  }
294  }
295  return ret;
296 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64

◆ devExitBoard()

int rlHilscherCIF::devExitBoard ( )

Definition at line 191 of file rlhilschercif.cpp.

192 {
193  int ret = DevExitBoard(usBoardNumber);
194  if(debug) printf("DevExitBoard ret=%d \n", ret);
195  return ret;
196 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64

◆ devGetInfo()

int rlHilscherCIF::devGetInfo ( int  info)

Definition at line 113 of file rlhilschercif.cpp.

114 {
115  if(info == GET_FIRMWARE_INFO)
116  {
117  int ret = DevGetInfo(usBoardNumber,
118  GET_FIRMWARE_INFO,
119  sizeof(FIRMWAREINFO),
120  &abInfo[0]);
121  if(debug) printf("DevGetInfo(GET_FIRMWARE_INFO) ret=%d\n", ret);
122  return ret;
123  }
124  if(info == GET_IO_INFO)
125  {
126  // Read the mode of the IO-Communication, 0 = MODE UNKNOWN
127  int ret = DevGetInfo(usBoardNumber, // DeviceNumber
128  GET_IO_INFO, // InfoArea
129  sizeof(IOINFO), // Size of bytes to read
130  &tIoInfo); // Pointer to user buffer
131 
132  if(debug)
133  {
134  printf("DevGetInfo (IOINFO) ret=%d \n", ret);
135  printf("ExchangeIO information\n"
136  " IO-Communication mode : %d\n"
137  " IO-COM bit : %d\n"
138  " IO-Count : %ld\n",
139  tIoInfo.bIOExchangeMode, tIoInfo.bComBit, tIoInfo.ulIOExchangeCnt);
140  if(tIoInfo.bIOExchangeMode == 0)
141  {
142  printf( " --- IO-Communication NOT AVAILABLE ---\n");
143  }
144  else
145  {
146  printf( " --- IO-Communication AVAILABLE ---\n");
147  // Test if IO-Communication is running
148  if(tIoInfo.bComBit == 0)
149  {
150  printf(" IO-Communication is not running, so all function\n"
151  " returning an error !\n");
152  }
153  }
154  }
155  return ret;
156  }
157  printf("rlHilscherCIF::devGetInfo() unknown info\n");
158  return -1;
159 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64
unsigned char abInfo[300]
Definition: rlhilschercif.h:66

◆ devGetMessage()

int rlHilscherCIF::devGetMessage ( int  timeout)

Definition at line 210 of file rlhilschercif.cpp.

211 {
212  if(isOpen == 0)
213  {
214  printf("rlHilscherCIF::devGetMessage ERROR device is not open\n");
215  return -1;
216  }
217  if(tMessage.rx == 0x0ff)
218  {
219  printf("rlHilscherCIF::devGetMessage() ERROR you have to set tMessage first\n");
220  return -1;
221  }
222  if(debug) printf("rlHilscherCIF::devGetMessage() timeout=%d", timeout);
223  int ret = DevGetMessage(usBoardNumber, // Device Number
224  sizeof(tMessage), // Users buffer size
225  (MSG_STRUC *)&tMessage, // Pointer to user buffer
226  (long) timeout); // Timeout
227  if(debug) printf("DevGetMessage ret=%d\n", ret);
228  if(ret == DRV_NO_ERROR)
229  {
230  // Message available
231  if(debug) printf( " RX: 0x%02X, TX: 0x%02X, LN: 0x%02X, NR: 0x%02X\n",
232  tMessage.rx,
233  tMessage.tx,
234  tMessage.ln,
235  tMessage.nr);
236  if(debug) printf( " A: 0x%02X, F: 0x%02X, B: 0x%02X, E: 0x%02X\n",
237  tMessage.a,
238  tMessage.f,
239  tMessage.b,
240  tMessage.e);
241  }
242  return ret;
243 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64
RCS_MESSAGETELEGRAM_10 tMessage
Definition: rlhilschercif.h:69

◆ devInitBoard()

int rlHilscherCIF::devInitBoard ( )

Definition at line 102 of file rlhilschercif.cpp.

103 {
104 #ifdef RLUNIX
105  int ret = DevInitBoard(usBoardNumber);
106 #else
107  int ret = DevInitBoard(usBoardNumber,NULL);
108 #endif
109  if(debug) printf("DevInitBoard ret=%d\n",ret);
110  return ret;
111 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64

◆ devOpenDriver()

int rlHilscherCIF::devOpenDriver ( )

Definition at line 90 of file rlhilschercif.cpp.

91 {
92  isOpen = 1;
93 #ifdef RLUNIX
94  int ret = DevOpenDriver();
95 #else
96  int ret = DevOpenDriver(usBoardNumber);
97 #endif
98  if(debug) printf("DevOpenDriver ret=%d\n",ret);
99  return ret;
100 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64

◆ devPutMessage()

int rlHilscherCIF::devPutMessage ( int  timeout)

Definition at line 245 of file rlhilschercif.cpp.

246 {
247  if(isOpen == 0)
248  {
249  printf("rlHilscherCIF::devPutMessage ERROR device is not open\n");
250  return -1;
251  }
252  if(debug) printf("rlHilscherCIF::devPutMessage() timeout=%d", timeout);
253  int ret = DevPutMessage(usBoardNumber, // Device Number
254  (MSG_STRUC *)&tMessage, // Pointer to user buffer
255  timeout); // Timeout
256  if(debug) printf("DevPutMessage ret=%d\n", ret);
257  return ret;
258 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64
RCS_MESSAGETELEGRAM_10 tMessage
Definition: rlhilschercif.h:69

◆ devPutTaskParameter()

int rlHilscherCIF::devPutTaskParameter ( )

Definition at line 170 of file rlhilschercif.cpp.

171 {
172  // Write parameters to communication board
173  int ret = DevPutTaskParameter(usBoardNumber, // Device number
174  1, // Protokoll task number
175  sizeof(aParameter), // Lenght of bytes
176  &aParameter ); // Pointer to data buffer
177  if(debug) printf("DevPutTaskParameter ret=%d (Interface number 1)\n", ret);
178  return ret;
179 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64
ASC_PARAMETER aParameter
Definition: rlhilschercif.h:67

◆ devReset()

int rlHilscherCIF::devReset ( )

Definition at line 181 of file rlhilschercif.cpp.

182 {
183  // Reset board so it can take the parameters
184  int ret = DevReset((unsigned char) usBoardNumber, // Device number
185  (unsigned short) WARMSTART, // Reset mode, Warmstar
186  (unsigned long) 8000L); // Timeout 8000 ms
187  if(debug) printf("DevResetBoard ret=%d\n", ret);
188  return ret;
189 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64
#define WARMSTART

◆ devSetHostState()

int rlHilscherCIF::devSetHostState ( int  mode)

Definition at line 161 of file rlhilschercif.cpp.

162 {
163  int ret = DevSetHostState(usBoardNumber,
164  mode,
165  0L);
166  if(debug) printf("DevSetHostState mode=%d ret=%d\n", mode, ret);
167  return ret;
168 }
unsigned short usBoardNumber
Definition: rlhilschercif.h:64

◆ open()

int rlHilscherCIF::open ( )

Definition at line 66 of file rlhilschercif.cpp.

67 {
68  int ret;
69  isOpen = 1;
70  if((ret = devOpenDriver()) != DRV_NO_ERROR) return ret;
71  if((ret = devInitBoard()) != DRV_NO_ERROR) return ret;
72  if((ret = devGetInfo(GET_FIRMWARE_INFO)) != DRV_NO_ERROR) return ret;
73  if((ret = devSetHostState(HOST_READY)) != DRV_NO_ERROR) return ret;
76  devReset();
77  if(debug) printf("cif.open() success\n");
78  return ret;
79 }
int devGetInfo(int info)
void printFirmwareInfo()
int devSetHostState(int mode)
int devPutTaskParameter()

◆ printFirmwareInfo()

void rlHilscherCIF::printFirmwareInfo ( )

Definition at line 298 of file rlhilschercif.cpp.

299 {
300  unsigned char abTemp[30]; // Temporary buffer
301  memcpy(&abTemp, &abInfo[0], 16);
302  abTemp[16] = 0;
303  printf("FirmwareName: %s\n",&abTemp[0]);
304  memcpy(&abTemp, &abInfo[16], 16);
305  abTemp[16] = 0;
306  printf("FirmwareVersion: %s\n",&abTemp[0]);
307 }
unsigned char abInfo[300]
Definition: rlhilschercif.h:66

Member Data Documentation

◆ abInfo

unsigned char rlHilscherCIF::abInfo[300]

Definition at line 66 of file rlhilschercif.h.

◆ aParameter

ASC_PARAMETER rlHilscherCIF::aParameter

Definition at line 67 of file rlhilschercif.h.

◆ debug

int rlHilscherCIF::debug

Definition at line 43 of file rlhilschercif.h.

◆ isOpen

int rlHilscherCIF::isOpen
private

Definition at line 74 of file rlhilschercif.h.

◆ mutex

rlMutex rlHilscherCIF::mutex

Definition at line 71 of file rlhilschercif.h.

◆ tIoInfo

IOINFO rlHilscherCIF::tIoInfo

Definition at line 68 of file rlhilschercif.h.

◆ tMessage

RCS_MESSAGETELEGRAM_10 rlHilscherCIF::tMessage

Definition at line 69 of file rlhilschercif.h.

◆ usBoardNumber

unsigned short rlHilscherCIF::usBoardNumber

Definition at line 64 of file rlhilschercif.h.

◆ usDevState

unsigned short rlHilscherCIF::usDevState

Definition at line 65 of file rlhilschercif.h.

◆ usHostState

unsigned short rlHilscherCIF::usHostState

Definition at line 65 of file rlhilschercif.h.


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