Mitsubishi Electronics FR-D720-008 Marine Battery User Manual


 
193
Communication operation and setting
4
PARAMETERS
(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, for example, 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
®
Visual C++
®
(Ver.6.0)
#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=8bit
hDcb.Parity = 2; // Even parity
hDcb.StopBits = 2; // Stop bit=2bit
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 1s
hTim.ReadTotalTimeoutConstant = 1000; // Read time out 1s
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
}
}