AnaGate Programmer's Manual Analytica GmbH A. Schmidt, Analytica GmbH S.
AnaGate Programmer's Manual Analytica GmbH by A. Schmidt and S. Welisch This document was generated with DocBook at 2010-09-09 17:22:53. Hilfe-Datei (dtsch.): AnaGate-API.chm Hilfe-Datei (engl.): AnaGate-API-EN.chm PDF-Datei (dtsch.): AnaGate-API-1.10.pdf PDF-Datei (engl.): AnaGate-API-1.10-EN.pdf Publication date 09.
Table of Contents Introduction .................................................................................................................... vii I. AnaGate API .................................................................................................................. 1 1. The Programming interface of AnaGate devices ........................................................... 3 2. Notes concerning the communication protocol TCP ....................................................... 5 2.1.
AnaGate Programmer's Manual Bibliography ...................................................................................................................
List of Figures 7.1. Input form of SPI example (VB6) .................................................................................. 64 B.1. Definition of a I2C slave address in 7-bit format .............................................................. 71 B.2. Definition of a I2C slave address in 10-bit format ............................................................
List of Tables 1.1. Library files for Windows .............................................................................................. 3 1.2. Library files for Linux .................................................................................................. 3 2.1. AnaGate devices and related port numbers ........................................................................ 5 6.1. Usage of the CHIP-Enable Bits of I2C EEPROMs ............................................................ 58 A.1.
Introduction The AnaGate Programmer's Manual includes the exact description of the programming interfaces to all models of AnaGate hardware series.
Part I.
Table of Contents 1. The Programming interface of AnaGate devices ................................................................... 3 2. Notes concerning the communication protocol TCP ............................................................... 5 2.1. Important properties of the network protocol ............................................................. 5 3. Common function reference .............................................................................................. 7 DLLInfo ...........
Chapter 1. The Programming interface of AnaGate devices The AnaGate product line consist of several hardware devices, which offers access to different bus systems (I2C, SPI, CAN) or processors (Renesas) via standard network protocol. The communication to the individual devices always is done through a documented and disclosed proprietary network protocol. Thus, all products which incorporates a socket interface (like personal computers, PLC, ...
The Programming interface of AnaGate devices Tip It is possible to extend individually the newer device models with embedded Linux (kernel 2.6) and ARM9 processor. The complete software API is available in a cross-compiled version and can be used on the devices itself to create individual device extensions. To do so is very easy because the programming interface on the personal computer and the device is completely identical.
Chapter 2. Notes concerning the communication protocol TCP Access to the different models of the AnaGate product line is always done via the most frequently used network protocol TCP (Transmission Control Protocol). TCP is connection-oriented packet-switched transport protocol which is located in layer 4 of the of the OSI reference model. In princible TCP is an end-to-end connection which allows exchange of data in both directions at the same time.
Notes concerning the communication protocol TCP To amend this problematic nature TCP provides an internal keep alive mechanism. Keep-alives are special data packets which are sent in regular intervalls between the two endpoints of an opened communication channel. The recipient of a keep-alive packet has to confirm the receipt to the sender within a certain period of time.
Chapter 3.
Common function reference DLLInfo DLLInfo — Determines the current version information of the AnaGate DLL. Syntax #include int DLLVersion(char * pcMessage, int nMessageLen); Parameter pcMessage nMessageLen Data buffer that is to accept the version reference number of the AnaGate DLL. Size in bytes of the transferred data buffer. Return value Actual size of the returned version reference number.
Chapter 4. CAN API reference The CAN API can be used with all CAN gateway models of the AnaGate series. The programming interface is identical for all devices and uses the network protocol TCP or UDP in general.
CAN API reference CANOpenDevice, CANOpenDeviceEx CANOpenDevice, CANOpenDeviceEx — Opens an network connection (TCP or UDP) to an AnaGate CAN device. Syntax #include
CAN API reference Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description Opens a TCP/IP connection to an CAN interface of a AnaGate CAN device. With CANOpenDeviceEx it is possible to set the ethernet layer4 protocol (tcp or udp). If the connection is established, CAN telegrams can be sent and received. The connection should be closed with the function CANCloseDevice if not longer needed.
CAN API reference CANCloseDevice CANCloseDevice — Closes an open network connection to an AnaGate CAN device. Syntax #include int CANCloseDevice(int hHandle); Parameter hHandle Valid access handle. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description Closes an open network connection to an AnaGate CAN device. The hHandle parameter is a return value of a succesfull call to the function CANOpenDevice.
CAN API reference CANSetGlobals CANSetGlobals — Sets the global settings, which are to be used on the CAN bus Syntax #include int CANSetGlobals(int nOperatingMode, BOOL bTimeStampOn); hHandle, int nBaudrate, unsigned bTermination, BOOL bHighSpeedMode, char BOOL Parameter hHandle Valid access handle. nBaudrate The baud rate to be used. Following values are allowed: • 10.000 für 10kBit • 20.000 für 20kBit • 50.000 für 50kBit • 62.500 für 62,5kBit • 100.000 für 100kBit • 125.
CAN API reference bTimeStampOn Use time stamp mode (TRUE= yes, FALSE= no). This setting is not supported by all AnaGate CAN models. In activated time stamp mode an additional timestamp is sent with the CAN telegram. This timestamp indicates when the incomming message is received by the CAN controller or when the outgoing message is confirmed by the CAN controller. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
CAN API reference CANGetGlobals CANGetGlobals — Returns the currently used global settings on the CAN bus. Syntax #include int CANGetGlobals(int hHandle, int * pnBaudrate, unsigned char * pnOperatingMode, BOOL * pbTermination, BOOL * pbHighSpeedMode, BOOL * pbTimeStampOn); Parameter hHandle Valid access handle. pnBaudrate The baud rate currently used on the CAN bus. pnOperatingMode The operating mode to be used. Following values are returned. • 0 = default mode.
CAN API reference Remarks The settings of the integrated CAN bus termination, the high speed mode and the time stamp are not supported by the AnaGate CAN (hardware version 1.1.A). These settings are ignored by the device.
CAN API reference CANSetFilter CANSetFilter — Sets the current filter settings for the connection. Syntax #include int CANSetFilter(int hHandle, const int * pnFilter); Parameter hHandle Valid access handle. pnFilter Pointer to an array of 8 filter entries (4 mask and 4 range filter entries). A filter entry contains of two 32-bit values. Unused mask filter entries must be initialized with 0 values.
CAN API reference CANGetFilter CANGetFilter — Returns the current filter settings for the connection. Syntax #include int CANGetFilter(int hHandle, int * pnFilter); Parameter hHandle Valid access handle. pnFilter Pointer to an array of 8 filter entries (4 mask and 4 range filter entries). A filter entry contains of two 32-bit values. Unused mask filter entries are initialized with 0 values. Unused range filter entries are initialized with (0,0x1FFFFFFF) value pairs.
CAN API reference CANSetTime CANSetTime — Sets the current system time on the AnaGate device. Syntax #include int CANSetTime(int hHandle, long nSeconds, long nMicroseconds); Parameter hHandle Valid access handle. nSeconds Time in seconds from 01.01.1970. nMicroseconds Micro seconds. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description The CANSetTime function sets the system time on the AnaGate hardware.
CAN API reference CANWrite, CANWriteEx CANWrite, CANWriteEx — Send a CAN telegram to the CAN bus via the AnaGate device. Syntax #include int CANWrite(int hHandle, int nIdentifier, const char * pcBuffer, int nBufferLen, int nFlags); int CANWriteEx(int hHandle, int nIdentifier, const char * pcBuffer, int nBufferLen, int nFlags, long * pnSeconds, long * pnMicroSeconds); Parameter hHandle Valid access handle. nIdentifier CAN identifier of the sender.
CAN API reference See the following example for sending a data telegram to the connected CAN bus. #include int main() { char cMsg[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int hHandle = 0; int nRC = 0; int nFlags = 0x0; // 11bit address + standard (not remote frame) int nIdentifier = 0x25; // send with CAN ID 0x25; int nRC = CANOpenDevice(&hHandle, TRUE, TRUE, 0, "192.168.0.
CAN API reference CANSetCallback, CANSetCallbackEx CANSetCallback, CANSetCallbackEx — Defines an asynchronous callback function, which is called for each incoming CAN telegram. Syntax #include
CAN API reference void WINAPI MyCallbackEx(int nIdentifier, const char * pcBuffer, int nBufferLen, int nFlags, int hHandle, long nSeconds, long nMicroseconds) { std::cout << "CAN-ID=" << nIdentifier << ", Data="; for ( int i = 0; i < nBufferLen; i++ ) { std::cout << " 0x" << std::hex << int((unsigned char)(pcBuffer[i])); } time_t tTime = nSeconds; struct tm * psLocalTime = localtime(&tTime ); std::cout << " " << std::setw(19) << asctime( psLocalTime ) << " ms(" << std::dec << std::setw(3) << nMicroseconds/
CAN API reference CANReadDigital CANReadDigital — Reads the current values of digital input and output registers of the AnaGate device. Syntax #include int CANReadDigital(int hHandle, unsigned long * pnInputBits, unsigned long * pnOutputBits); Parameter hHandle Valid access handle. pnInputBits Pointer to the current value of the digital input register. Currently only bits 0 to 3 are used, other bits are reserved for future use and are set to 0.
CAN API reference } See also CANWriteDigital 25 © 2007-2010 Analytica GmbH
CAN API reference CANWriteDigital CANWriteDigital — Writes a new value to the digital output register of the AnaGate device. Syntax #include int CANWriteDigital(int hHandle, unsigned long nOutputBits); Parameter hHandle Valid access handle. nOutputBits New register value. Currently only bits 0 to 3 are used, other bits are reserved for future use. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
CAN API reference CANRestart CANRestart — Restarts a AnaGate CAN device. Syntax #include int CANRestart(const char * pcIPAddress, int nTimeout ); Parameter pcIPAddress Network address of the AnaGate partner. nTimeout Default timeout for accessing the AnaGate in milliseconds. A timeout is reported if the AnaGate partner does not respond within the defined timeout period. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
CAN API reference CANDeviceConnectState CANDeviceConnectState — Retrieves the current network connection state of the current AnaGate connection. Syntax #include int CANDeviceConnectState(int hHandle); Parameter hHandle Valid connection handle of a successful call to CANOpenDevice. Return value Returns the current network connection state. Following values are possible: • 1 = DISCONNECTED: The connection to the AnaGate is disconnected. • 2 = CONNECTING: The connection is connecting.
CAN API reference CANStartAlive CANStartAlive — Starts the ALIVE mechanism, which checks periodically the state of the network connection to the AnaGate hardware. Syntax #include int CANStartAlive(int hHandle, int nAliveTime ); Parameter hHandle Valid access handle. nAliveTime Default time out in seconds for the ALIVE mechanism. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
CAN API reference CANErrorMessage CANErrorMessage — Returns a description of the given error code as a text string. Syntax #include int CANErrorMessage(int nRetCode, char * pcMessage, int nMessageLen); Parameter nRetCode pcMessage nMessageLen Error code for which the error description is to be determined. Data buffer that is to accept the error description. Size in bytes of the transferred data buffer. Return value Actual size of the returned description.
Chapter 5. SPI API reference The Serial Peripheral Interface (SPI) is a synchroneous data link standard named by Motorola which operates in full duplex mode. The SPI gateway models of the AnaGate series provides access to a SPI bus via a standard networking. With the SPI API these SPI gateways can be easily controlled. The programming interface is identical for all devices and used the network protocol TCP in general.
SPI API reference SPIOpenDevice SPIOpenDevice — Opens a network connection to an AnaGate SPI device. Syntax #include int SPIOpenDevice(int * pHandle, const char * pcIPAddress, int nTimeout); Parameter pHandle Pointer to a variable, in which the access handle is saved in the event of a successful connection to the AnaGate device. pcIPAddress Network address of the AnaGate partner. nTimeout Default timeout for accessing the AnaGate in milliseconds.
SPI API reference See also SPICloseDevice 33 © 2007-2010 Analytica GmbH
SPI API reference SPICloseDevice SPICloseDevice — Closes an open network connection to an AnaGate SPI device. Syntax #include int SPICloseDevice(int hHandle); Parameter hHandle Valid access handle. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description Closes an open network connection to an AnaGate SPI device. The hHandle parameter is a return value of a succesfull call to the function SPIOpenDevice.
SPI API reference SPISetGlobals SPISetGlobals — Sets the global settings, which are to be used on the AnaGate SPI. Syntax #include int SPISetGlobals(int hHandle, int nBaudrate, unsigned char nSigLevel, unsigned char nAuxVoltage, unsigned char nClockMode); Parameter hHandle Valid access handle. nBaudrate The baud rate to be used. The values can be set individually, like • 500.000 for 500kBit • 1.000.000 for 1MBit • 5.000.
SPI API reference Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description Sets the global settings of SPI interface of the AnaGate SPI or the AnaGate Universal Programmer. These settings are not saved permantently on the device and are reset every device restart.
SPI API reference SPIGetGlobals SPIGetGlobals — Returns the currently used global settings of the AnaGate SPI. Syntax #include int SPIGetGlobals(int hHandle, int * pnBaudrate, unsigned char * pnSigLevel, unsigned char * pnAuxVoltage, unsigned char * pnClockMode); Parameter hHandle Valid access handle. pnBaudrate The baud rate currently used on the SPI bus in kBit. pnSigLevel The voltage level currently used by the AnaGate SPI.
SPI API reference See also SPISetGlobals 38 © 2007-2010 Analytica GmbH
SPI API reference SPIDataReq SPIDataReq — Writes and reads data to/from SPI bus. Syntax #include int SPIDataReq(int hHandle, const char * pcBufWrite, int nBufWriteLen, char * pcBufRead, int nBufReadLen); Parameter hHandle Valid access handle. pcBufWrite Buffer with the data that is to be sent to the SPI partner. nBufWriteLen pcBufRead Length of the data buffer pcBufWrite (byte count). Byte buffer which holds the data received from the SPI partner.
SPI API reference nRC = SPIDataReq( hHandle, cBufWrite, 1, cBufReceive, 5 ); // send 2 byte and receive 1 byte nRC = SPIDataReq( hHandle, cBufW2ite, 2, cBufReceive, 1 ); SPICloseDevice(hHandle); } return 0; } Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
SPI API reference SPIReadDigital SPIReadDigital — Reads the current values of digital input and output registers of the AnaGate device. Syntax #include int SPIReadDigital(int hHandle, unsigned long * pnInputBits, unsigned long * pnOutputBits); Parameter hHandle Valid access handle. pnInputBits Pointer to the current value of the digital input register. Currently only bits 0 to 3 are used, other bits are reserved for future use and are set to 0.
SPI API reference } See also SPIWriteDigital 42 © 2007-2010 Analytica GmbH
SPI API reference SPIWriteDigital SPIWriteDigital — Write a new value to the digital output register of the AnaGate device. Syntax #include int SPIWriteDigital(int hHandle, unsigned long nOutputBits); Parameter hHandle Valid access handle. nOutputBits New register value. Currently only bits 0 to 3 are used, other bits are reserved for future use. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
SPI API reference SPIErrorMessage SPIErrorMessage — Returns a description of the given error code as a text string. Syntax #include int SPIErrorMessage(int nRetCode, char * pcMessage, int nMessageLen); Parameter nRetCode pcMessage nMessageLen Error code for which the error description is to be determined. Data buffer that is to accept the error description. Size in bytes of the transferred data buffer. Return value Actual size of the returned description.
Chapter 6. I2C API reference Philips Semiconductors (now NXP Semiconductors) has developed a simple bidirectional 2-wire bus for efficient inter-IC control. This bus is called the Inter-IC or I2C-bus. Only two bus lines are required: a serial data line (SDA) and a serial clock line (SCL). Serial, 8-bit oriented, bidirectional data transfers can be made at up to 100 kbit/s in the Standard-mode, up to 400 kbit/s in the Fast-mode, up to 1 Mbit/s in the Fast-mode Plus (Fm+), or up to 3.
I2C API reference I2COpenDevice I2COpenDevice — Opens a network connection to an AnaGate I2C or an AnaGate Universal Programmer). Syntax #include int I2COpenDevice(int * pHandle, unsigned int nBaudrate, const char * pcIPAddress, int nTimeout); Parameter pHandle Pointer to a variable, in which the access handle is saved in the event of a successful connection to the AnaGate device. nBaudrate Baud rate to be used for the I2C bus.
I2C API reference int main() { int hHandle; int nRC = I2COpenDevice(&hHandle, 100000, "192.168.0.254", 5000); if ( nRC == 0 ) { // ...
I2C API reference I2CCloseDevice I2CCloseDevice — Closes an open network connection to an AnaGate I2C device. Syntax #include int I2CCloseDevice(int hHandle); Parameter hHandle Valid access handle. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description Closes an open network connection to an AnaGate I2C device. The hHandle parameter is a return value of a succesfull call to the function I2COpenDevice.
I2C API reference I2CReset I2CReset — Resets the I2C Controller in an AnaGate I2C device. Syntax #include int I2CReset(int hHandle); Parameter hHandle Valid access handle. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description Resets the I2C Controller in an AnaGate I2C device.
I2C API reference I2CRead I2CRead — Reads data from an I2C partner. Syntax #include int I2CRead(int hHandle, unsigned short nSlaveAddress, const char * pcBuffer, int nBufferLen); Parameter hHandle Valid access handle. nSlaveAddress Slave address of the I2C partner. The slave address can represent a so-called 7-bit or 10-bit address. (siehe Appendix B, I2C slave address formats). pcBuffer Byte buffer in which the data received from the I2C partner is to be stored.
I2C API reference I2CWrite I2CWrite — Writes data to an I2C partner. Syntax #include int I2CWrite(int hHandle, unsigned short nSlaveAddress, const char * pcBuffer, int nBufferLen); Parameter hHandle Valid access handle. nSlaveAddress Slave address of the I2C partner. The slave address can represent a so-called 7-bit or 10-bit address. (siehe Appendix B, I2C slave address formats). pcBuffer Byte buffer with the data that is to be sent to the I2C partner.
I2C API reference I2CSequence I2CSequence — This command is used to write a sequence of write and read commands to an I2C device. Syntax #include int I2CSequence(int hHandle, const char * pcWriteBuffer, int nNumberOfBytesToWrite, char * pcReadBuffer, int nNumberOfBytesToRead, int * pnNumberOfBytesRead, int * pnByteNumberLastError); Parameter hHandle Valid access handle. pcWriteBuffer byte buffer, containing the commands which are to be sent to the AnaGate I2C.
I2C API reference pnByteNumberLastError Number of byte in the pcWriteBuffer buffer, which raises an error. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes). Description The user must ensure that the setup of the data buffer and the address of the I2C partner are correct.
I2C API reference I2CReadDigital I2CReadDigital — Reads the current values of digital input and output registers of the AnaGate device. Syntax #include int I2CReadDigital(int hHandle, unsigned long * pnInputBits, unsigned long * pnOutputBits); Parameter hHandle Valid access handle. pnInputBits Pointer to the current value of the digital input register. Currently only bits 0 to 3 are used, other bits are reserved for future use and are set to 0.
I2C API reference } See also I2CWriteDigital 55 © 2007-2010 Analytica GmbH
I2C API reference I2CWriteDigital I2CWriteDigital — Writes a new value to the digital output register of the AnaGate device. Syntax #include int I2CWriteDigital(int hHandle, unsigned long nOutputBits); Parameter hHandle Valid access handle. nOutputBits New register value. Currently only bits 0 to 3 are used, other bits are reserved for future use. Return value Returns Null if successful, or an error value otherwise (Appendix A, Return Codes).
I2C API reference I2CErrorMessage I2CErrorMessage — Returns a description of the given error code as a text string. Syntax #include int I2CErrorMessage(int nRetCode, char * pcMessage, int nMessageLen); Parameter nRetCode pcMessage nMessageLen Error code for which the error description is to be determined. Data buffer that is to accept the error description. Size in bytes of the transferred data buffer. Return value Actual size of the returned description.
I2C API reference 6.1. Programming I2C EEPROM The AnaGate I2C is very well suited for programming serial I2C EEPROM. To support this special requirement two different functions are made available: I2CReadEEPROM and I2CWriteEEPROM. Like all other I2C-capable devices EEPROM's are addressable on the I2C bus via a unique slave address (see also Appendix B, I2C slave address formats). The so-called Device Type Identifier for these types of devcies is 0xA.
I2C API reference I2CReadEEPROM I2CReadEEPROM — Reads data from an EEPROM on the I2C bus. Syntax #include int I2CReadEEPROM(int hHandle, unsigned short nSubAddress, unsigned int nOffset, const char * pcBuffer, int nBufferLen, unsigned int nOffsetFormat); Parameter hHandle Valid access handle. nSubAddress Subaddress of the EEPROM to communicate with. The valid values for nSubAddress are governed by the setting used in the parameter nOffsetFormat (bits 8-10).
I2C API reference Description The I2CReadEEPROM function reads data from an I2C EEPROM. Of course all access to the memory of an EEPROM is done by standard I2C read or write commands. So, when reading from the memory only the matching slave address, the memory offset address and the data has to be sent to the I2C bus. I2CReadEEPROM translates the given memory address on the chip by means of the sub address and the addressing mode of the present EEPROM type.
I2C API reference I2CWriteEEPROM I2CWriteEEPROM — Writes data to an I2C EEPROM. Syntax #include int I2CWriteEEPROM(int hHandle, unsigned short nSubAddress, unsigned int nOffset, const char * pcBuffer, int nBufferLen, unsigned int nOffsetFormat); Parameter hHandle Valid access handle. nSubAddress Subaddress of the EEPROM to communicate with. The valid values for nSubAddress are governed by the setting used in the parameter nOffsetFormat (bits 8-10).
I2C API reference Description The I2CWriteEEPROM function writes data to an I2C EEPROM. Of course all access to the memory of an EEPROM is done by standard I2C read or write commands. So, when writing to the memory only the matching slave address, the memory offset address and the data has to be sent to the I2C bus. I2CWriteEEPROM translates the given memory address on the chip by means of the sub address and the addressing mode of the present EEPROM type.
Chapter 7. Programming examples 7.1. Programming language C/C++ The AnaGate programming API can be used on Windows systems as well as on linux systems (X86). All available API functions are coded operating system independant, so that source code once created can be used on both operating systems. Only the way the libraries are linked on the different operating systems or different compilers have to be customized.
Programming examples 7.2. Programming language Visual Basic 6 As already described in the previous chapters, the libraries of the AnaGate-API use the cdecl calling convention to parse function parameters to the program stack. Unfortunately this is generally not supported by the programming language Visual Basic 6. To work around this limitiation, the libraries for the AnaGate devices are available in a specfic version for programming VB6 applications.
Programming examples Dialog fields Network address Network address of the AnaGate SPI. Check address Establishs a connection to the AnaGate SPI with the specified network address and reads back some device information and global device settings. Baud rate The baud rate to be used. The value can be set individually. Signal Level The voltage level for SPI signals to be used. Aux. Voltage The voltage level of the support voltage to be used. Clock mode The phase and polarity of the clock signal.
Programming examples 1 2 A call to SPIOpenDevice establishes a network connection to the device. If the function fails, a textual error description is returned via Funktion GetErrorMsg. The connection to the device is closed with the SPICloseDevice function. Reading the device settings and creation of the textual presentation of the data is done by the GetAnagateInfo function.
Programming examples End If Me.lblDeviceInfo.Caption = GetAnagateInfo(hHandle) nBufferWriteLen = GetCommand(arrWrite) nBufferReadLen = nBufferWriteLen 2 nRC = SPIDataReq(hHandle, VarPtr(arrWrite(1)), nBufferWriteLen, _ 3 VarPtr(arrRead(1)), nBufferReadLen) If nRC = 0 Then For I = 1 To nBufferReadLen sByteText = sByteText & "0x" & ToHex(arrRead(I)) & " " Next I Me.
Programming examples Console.Out.Write( ",Data=" ) For I As Integer = 0 To BufferLen - 1 Console.Out.Write( Bytes(I) ) Next End Sub Function Main(ByVal CmdArgs() As String) As Integer 'Opens the single dim RC as Int32 = If RC = 0 Then CANSetCallback( end If If RC = 0 Then CANCloseDevice( end if end Function CAN port of a AnaGate CAN CANOpenDevice(Handle, 0, 1, 400, 0, "192.168.2.
Appendix A. Return Codes API return codes Followed a list of the return values of the API functions. This values are defined in the header file AnaGateErrors.h. Table A.1. Common return values for all devices of AnaGate series Value Name Description 0 ERR_NONE No errors. 0x000001 ERR_OPEN_MAX_CONN Open failed, maximal count of connections reached. 0x0000FF ERR_OP_CMD_FAILED Command failed with unknown failure. 0x020000 ERR_TCPIP_SOCKET Socket error in TCP/IP layer occured.
Return Codes Table A.4. Return values for AnaGate Renesas Value Name Description 0x000920 ERR_RENESAS_TIMEOUT Renesas timeout 0x000921 ERR_RENESAS_INVALID_ID Renesas Invalid ID 0x000922 ERR_RENESAS_FLASH_ERASE_FAILED Renesas failed erase the flash 0x000923 ERR_RENESAS_PAGE_PROG_FAILED Renesas failed prog the page A textual description of the return value can be retrieved with the function RenesasErrorMessage().
Appendix B. I2C slave address formats A standard I2C address is the first byte sent be the I2C master, whereas only the first seven bit form the adress, the last bit (R/W-bit) defines the direction in which the data is sent. I2C has a 7-bit address space and can address 112 slaves on a single bus (16 of the 128 addresses are reserved fo special purposes). Figure B.1. Definition of a I2C slave address in 7-bit format Each I2C-able IC has a determined bus address.
I2C slave address formats Chip Enable 1 2 Device Type Identifier b7 b6 b5 b4 b3 b2 b1 R/W EEPROMb0 Memory M24C08 1 0 1 0 E2 A9 A8 R/W 1024 byte M24C16 1 0 1 0 A10 A9 A8 R/W 2048 byte M24C64 1 0 1 0 E2 E1 E0 R/W 8192 byte 1 E0,E1 and E2 are compared against the respective external pins on the memory device. 2 A10, A9 and A8 represent most significant bits of the address.
Appendix C. FAQ - Frequent asked questions Here is a list of frequently asked questions. C.1. Common questions Q: No LAN connection A: If no LAN connection is registered (the link LED next to the RJ45 socket does not light up), please check the wiring between the AnaGate and the hub or switch. You need to use a crossover cable when connecting the device directly to a PC. C.2.
FAQ - Frequent asked questions unsigned char CalcCRC( char * pBuffer, int nBufferLength ) { int i; unsigned char nCRC = pBuffer[2]; // skip the length bytes // XOR over all bytes in the message except the length information and the last byte for( i = 3; i < nBufferLength -1; i++ ) { nCRC ^= pBuffer[i]; } return nCRC; } When using the function CalcCRC the parameter pBuffer must point to the data buffer, which contains the already created complete data telegram.
Appendix D. Technical support The AnaGate hardware series and all existing programming interfaces are developed and supported by Analytica GmbH. Technical support can be requested as follows: Internet The AnaGate web site [http://www.anagate.de/en/index.html] of Analytica GmbH contains information and software downloads for AnaGate Library users: • Product updates featuring bug fixes or new features are available here free of charge.
Bibliography Books Other publications [NXP-I2C] NXP Semiconductors. Copyright © 2007 NXP Semiconductors. UM10204. I2C-bus specification and user manual. Rev. 03. 19.06.2007. [TCP2010] Analytica GmbH. Copyright © 2010 Analytica GmbH. Manual TCP-IP communication. Version 1.2.6. 15.05.2008.