118153-001 Rev. B
18
4.3.3 USB Example Code
The following code snippet of C# code declares a USB port, calls FindTheHid()
and if it is found writes out a report. The code then waits 50ms for a response.
If a response is received the variable count is assigned the number of bytes
received.
int
len;
//
Length
of
message
in
buf
byte
buf[]
=
new
byte[128];
//
holds
message
to
be
sent
usbPort
=
new
usbDll
();
string
tmp
=
""
;
string
rptstr
=
""
;
int
c,
count;
if
(usbPort.FindTheHid())
//
Search
the
list
if
HID
devices
and
find
{
//
the
Spellman
HID
&
PID
//
Figure
out
how
many
buffers
required
to
send
report
int
blocksToSend
=
len
/
64
;
if
(len
>
blocksToSend
*
usbconst
.rpt_size)
block+;
for
(
int
iBlk
=
0;
iBlk
<
blocksToSend;
iBlk++)
//
for
each
report
{
for
(
int
i
=
0;
i
<
len;
i++)
//
format
byte
buffer
as
string
{
str
=
str
+
System.
Convert
.ToChar(buf[i]);
}
usbPort.WriteReport(str);
//
write
report
to
uX
}
//
Wait
for
report
back
from
uX
while
(timeout_cnt
<
50)
//
Response
timeout
counter
loop
{
rptstr
=
usbPort.ReadReport();
//
Read
report
(if
any
from
uX)
tmp
=
tmp
+
rptstr;
//
concatenate
chars
c
=
rptstr.Length;
//
get
length
of
string
if
(rptstr.Contains((
char
)0x03))
//
Check
for
STX
terminating
char
{
//
If
found,
save
char
count
count
=
tmp.Length;
//
and
exit
loop
break
;
}
if
(c
>
0)
{
count
+=
c;
timeout_cnt
=
0;
}
Else
//
if
no
buffer
from
uX
increment
timeout
counter
{
time+;
}
Thread
.Sleep(1);
}
}
Содержание uX SERIES
Страница 11: ...uX MANUAL 4 118151 001 REV A Figure 2 1 50kV uX DIMENSIONS ...
Страница 12: ...uX MANUAL 5 118151 001 REV A Figure 2 2 65kVuX DIMENSIONS ...
Страница 16: ...uX MANUAL 9 118151 001 REV A Table 3 2 DC Input Filament Connections ...
Страница 17: ...uX MANUAL 10 118151 001 REV A Figure 3 3 Monitors Voltage Current Control Connections ...
Страница 18: ...uX MANUAL 11 118151 001 REV A Figure 3 4 Recommended Interlock HV on Configurations ...