Mitsubishi Electric FR-A820-00046 Instruction Manual page 848

Fr-a800 series
Hide thumbs Also See for FR-A820-00046:
Table of Contents

Advertisement

(N) Operation via communication and its settings
● Program example: To switch to the Network operation mode
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;
//**** Open COM1 port ****
hCom = CreateFile("COM1", (GENERIC_READ | GENERIC_WRITE), 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hCom != NULL) {
//****Set COM1 port communication ****
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) {
//**** Set COM1 port timeout ****
GetCommTimeouts(hCom,&hTim);
hTim.WriteTotalTimeoutConstant = 1000;
hTim.ReadTotalTimeoutConstant = 1000;
hTim.ReadTotalTimeoutConstantSetCommTimeouts(hCom,&hTim); // Setting of changed timeout values
//**** Setting of command for switching the station number 1 inverter to the Network operation mode ****
sprintf(szCommand,"01FB10000");
nTx = strlen(szCommand);
//**** Generate sum code ****
nSum = 0;
for(i = 0;i < nTx;i++) {
}
//**** Generate 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);
//**** Send ****
if(nRet != 0) {
//**** Receive ****
}
}
CloseHandle(hCom);
}
}
5 - 646
Visual C++
(Ver.6.0) programming example
// Communication handle
// Structure for setting communication settings
hTim;
// Structure for setting timeouts
// Send buffer
// Receive buffer
// For storing buffer size
// For calculating sum code
nSum += szCommand[i];
nSum &= (0xff );
nRet = ReadFile(hCom,szRx,sizeof(szRx),&nRx,NULL);
if(nRet != 0) {
//**** Display receive data ****
for(i = 0;i < nRx;i++) {
printf("%02X ",(BYTE)szRx[i]); // Output received data to console
// Display ASCII code in Hexadecimal' In case of 0' , "30" is displayed.
}
printf("\n\r");
}
// Get current communication information
// Structure size setting
// Communication speed = 19200 bps
// Data length = 8 bits
// Parity check at even numbers
// Stop bit = 2 bits
// Setting of changed communication information
// Get current timeout values
// Write timeout 1 second
// Read timeout 1 second
// Send data (NET operation write)
// Send data size
// Initialize sum data
// Calculate sum code
// Mask data
// Initialize send buffer
// Initialize receive buffer
// ENQ code + number of send data + number of sum codes
// Close communication port
Parameters

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents