Parameter
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
#include <stdio.h>
#include <windows.h>
void main(void){
HANDLE
hCom;
DCB
hDcb;
COMMTIMEOUTS
hTim;
char
szTx[0x10];
char
szRx[0x10];
char
szCommand[0x10]; //Command
int
nTx,nRx;
int
nSum;
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);
hDcb.DCBlength = sizeof(DCB);
hDcb.BaudRate = 19200;
hDcb.ByteSize = 8;
hDcb.Parity = 2;
hDcb.StopBits = 2;
bRet = SetCommState(hCom,&hDcb);
if (bRet == TRUE) {
//**** Makes a time out setting of COM1 port****
Get CommTimeouts(hCom,&hTim);
hTim.WriteTotalTimeoutConstant = 1000;
hTim.ReadTotalTimeoutConstant = 1000;
SetCommTimeouts(hCom,&hTim);
//**** Sets the command to switch the operation mode of the station 1 inverter to the network operation mode ****
sprintf(szCommand,"01FB10000");
nTx = strlen(szCommand);
//**** Generates sum code****
nSum = 0;
for (i = 0;i < nTx;i++) {
}
//**** Generates send data****
memset(szTx,0,sizeof(szTx));
memset(szRx,0,sizeof(szRx));
sprintf(szTx,"\5%s%02X",szCommand,nSum);
nTx = 1 + nTx + 2;
nRet = WriteFile(hCom,szTx,nTx,&nTx,NULL);
//**** Sending ****
if(nRet != 0) {
nRet = ReadFile(hCom,szRx,sizeof(szRx),&nRx,NULL);
//**** Receiving ****
}
}
CloseHandle(hCom);
}
}
Fig. 6-113:Programming example
FR-D700 SC EC
//Communication handle
//Structure for communication setting
//Structure for time out setting
//Send buffer
//Receive buffer
//For buffer size storing
//For sum code calculation
nSum += szCommand[i];
nSum &= (0xff);
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");
}
Communication operation and settings
®
®
Visual C++
(Ver.6.0)
//Retrieves current communication information
//Structure size setting
//Communication speed=19200bps
//Data length=8bit
//Even parity
//Stop bit=2bit
//Sets the changed communication data
/Obtains the current time out value
//Write time out 1s
//Read time out 1s
//Changed time out value setting
//Send data (NET operation write)
//Send data size
//Initialization of sum data
//Calculates sum code
//Masks data
//Initialization of send buffer
//Initialization of receive buffer
//ENQ code+send data+sum code
//Number of ENQ code+number of send data+number of sum code
//Close communication port
6 - 213