INOS
Hilscher module

Enable Hilscher module

The Hilscher module driver can be enabled in the iDev project properties under the feature settings:

Usage

Data is exchanged with the Hilscher module with a Dual-Port-Ram. The data that comes in from the external bus is read and stored in memory whereas the data to be sent is taken from the memory and put onto the external bus. Even though the offset may be the same for both buffers they are stored on different addresses in the DPR. The content and format of this data depends on the configuration of the external field bus. If the remote communication partner uses a different endianness then the data needs to be interpreted correctly.

As the DPR is not fast and should permanently be polled for incoming data this polling is usually done in a dedicated task with low priority. Never call the Hilscher functions from a realtime task or a realtime hook!

#include <csamdevicehilscher.h>
// receive data
g_pSAMDeviceHilscher->ReceiveData(0, rcvbuffer, rcvlng); // offset, data, length
// process data
// send data
g_pSAMDeviceHilscher->SendData(0, sndbuffer, sndlng); // offset, data, length

Example: Read and send data

This example consists of a master and a slave, both running on Indel targets. The master sends data to the slave and the slave returns it unchanged (echo). Then the master can receive the data and compare it to the originally sent data.

#include <CSAMDeviceHilscher.h>
void CHilscherMaster::Action()
{
uint8 buffer[256];
uint8 buffer2[256];
uint32 error=0;
uint32 c=0;
//do endless
while (1) {
// create some data
((uint32*)buffer)[0]=c++;
((uint32*)buffer)[1]=~c;
// send data
g_pSAMDeviceHilscher->SendData(0, buffer, 8);
// give communication and slave some time
Sleep(10);
// try to receive data
g_pSAMDeviceHilscher->ReceiveData(0, buffer2, 8);
// compare sent and received
if (memcmp(buffer, buffer2, 8)!=0) {
error++;
}
// give other tasks a chance
Relinquish();
}
// end CHilscherMaster::Action
}
//------------------------------------------------------------------------------
#include <CSAMDeviceHilscher.h>
void CHilscherSlave::Action()
{
uint8 buffer[256];
//do endless
while (1) {
// try to get data
g_pSAMDeviceHilscher->ReceiveData(0, buffer, 12);
// hello echo
g_pSAMDeviceHilscher->SendData(0, buffer, 12);
// give other tasks a chance
Relinquish();
}
// end CHilscherSlave::Action
}