Summary of Contents for ICP DAS USA LinPAC-22 Series
Page 1
ICP DAS V1.0.0 Apr 2019 Warranty All products manufactured by ICP DAS are warranted against defective materials for a period of one year from the date of delivery to the original purchaser. Warning ICP DAS assume no liability for damages consequent to the use of this product. ICP DAS reserves the right to change this manual at any time without notice. The information furnished by ICP DAS is believed to be accurate and reliable. However, no responsibility is ...
ICP DAS 1. Introduction This manual is intended to be used as a reference for users who need to use API functions to communicate with XV-Boards inserted into an LP-22xx/52xx series controller via the Modbus protocol. 1.1. What is the I/O Expansion Bus? The LinPAC-22xx/52xx series provides an I/O expansion bus which can be used to implement various I/O functions, such as D/I, D/O, A/I, A/O, A/D, D/A, Timer/Counter, and other I/O functions.
ICP DAS 1.3. Specifications For more detailed specifications related to specific XV-Boards and the Modbus register table, refer to: http://ftp.icpdas.com.tw/pub/cd/linpac/napdos/lp-5000/lp-52xx/lp-5231/user_manual/xv-board_user_manual_v1.0.3.pdf LinPAC-52xx Series XV-Board API User Manual...
ICP DAS 2. XV-Board API functions The following is an overview of the API functions used by the LP-22xx/52xx series controller that contains an XV-Board. 2.1. modbusRequest Description: This function is used to send a Modbus protocol request. Syntax: [ C ] modbusRequest(char cPort, char cNetID, char cFunction, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen, WORD wTimeout, WORD *wT) Parameters:...
Page 6
ICP DAS Example: int RetValue, timeout=100, count=1, netid=1; int comport=COM1; /* Refer to [Remark 1] */ int function=1; /* Refer to [Remark 2] */ int addr=33; /* Refer to [Remark 3] */ char szBuf[80]; DWORD baudrate=115200; WORD wT; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit);...
Page 7
ICP DAS Remarks: [1] Refer to the communication port number in the table below when sending the Modbus protocol request. 'cPort’ parameter for the XV-Board module: 1=COM1=/dev/ttyO1. 'cPort' parameter for the RS-485 serial port: 2=COM2=/dev/ttyO2, 5=COM5=/dev/ttyO5. Note: Remote I/O modules can be remotely controlled through an RS-485 serial bus.
ICP DAS 2.2. modbusRequestXV Description: This function is used to send a Modbus protocol request in an LP-22xx/52xx system. Syntax: [ C ] modbusRequestXV(char cPort, char cFunction, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board. 1=COM1=/dev/ttyO1. cFunction: [Input] The Modbus RTU protocol function code.
Page 9
ICP DAS Example: int RetValue, count=1; int comport=COM1; /* Refer to [Remark 1] */ int function=1; /* Refer to [Remark 2] */ int addr=33; /* Refer to [Remark 3] */ char szBuf[80]; DWORD baudrate=115200; WORD wValue; switch(function) { case FC05ForceSingleCoil: case FC15ForceMultipleCoil: szBuf[0]=wValue &...
Page 10
ICP DAS Remarks: [1] Refer to the communication port number in the table below to send the Modbus protocol request. 'cPort’ parameter for the XV-Board module: 1=COM1=/dev/ttyO1. 'cPort' parameter for the RS-485 serial port: 2=COM2=/dev/ttyO2, 5=COM5=/dev/ttyO5. Note: Remote I/O modules can be remotely controlled through an RS-485 serial bus.
ICP DAS 2.3. getXVBitBack Description: This function is used to read back the channel status value from a specified DO module in an LP-22xx/52xx system using the Modbus protocol. Syntax: [ C ] getXVBitBack(char cPort, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board.
Page 12
ICP DAS Example: int RetValue, comport=COM1, count=4; int addr=0; /* Refer to [Remark 1] */ char szBuf[80]; DWORD baudrate=115200; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit); if (RetValue > 0) { printf("open COM%d failed!\n",comport); return FAILURE; memset(szBuf, 0, sizeof(szBuf));...
ICP DAS 2.4. getXVBit Description: This function is used to read the channel status value from a specified DI module in an LP-22xx/52xx system using the Modbus protocol. Syntax: [ C ] getXVBit(char cPort, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board.
Page 14
ICP DAS Example: int RetValue, comport=COM1, count=4; int addr=32; /* Refer to [Remark 1] */ char szBuf[80]; DWORD baudrate=115200; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit); if (RetValue > 0) { printf("open COM%d failed!\n",comport); return FAILURE; memset(szBuf, 0, sizeof(szBuf));...
ICP DAS 2.5. getXVRegBack Description: This function is used to read back the voltage float value from a specified AO module in an LP-22xx/52xx system using the Modbus protocol. Syntax: [ C ] getXVRegBack(char cPort, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board.
Page 16
ICP DAS Example: int RetValue, comport=COM1, count=1; int addr=33; /* Refer to [Remark 1] */ char szBuf[80]; DWORD baudrate=115200; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit); if (RetValue > 0) { printf("open COM%d failed!\n",comport); return FAILURE; memset(szBuf, 0, sizeof(szBuf));...
ICP DAS 2.6. getXVReg Description: This function is used to read the current input voltage value from a specified AI module in an LP-22xx/52xx system using the Modbus protocol. Syntax: [ C ] getXVReg(char cPort, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board.
Page 18
ICP DAS Example: int RetValue, comport=COM1, count=1; int addr=3; /* Refer to [Remark 1] */ char szBuf[80]; DWORD baudrate=115200; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit); if (RetValue > 0) { printf("open COM%d failed!\n",comport); return FAILURE; memset(szBuf, 0, sizeof(szBuf));...
ICP DAS 2.7. setXVBit Description: This function is used to set the status value for a specified DO module in an LP-22xx/52xx system using the Modbus protocol. Syntax: [ C ] setXVBit(char cPort, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board.
Page 20
ICP DAS Example: int RetValue, comport=COM1, count=4; int addr=0; /* Refer to [Remark 1] */ char szBuf[80]; DWORD baudrate=115200, dwValue=15; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit); if (RetValue > 0) { printf("open COM%d failed!\n",comport); return FAILURE; memset(szBuf, 0, sizeof(szBuf));...
ICP DAS 2.8. setXVReg Description: This function is used to set the voltage float value for a specified AO module in an LP-22xx/52xx system using the Modbus protocol. Syntax: [ C ] setXVReg(char cPort, WORD wAddr, WORD wCount, char szBuf, WORD wBufLen) Parameters: cPort: [Input] The number of the COM port for the XV-Board.
Page 22
ICP DAS Example: int RetValue, comport=COM1, count=1; int addr=32; /* Refer to [Remark 1] */ char szBuf[80]; DWORD baudrate=115200, dwValue=65535; /* Open the device file */ RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit); if (RetValue > 0) { printf("open COM%d failed!\n",comport); return FAILURE; memset(szBuf, 0, sizeof(szBuf));...
ICP DAS 3. Error Codes The following table provides a list of error codes used by Modbus-based APIs. Value Return code Description NoError OK. The function was successful. FunctionError Function use error. PortError Port open error. BaudRateError Set Baud Rate error. DataError Set data Bits error.
ICP DAS 4. Demo for XV-Boards 4.1. AI/O, DI/O Expansion Boards 4.1.1. AIO Location First, install the LinPAC AM335x SDK from the LinPAC CD or from the ICP DAS FTP site, and follow the steps described below to implement the demonstration. Refer to the setxvao.c, getxvao.c , and getxvai.c files in the path C:\cygwin\LinPAC_AM335x_SDK\examples\xvboard\ folder for details.
Page 25
ICP DAS Remarks: The following is a more detailed description of the demonstration. (1) In this program, the address value for the AO1 channel is 33. Refer to the Modbus register table for the XV310 module for more details. The table below provides the valid range for the register addresses.
Page 26
ICP DAS Read the Analog Input value for a single channel Step1: Transfer the getxvai.exe file to the LP-22xx/52xx module. Step2: Change the permissions for the file as shown below: # chmod 755 getxvai.exe Step3: Execute the program. # ./getxvai 1 // Input voltage is 10 V Remarks: The following is a description of the demonstration.
ICP DAS 4.1.2 DIO Location First, install the LP-52xx SDK from the LinPAC CD or from the ICP DAS FTP site, and follow the steps described below to implement the demonstration. Refer to the setxvdo.c, getxvdo.c, and getmodbus.c files in the path C:\cygwin\LinPAC_AM335x_SDK\examples\xvboard\ folder for more details.
Page 28
ICP DAS Connect the DO channel on the XV310 module to the DI channel on the M-7002 module, as illustrated below: M-7002 Power Supply Set and read back the Digital Output value from multiple channels Step1: Transfer the setxvdo.exe and getxvdo.exe files to the LP-52xx module. Step2: Change the permissions for the files as shown below: # chmod 755 setxvdo.exe # chmod 755 getxvdo.exe...
Page 29
ICP DAS Remarks: The following is a more detailed description of the demonstration. (1) Refer to the Modbus register table for the XV310 module for more details. The table below provides the valid range for the register addresses. Refer to Chapter 1.3: “Specifications” for details of other specifications for the XV-Board, together with the Modbus register table.
Page 30
ICP DAS Read the Digital Input value from multiple channels on the M-7002 module Step1: Transfer the getmodbus.exe file to the LP-52xx module. Step2: Change the permissions for the file, as shown below: # chmod 755 getmodbus.exe Step3: Execute the program. Read the DI0 channel on the M-7002 module # ./getmodbus 2 115200 1 2 32 1 100 Read the DI1 channel on the M-7002 module # ./getmodbus 2 115200 1 2 33 1 100 Read the DI2 channel on the M-7002 module # ./getmodbus 2 115200 1 2 34 1 100...
ICP DAS Appendix A. Revision History This chapter provides information related to the revision history of this document. The table below shows the revision history. Revision Date Description V1.0.0 Apr 2019 Initial issue LinPAC-52xx Series XV-Board API User Manual...