Mitsubishi Electric FR-HC2-7.5K Instruction Manual page 111

Hide thumbs Also See for FR-HC2-7.5K:
Table of Contents

Advertisement

Description of parameters
(7) Instructions for the program
1) When data from the computer has any error, the converter 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 converter 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
Example of clearing parameters of the converter
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 a command to clear parameters of the station 1 converter. 
sprintf(szCommand,"01FC15A5A");
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);
}
}
104
®
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=8 bits
// Even parity
// Stop bit=2 bits
// 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 (Parameter clear)
//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

Advertisement

Table of Contents
loading

This manual is also suitable for:

Fr-hc2-h7.5kFr-hc2

Table of Contents