Mitsubishi Electric FR-E720-0.1K(SC) Instruction Manual page 224

Fr-e700 series
Table of Contents

Advertisement

Communication operation and setting
(6)
Instructions for the program
1) 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.
2) 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.
3) 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
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);// ENQ code+send data+sum code
nTx = 1 + nTx + 2;
nRet = WriteFile(hCom,szTx,nTx,&nTx,NULL);
//∗∗∗∗ Sending ∗∗∗∗
if(nRet != 0) {
//∗∗∗∗ Receiving ∗∗∗∗
}
}
CloseHandle(hCom);
}
}
224
®
Visual C++
//Communication handle
//Structure for communication setting
hTim;
// Structure for time out setting
// Send buffer
// Receive buffer
// For buffer size storing
// For sum code calculation
nSum += szCommand[i];
nSum &= (0xff);
nRet = ReadFile(hCom,szRx,sizeof(szRx),&nRx,NULL);
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");
}
®
(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
// Number of ENQ code+number of send data+number of sum code
// Close communication port

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents