Mitsubishi Electric FR-F820-00046 Instruction Manual page 493

Fr-f800 series
Hide thumbs Also See for FR-F820-00046:
Table of Contents

Advertisement

Microsoft® Visual C++® (Ver.6.0) programming example
#include <stdio.h>
#include <windows.h>
void main(void){
HANDLE
DCB
COMMTIMEOUTS
char
char
char
int
int
BOOL
int
int
// ****
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
****
G
e
C t
o
m
h
D
c
b
D .
h
D
c
b
B .
h
D
c
b
B .
h
D
c
b
P .
h
D
c
b
S .
b
R
t e
=
if(bRet == TRUE) {
}
C
o l
s
e
H
}
}
492
5. PARAMETERS
5.12 (N) Communication operation parameters
hCom;
// Communication handle
hDcb;
// Structure for setting communication settings
hTim;
// Structure for setting timeouts
szTx[0x10];
// Send buffer
szRx[0x10];
// Receive buffer
szCommand[0x10];// Command
nTx,nRx;
// For storing buffer size
nSum;
// For calculating sum code
bRet;
nRet;
i;
****
****
m
S
a t
e t
h (
C
o
m
& ,
h
D
c
b
; )
C
B
e l
n
g
h t
=
s
z i
e
o
( f
D
C
B
; )
a
u
d
R
a
e t
=
1
9
2
0
; 0
y
e t
S
z i
e
=
; 8
r a
y t i
=
; 2
o t
p
B
s t i
=
; 2
S
e
C t
o
m
m
S
a t
e t
h (
C
o
m
& ,
h
D
c
b
; )
//
Set COM1 port timeout
****
****
G
e
C t
o
m
m
i T
m
e
o
u
s t
h (
C
o
m
& ,
h
i T
m
; )
h
i T
m
.
W
i r
e t
T
o
a t
i T l
m
e
o
u
C t
o
n
s
a t
t n
=
h
i T
m
R .
e
a
d
T
o
a t
i T l
m
e
o
u
C t
o
n
s
a t
t n
=
hTim.ReadTotalTimeoutConstantSetCommTimeouts(hCom,&hTim);// Setting of changed timeout values
//
Setting of command for switching the station number 1 inverter to the Network operation mode
****
s
r p
n i
( f t
z s
C
o
m
m
a
n
, d
0 "
1
F
B
1
0
0
0
0
; ) "
n
T
x
=
s
r t
e l
( n
z s
C
o
m
m
a
n
d
; )
//
Generate sum code
****
****
n
S
u
m
=
; 0
for(i = 0;i < nTx;i++) {
n
S
u
m
+
=
z s
C
o
m
m
a
n
[ d
; ] i
n
S
u
m
&
=
0 (
f x
; ) f
}
//
Generate send data
****
****
memset(szTx,0,sizeof(szTx));
m
e
m
s
e
( t
z s
R
x
0 ,
s ,
z i
e
o
( f
z s
R
x
; ) )
sprintf(szTx,"\5%s%02X",szCommand,nSum);// ENQ code + send data + sum code
n
T
x
=
1
+
n
T
x
+
; 2
nRet = WriteFile(hCom,szTx,nTx,&nTx,NULL);
//
Send
****
****
if(nRet != 0) {
nRet = ReadFile(hCom,szRx,sizeof(szRx),&nRx,NULL);
//
Receive
****
****
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");
}
}
a
n
d
e l
h (
C
o
m
; )
/ /
G
t e
c
/ /
t S
u r
c
/ /
C
o
m
m
/ /
D
a
a t
/ /
P
r a
y t i
/ /
S
o t
p
/ /
S
e
t t
n i
/ /
G
t e
c
1
0
0
; 0
/ /
W
i r
e t
1
0
0
; 0
/ /
R
e
a
d
/ /
S
e
n
d
/ /
S
e
n
d
/ /
n I
t i
a i
z i l
/ /
C
a
c l
u
/ /
M
a
k s
// Initialize send buffer
/ /
Initialize receive buffer
/ /
E
N
Q
****
/ /
C
o l
s
e
r u
e r
t n
c
o
m
m
u
n
c i
t a
o i
n
i
f n
r o
m
t a
o i
n
u t
e r
s
z i
e
s
e
t t
n i
g
u
n
c i
t a
o i
n
s
p
e
e
d
=
1
9
2
0
0
b
p
s
e l
n
g
h t
=
8
b
s t i
c
h
e
k c
t a
e
v
e
n
n
u
m
b
e
s r
b
t i
=
2
b
s t i
g
f o
c
h
a
n
g
e
d
c
o
m
m
u
n
c i
t a
o i
n
i
f n
r o
m
r u
e r
t n
i t
m
e
o
t u
v
a
u l
e
s
i t
m
e
o
t u
1
s
e
c
o
n
d
i t
m
e
o
t u
1
s
e
c
o
n
d
****
d
a
a t
(
N
E
T
o
p
r e
t a
o i
n
w
t i r
) e
d
a
a t
s
z i
e
e
s
u
m
d
a
a t
a l
e t
s
u
m
c
o
d
e
d
a
a t
c
o
d
e
+
n
u
m
b
r e
f o
s
e
n
d
d
a
a t
+
n
u
m
b
c
o
m
m
u
n
c i
t a
o i
n
p
o
t r
t a
o i
n
r e
f o
s
u
m
c
o
d
e
s

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents