Overview

This group defines all required functions to initialize a correct communication via Common Serial Interface (CSI)

+ Collaboration diagram for Initialization:

Functions

CSI_API long CsiClose (struct CsiBus *pBus)
 Closes the serial connection and frees allocated resources. More...
 
CSI_API long CsiConnectToDevice (struct CsiBus *pBus, const char *SerialDeviceName, uint32_t BaudRate, uint32_t TimeoutMs, struct CsiDev *pDev, uint8_t NodeId)
 The function initializes the bus object (pBus), the serial channel object (pChan) with the baud rate and timeout values and opens the serial connection to the device. More...
 
CSI_API long CsiDevInit (struct CsiBus *pBus, uint8_t NodeId, struct CsiDev *pDev, enum CsiSerialProtocolVersion SerProtocolVersion)
 Initialize CSI device object with all parameters. More...
 
CSI_API long CsiOpen (struct CsiBus *pBus, const char *DeviceName, uint32_t BaudRate, uint32_t TimeoutMs)
 Initialize CSI API and connection to CSI bus. More...
 
CSI_API long CsiSetCommTimout (struct CsiBus *pBus, uint32_t TimeoutMs)
 Set timeout in milliseconds for bus communication (read/write). More...
 

Function Documentation

CSI_API long CsiClose ( struct CsiBus pBus)

Closes the serial connection and frees allocated resources.

Parameters
[in]pBusReference of bus object to finish communicaton.
Returns
Error code - ERR_NOERR indicates success
143 {
144  long Result = ERR_NOERR;
145  if (&pBus->SerChannel)
146  {
147  Result = CsiBusClose(pBus);
148  }
149 
150  return Result;
151 }
long CsiBusClose(struct CsiBus *pBus)
Close connection.
Definition: csi_bus.c:109
#define ERR_NOERR
No error.
Definition: err_codes.h:102
struct CsiSerChannel SerChannel
serial channel data for connection
Definition: csi_types.h:79

+ Here is the call graph for this function:

CSI_API long CsiConnectToDevice ( struct CsiBus pBus,
const char *  SerialDeviceName,
uint32_t  BaudRate,
uint32_t  TimeoutMs,
struct CsiDev pDev,
uint8_t  NodeId 
)

The function initializes the bus object (pBus), the serial channel object (pChan) with the baud rate and timeout values and opens the serial connection to the device.

If the SerialDeviceName is empty, the function tries to autodetect the serial channel by reading the object 0x1000.If a device responds to this request, the serial channel has been detected.

Parameters
[in]pBusBus object to initialize.
[in]SerialDeviceNameName of the serial port device (i.e. COM1). If the value of SerialDeviceName is 0, the function tries to auto detect the serial channel.
[in]BaudRateThe baud rate in bit / s (baud). You should use standard baud rates from TStandardBaudRate enumeration
[in]TimeoutMsThe timeout in milliseconds for serial protocol.
[in]pDevPointer to the device object
[in]NodeIdNode identifier of the device to connect
Returns
Error code - CSI_ERR_NOERR indicates successful initialization
See also
CsiDevInit()
78 {
79  pDev->NodeId = NodeId;
80  pDev->pBus = pBus;
81  pBus->TimeoutMs = TimeoutMs;
82  pBus->SerChannel.BaudRate = BaudRate;
83 
84  if (!SerialDeviceName)
85  {
86  return Csi_AutoDetectSerialChannel(pDev);
87  }
88  else
89  {
90  strncpy(pBus->SerChannel.DeviceName, SerialDeviceName,
91  sizeof(pBus->SerChannel.DeviceName));
92  return CsiBusOpen(pBus);
93  }
94 }
uint32_t TimeoutMs
timeout value in milliseconds for serial protocol
Definition: csi_types.h:82
long CsiBusOpen(struct CsiBus *pBus)
This function initializes connection to CSI bus.
Definition: csi_bus.c:92
struct CsiBus * pBus
the bus object the device is attached to
Definition: csi_types.h:90
char DeviceName[64]
stores the device name
Definition: csi_types.h:59
struct CsiSerChannel SerChannel
serial channel data for connection
Definition: csi_types.h:79
uint32_t BaudRate
baudrate of serial channel
Definition: csi_types.h:57
uint8_t NodeId
the node identifier for this device
Definition: csi_types.h:91

+ Here is the call graph for this function:

CSI_API long CsiDevInit ( struct CsiBus pBus,
uint8_t  NodeId,
struct CsiDev pDev,
enum CsiSerialProtocolVersion  SerProtocolVersion 
)

Initialize CSI device object with all parameters.

After a call to this function all other functions that require a valid device object can be called.

Parameters
[in]pBusReference of bus object the device is attached to
[in]NodeIdNodeId of devicer to initialize
[in]pDevReference to device object to initialize
[in]SerProtocolVersionThe serial protocol version to use for communication. The CSI library supports older device with th V1 protocol and newer devices, such as Nemesys S and Nemesys M with the new V2 protocol.
Returns
Error code - CSI_ERR_NOERR indicates successful initialization

Referenced by NemDevInit(), and NemV4DevInit().

129 {
130  long Result = ERR_NOERR;
131 
132  pDev->NodeId = NodeId;
133  pDev->pBus = pBus;
135  return Result;
136 }
enum CsiSerialProtocolVersion SerProtocolVersion
the serial protocol version to use for this device
Definition: csi_types.h:92
struct CsiBus * pBus
the bus object the device is attached to
Definition: csi_types.h:90
#define ERR_NOERR
No error.
Definition: err_codes.h:102
uint8_t NodeId
the node identifier for this device
Definition: csi_types.h:91
CSI_API long CsiOpen ( struct CsiBus pBus,
const char *  DeviceName,
uint32_t  BaudRate,
uint32_t  TimeoutMs 
)

Initialize CSI API and connection to CSI bus.

The function initializes the bus object (pBus) and the serial channel object (pChan) with the baud rate and timeout values and opens the serial connection to the device. A valid bus object is required for calls to function CsiDevInit().

Parameters
[in]pBusBus object to initialize.
[in]DeviceNameMay Name of the serial port device (i.e. COM1)
[in]BaudRateThe baud rate in bit / s (baud). You should use standard baud rates from TStandardBaudRate enumeration
[in]TimeoutMsThe timeout in milliseconds for serial protocol.
Returns
Error code - CSI_ERR_NOERR indicates successful initialization
See also
CsiDevInit()
104 {
105  pBus->SerChannel.BaudRate = BaudRate;
106  strncpy(pBus->SerChannel.DeviceName, DeviceName, sizeof(pBus->SerChannel.DeviceName));
107  pBus->TimeoutMs = TimeoutMs;
108  pBus->SerChannel.pPriv = 0;
109 
110  return CsiBusOpen(pBus);
111 }
uint32_t TimeoutMs
timeout value in milliseconds for serial protocol
Definition: csi_types.h:82
long CsiBusOpen(struct CsiBus *pBus)
This function initializes connection to CSI bus.
Definition: csi_bus.c:92
char DeviceName[64]
stores the device name
Definition: csi_types.h:59
struct CsiSerChannel SerChannel
serial channel data for connection
Definition: csi_types.h:79
uint32_t BaudRate
baudrate of serial channel
Definition: csi_types.h:57
void * pPriv
pointer to private data
Definition: csi_types.h:58

+ Here is the call graph for this function:

CSI_API long CsiSetCommTimout ( struct CsiBus pBus,
uint32_t  TimeoutMs 
)

Set timeout in milliseconds for bus communication (read/write).

Parameters
[in]pBusReference of bus object the device is attached to
[in]TimeoutMsTimeout value in milliseconds
Returns
Error code - CSI_ERR_NOERR indicates successful initialization
118 {
119  pBus->TimeoutMs = TimeoutMs;
120  return ERR_NOERR;
121 }
uint32_t TimeoutMs
timeout value in milliseconds for serial protocol
Definition: csi_types.h:82
#define ERR_NOERR
No error.
Definition: err_codes.h:102