Communication operation and setting
Parameter
6 - 254
Instructions for the program
When data from the computer has any error, the inverter does not accept that data. Hence, in the user
program, always insert a retry program for data error.
All data communication, e.g. run command or monitoring, are started when the computer gives a
communication request. The inverter does not return any data without the computer's request.
Hence, design the program so that the computer gives a data read request for monitoring, etc. as
required.
Program example
To change the operation mode to computer link operation
Programming example of Microsoft® Visual C++® (Ver.6.0)
Fig. 6-129:
Programming example
#include <stdio.h>
#include <windows.h>
void main(void){
HANDLE hCom; //Communication
handle
DCB
hDcb;
//Structure for communication setting
COMMTIMEOUTS
hTim;
//Structure for time out setting
char szTx[0x10];
//Send
buffer
char szRx[0x10];
//Receive
buffer
char szCommand[0x10];
//Command
int
nTx,nRx;
//For buffer size storing
int
nSum;
//For sum code calculation
BOOL bRet;
int nRet;
int i;
//**** Opens COM1 Port****
hCom = CreateFile ("COM1", (GENERIC_READ | GENERIC_WRITE), 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hCom != NULL) {
//**** Makes a communication setting of COM1 port****
GetCommState(hCom,&hDcb); //Retrieves current communication information
hDcb.DCBlength = sizeof(DCB);
//Structure size setting
hDcb.BaudRate = 19200;
//Communication speed=19200bps
hDcb.ByteSize = 8;
//Data length=8bits
hDcb.Parity = 2;
//Even parity
hDcb.StopBits = 2;
//Stop bit=2bits
bRet = SetCommState(hCom,&hDcb);
//Sets the changed communication data
if (bRet == TRUE) {
//**** Makes a time out setting of COM1 port****
Get CommTimeouts(hCom,&hTim);
/Obtains the current time out value
hTim.WriteTotalTimeoutConstant = 1000;
//Write time out 1 s
hTim.ReadTotalTimeoutConstant = 1000;
//Read time out 1 s
SetCommTimeouts(hCom,&hTim);
//Changed time out value setting
//**** Sets the command to switch the operation mode of the station 1 inverter to the network operation mode ****
sprintf(szCommand,"01FB10000");
//Send data (NET operation write)
nTx = strlen(szCommand);
//Send data size
//**** Generates sum code****
nSum = 0;
//Initialization of sum data
for (i = 0;i < nTx;i++) {
nSum += szCommand[i];
//Calculates sum code
nSum &= (0xff );
//Masks data
}
//**** Generates send data****
memset(szTx,0,sizeof(szTx));
//Initialization of send buffer
memset(szRx,0,sizeof(szRx));
//Initialization of receive buffer
sprintf(szTx,"\5%s%02X",szCommand,nSum);
//ENQ code+send data+sum code
nTx = 1 + nTx + 2;
//Number of ENQ code+number of send data+number of sum code
nRet = WriteFile(hCom,szTx,nTx,&nTx,NULL);
//**** Sending ****
if(nRet != 0) {
nRet = ReadFile(hCom,szRx,sizeof(szRx),&nRx,NULL);
//**** Receiving ****
if(nRet != 0) {
//**** Displays the receive data ****
for(i = 0;i < nRx;i++) {
printf("%02X ",(BYTE)szRx[i]);//Consol output of receive data
//Displays ASCII coder in hexadecimal. Displays 30 when "0"
}
printf("\n\r");
}
}
}
CloseHandle(hCom);
//Close communication port
}
}
Содержание fr-e700 series
Страница 2: ......
Страница 4: ......
Страница 20: ...Contents XVI ...
Страница 112: ...Operation panel Operation 4 20 ...
Страница 154: ...External operation Basic settings 5 42 ...
Страница 528: ...CC Link IE Field Network Basic Parameter 6 374 ...
Страница 562: ...Meters and measuring methods Troubleshooting 7 34 ...
Страница 606: ...A 30 Index Appendix ...
Страница 607: ......