#
i nc l u d e
<
s t d i o
.
h
>
#
i nc l u d e
<
wi n s o c k
.
h
>
i n t
m a i n
( )
{
ch a r
c m d
[
2 5 6
]
=
" * I D N ? \ r \ n "
;
ch a r
a n s
[
2 5 6
]
=
" "
;
/ /
i n i t
s o c k e t s
( B e r k e l e y
s t y l e ,
U N I X
c o m pa t i b l e)
WS A D A T A
ws a d a ta
;
WS A S t a r t u p
(
2
,
&
ws a d a t a
);
/ /
c r ea t e
T C P
s o c k e t
SO C K E T
s o c k
=
s o c k e t
(
A F _ I N E T
,
S O C K _ S TR E A M
,
I P P R O TO _ T C P
);
/ /
bi n d
s o c k e t
t o
d yn a m i c
l o c a l
p o r t
SO C K A D DR _ I N
s o c k a d d r _ i n
;
m e m s e t
(&
s o c k a d d r _ in
,
0
,
s i z e o f
(
s o c k a d d r _ in
) );
s o c k a d d r _ in
.
s i n _ f a m i l y
=
A F _ I N E T
;
/ /
U D P ,
T C P
s o c k a d d r _ in
.
s i n _ p o r t
=
h t o n s
(
1 0 0 0 1
);
/ /
R e m o t e
p o r t
s o c k a d d r _ in
.
s i n _ a dd r
.
S _u n
.
S _ u n _b
.
s _ b 1
=
1 9 2
;
/ /
I P
a d d r e s s
s o c k a d d r _ in
.
s i n _ a dd r
.
S _u n
.
S _ u n _b
.
s _ b 2
=
1 6 8
;
/ / ( ad j u s t t o y o u r
s o c k a d d r _ in
.
s i n _ a dd r
.
S _u n
.
S _ u n _b
.
s _ b 3
=
1 6
;
/ / e n v i r o n m e n t )
s o c k a d d r _ in
.
s i n _ a dd r
.
S _u n
.
S _ u n _b
.
s _ b 4
=
2 2 1
;
/ /
c o nn e c t
t o
d e v i c e
(t h r e e
wa y
h an d s h a k e)
c o nn e c t
(
s o c k
,
(
SO C K A D DR
* )&
s o c k a d d r _ i n
,
s i z e o f
(
SO C K A D DR _ I N
) );
/ /
s e nd
c o m m a n d
t o
d e v i c e
s e nd
(
s o c k
,
c m d
,
(
i n t
)
s t r l e n
(
c m d
),
0
);
/ /
r e ad
a n s we r
f r o m
d e v i c e
un t i l
<C R ><L F >
i s
f o u n d
f o r
( ; ; )
{
ch a r
b u f
[
2 5 6
]
=
" "
;
i n t
l e ng t h
=
r e c v
(
s o c k
,
bu f
,
s i z e o f
(
b u f
),
0
);
i f
(
l e n g t h
<=
0
)
b r e a k
;
bu f
[
l e n g t h
]
=
0
;
s t r n ca t
(
an s
,
b u f
,
s i z e o f
(
an s
)
-
s t r l e n
(
an s
)
-
1
);
ch a r
*
c r l f
=
s t r s t r
(
an s
,
" \ r \ n "
) ;
i f
(
c r l f
! =
N U L L
)
{
*
c r l f
=
0
;
b r e a k
;
}
}
/ /
c l o s e
s o c k e t
(t h r e e
wa y
h an d s h a k e)
a n d
c l ea n
up
c l o s e s o c k e t
(
s o c k
);
WS A C l e a n up
( );
/ /
pr i n t
a n s we r
pr i n t f
(
" % s \ n "
,
an s
) ;
r e t u rn
0
;
}
SCPI protocol common instruction set | Last changed on: 2020-10-07 |
www.iseg-hv.com
23/61