6.1 The explain of method interface defined in the dynamic library
int InitSock(char* SevIP,int SevPort);
Explain£ºbuild socket connections.
Explain of parameters£º
char* SevIP---ip address of server.
int SevPort---port of server.
int DeinitSock();
Explain£ºuninstall socket connection.
Note£ºMust appear in pairs with InitSock, ro may affect other operations.
int openi2c();
Explain£ºopen i2c.
int closei2c();
Explain£ºclose i2c.
seti2cspeed(int i2cPort, int i2cSpeed);
Explain£ºset the port and speed of i2c.
Explain of parameters£º
int i2cPort--- i2c port.
int i2cSpeed--- i2c speed.
return value£º 0£ºsuccess; not 0£ºwrong code.
int ReadregMulti(int i2cport, char idevaddr, int iregaddr, int iregaddrcount, char *buffer, int len);
Explain: read register
Explain of parameters£º
int i2cport --- i2c port.
char idevaddr--- device address.
int iregaddr--- register address.
int iregaddrcount--- register address occupation number of bytes.
char *buffer--- the start address which the read value stored.
int len--- the number of read register
WriteregMulti(int i2cport, char idevaddr, int iregaddr, int iregaddrcount, char *data, int len);
Explain:write register
Explain of parameters£º
int i2cport --- i2c port.
char idevaddr--- device address.
int iregaddr--- register address.
int iregaddrcount--- register address occupation number of bytes.
char *data--- the start address which the writing value stored.
int len--- the number of write register.
Note:when calling the ReadregPeriod function, count*period<4000000, this is because the socket read timeout is set to 4s, more than the number of dll will return -7, read error, error code:10060.
USBIO_OpenDevice(int deviceId)
Explain:Open USB Device
Explain of parameters:
int deviceId ---Serial number of device, 0 corresponding to the first device.
Returns: returns a handle, if have error is invalid.
USBIO_CloseDevice(int deviceId)
Explain:Close USB Device
Explain of parameters:
int deviceId ---Serial number of device, 0 corresponding to the first device.
USBIO_SetStream(int deviceId, int mode)
Explain:Set serial flow pattern.
Explain of parameters:
int deviceId ---Serial number of device, 0 corresponding to the first device.
int mode --- The specified model, see down
bit 1-bit0:I2C interface speed /SCL frequency, 00= and low /20KHz, 01= standard /100KHz (the default), 10= /400KHz, 11= high speed /750KHz
bit2:The SPI I/O /IO pin, 0= single input single output (D3 clock /D5 /D7) (the default), 1= double input double output (D3 clock /D5 D4 /D7 into the D6)
bit7:A sequence of bytes in SPI, 0= low in front, 1= high in the front.
Other reserved, must be 0.
USBIO_StreamI2C(int deviceId, int writeLength, char * writeBuffer, int readLength, char * readBuffer)
Explain:The processing of I2C data flow, 2 wire interface, the clock line for the SCL pin, the data line to the SDA pin (quasi bidirectional I/O), speed of about 56K byte.
Explain of parameters:
int deviceId ---Serial number of device, 0 corresponding to the first device.
int writeLength --- The number of bytes of data to write.
char * writeBuffer ---Pointer to a buffer, placed ready to write data, the first byte is usually I2C device address and the read and write direction.
int readLength --- Data bytes to read number.
char * readBuffer --- Pointer to a buffer, after the return is read into the data.
6.2 Control function return value limit.
The preparation of control binding C script functions, print format binding function requirements are as follows:
if(isSuccess)
printf("error=%s,return=%f","ok",0.0);
elseif(xxx)
printf("error=%s,return=%d","err 1, failed", 1);
elseif(yyy)
printf("error=%s,return=%d","err 2, failed", 2);
Note:"error=" value means state message of result executed, ok or failed, if ok, print ok, if failed, print 'err xx, failed.',The "return=" means the return value of the function definition. Only the successful implementation, namely OK, the tool will return value is passed to the control, failure, the tool will execute the print status information to the interface.
C scripting function corresponding control, special attention should be paid to the return value of function of each control requirements:
When the spectrum from the function into the drawing, In the C script function return value defines:
Format:{x1,y1}#{x2,y2}#{x3,y3}#...... such as:{3,4}#{5,6}#{7,8}#
Sample:
#include "stdio.h"
#define length 300
int fftdata(int argc, char ** argv )
{
int doubleArray[2][length];
int i;
int j;
for(i = 0; i < length; i++){
doubleArray[0][i] = i;
doubleArray[1][i] = i + 1;
}
printf("\n");
Note: "error=%s, return=" should be in the for cycle.
printf("error=%s,return=","ok");
for(j = 0; j < (length- 1); j++){
printf("{%d,%d}#", doubleArray[0][j],doubleArray[1][j]);
}
return 0;
}
If DUT network and I2C speed set well, it will transform 7 parameters to C script functions when execute the function script:
The first parameter: IP of the device; such as: 192.168.0.1
The second parameter: server port(always 4000);
The third parameter: I2c Port dec int , such as: 3;
The fourth parameter: I2c speed(it will transform without the unit, such as set it to 100K, just transform the 100 when transform).
The fifth parameter: DevAddress(The "DevAddress" will be changed to dec from hex when transform, such as the "Dev Address" is b6, it will change b6(hex) to 182(dec) when transform)
The sixth parameter: Method name
The seventh parameter: Identification of connection mode (-1 USB, 0 for Socket)
int functionName( int argc, char ** argv )
argc means the count of parameter, argv contains all value of parameters.
You can get the parameters by index when call 12C read and write in the C script, the parameters index start from 1, so:
argv[1] ==>device IP (string)
argv[2]==>server port (int)
argv[3]==>I2c port (int)
argv[4]==> I2c speed (int)
argv[5]==>DevAddress(int)
argv[6]==>(Param 1) If the Button is configured with the n parameters, can be ordered removed.
argv[7]==>(Param 2) If the Button is configured with the n parameters, can be ordered removed.
.
.
argv[n]==>(Param n) If the Button is configured with the n parameters, can be ordered removed.
argv[n+1]==>Function to be executed,Without '#', argv[argc-2] can get the method name.
argv[n+2]==>Connection mode, the argv[argc-1] can get the connection mode.
If the HiChannel menu item in the USB is properly configured, in performing functions, to the C script functions to the default delivery four parameters:
The first parameter: USB speed
The second parameter: DevAddress
The third parameters: the method name
The fourth parameters: identify the connection mode (-1 USB, 0 for Socket).
int functionName( int argc, char ** argv )
argc means the count of parameter, argv contains all value of parameters.
In the C script to call I2C to read and write can be indexed to remove parameter index parameters, starting from 1, so:
argv[1] ==>USB speed (int)
argv[2] ==>DevAddress(int)
argv[3]==>(Param1)If the Button is configured with the n parameters, can be ordered removed.
argv[4]==>(Param2)If the Button is configured with the n parameters, can be ordered removed.
.
.
argv[n]==>(Param n)If the Button is configured with the n parameters, can be ordered removed.
argv[n+1]==>Function to be executed, Without '#', argv[argc-2] can get the method name.
argv[n+2]==>Connection mode, the argv[argc-1] can get the connection mode.
Note: All parameters are string when they are transformed to C script, so different type parameters need to change type when use the parameters. Otherwise the HiChannel may load timeout or no response.
6.5 Explain of writing C script functions
Note:Write a C function format sample only as a reference, and can not directly use
When the need for I2C to read and write, first of all need to customize a header file to define the method call, the following definition header file reference sample:
#define CHIP_PORT atoi(argv[3]) //In Socket Connection, argv[3] defines I2C port
#define CHIP_ADDR atoi(argv[5])//In Socket Connection, argv[5] defines dev address
#define USB_ADDR atoi(argv[2]) //In Usb Connection, argv[2] defines dev address of usb device
#define USB_SPEED atoi(argv[1]) //In Usb Connection, argv[1] defines speed of usb
//The g_connect logo is a Sockect connection or a USB connection, g_connect is equal to 0, as the USB connection, g_connect is not 0, as the Sockect connection
#define INIT_CONNECT if (g_connect) {\
InitSock(argv[1],atoi(argv[2])); \
}else{\
if(USBIO_OpenDevice(0) == INVALID_HANDLE_VALUE ){ \
printf("error=%s,return=%d","err openerror,failed",-1); \
return; \
} \
USBIO_SetStream(0,USB_SPEED);\
}
#define DEINIT_CONNECT if (g_connect) {\
DeinitSock();\
}else{\
USBIO_CloseDevice(0);\
}
#define CHIP_MRD(REG_ADDR, P_RBUF, RLEN) if (g_connect) { ReadregMulti((CHIP_PORT), (CHIP_ADDR), (REG_ADDR), 1, ((char *)(P_RBUF)), (RLEN)); \
} else {\
unsigned char P_WBUF[2];\
P_WBUF[0] = USB_ADDR;\
P_WBUF[1] = REG_ADDR;\
USBIO_StreamI2C(0,2,(PVOID)pSend,RLEN,(PVOID)(P_RBUF));\
}
#define CHIP_MWR(REG_ADDR, P_WBUF, WLEN) if (g_connect) { WriteregMulti((CHIP_PORT), (CHIP_ADDR), (REG_ADDR), 1, ((char *)(P_WBUF)), (WLEN));\
} else {\
unsigned char P_RBUF;\
char *p = (char *)malloc((WLEN)+2);\
char *pw =(char *)(P_WBUF);\
int i = 0;\
p[0]= USB_ADDR;\
p[1]= REG_ADDR;\
for (i=0;i<(WLEN);i++) {\
p[i+2] = pw[i];\
};\
USBIO_StreamI2C(0,2+(WLEN),(PVOID)p,0,(PVOID)(&cRecv));\
}
Defines a header file, in the C script first need to introduce it, the following definition of C sample:
#include "stdio.h"
#include "string.h"
#include Custom header file
#include "USBIOX.H" //Must be introduced
extern int g_connect; //This line of code is a must.
int on_line(int argc, char ** argv)
{
INIT_CONNECT;
unsigned char chip_id[4];
unsigned char on_line;
CHIP_MRD(0x6f, &chip_id, 4);
on_line = (chip_id[2]==0x36) && (chip_id[3]==0x31);
if(on_line) {
printf("error=%s,return=%d","ok",1); }
else {
printf("error=%s,return=%d","ok",0); }
DEINIT_CONNECT;
}
//The internal private method, use 'static' to identify
static int demo_m2( int argc, char ** argv )
{
int i = 0;
printf("demo_m2........");
return 0;
}
//Just to be external calls, and are not shown on the tool list of UI functions, this time using the 'inner_' to identify
int inner_compile( int argc, char ** argv )
{
int i = 0;
printf("I'm inner function");
return 0;
}