XT2640 Operating Manual
13 July 2016
Page 134 of 187
Since the XT2640 communicates entirely using the standard ASCII character set, methods for sending and receiving character strings
must be used, remembering to always terminate both transmitted and received strings with the <CR> and/or <LF> characters.
To transmit a command string (TransmitString) to the XT2640 the following is an example –
Dim send_data As Byte() = System.Text.Encoding.ASCII.GetBytes(Transmit Chr(10))
Dim send_len As Integer = cmd_string.Length
enet_socket.GetStream.Write(send_data, 0, se 1)
To receive a response string (ReceiveString) from the XT2640 the following is an example –
Dim sr As New System.IO.StreamReader(enet_socket.GetStream())
Dim ReceiveString as String = sr.ReadLine()
24.1.3
USB
INTERFACE
Connector
USB B connector
Cable required
USB 2.0 A‐B Cable
Compatibility
Compatible with Windows XP and later operating systems
USB Speed
Full‐speed
USB Device
Enumerates as a Human Interface Device (HID) of the Vendor‐specific type
Driver
None required
24.1.3.1
CONNECTING
TO
THE
USB
INTERFACE
The USB connector located on the rear panel of the XT2640 must be connected to the computer or a hub using a standard USB AB
type cable. The use of a quality cable is particularly recommended if interference is likely, as lower quality cables have poor
shielding (if any) and have a high RF impedance in the ground connection.
The XT2640 does not require a vendor supplied driver, so no installation is required. When the XT2640 is first connected to a
computer (sometimes to each specific USB port of a computer) the operating system of the computer must load its native HID device
driver, this may take a short while. During that time the XT2640 cannot be communicated with via the USB. The XT2640 appears as a
standard HID Input Device with Vendor‐specific properties, it is shown in the Windows Device Manager as a Human Interface Device
‐> USB Input Device.
24.1.3.2
WRITING
SOFTWARE
TO
CONTROL
THE
XT2640
VIA
USB
Since the XT2640 appears as a standard HID Device with Vendor‐specific properties, you must communicate through the standard
Windows® interface for such devices. This can be a difficult task, so XiTRON includes a pair of DLL files to ease this communication
(SLABHIDtoUART.dll and SLABHIDDevice.dll, both of which must be accessible to your program). All attempts to open the port,
transmit strings through the port, receive strings through the port and close the port should be directly made through simple calls to
these DLL files. Header files defining these calls for VB.NET, for C# and for C/C++ are also provided (SLABCP2110.vb, SLABCP2110.cs
and SLABCP2110.h respectively).
When compiling applications using the Visual Studio development platform you should compile for x86 processors otherwise there
may be conflicts with the supplied DLL files.
Note that most communications require knowledge of the USB VID (Vendor ID) and PID (Product ID) numbers used by the XT2640.
These are 4292 and 34869 respectively for all XT2640 units.
Before your software can communicate with the XT2640 it generally must create an object for the socket and then configure and
open it.
Dim num_devices As Integer
Dim usbdevice As System.IntPtr
HidUart_GetNumDevices(num_devices, 4292, 34869)
If (num_devices > 0 And HidUart_Open(usbdevice, 0, 4292, 34869) = HID_UART_SUCCESS) Then
HidUart_SetUartConfig(usbdevice, 115200, HID_UART_EIGHT_DATA_BITS, HID_UART_NO_PARITY, /
ID_UART_SHORT_STOP_BIT,
HID_UART_RTS_CTS_FLOW_CONTROL)
HidUart_SetTimeouts(usbdevice, 0, 1000)
End If
To close the connection the following is an example.
HidUart_Close(usbdevice)
Since the XT2640 communicates entirely using the standard ASCII character set, methods for sending and receiving character strings
must be used, remembering to always terminate both transmitted and received strings with the <CR> and/or <LF> characters.
Although not shown here, it is recommended that you should check if the device handle is active by using the
HidUart_IsOpened
function call prior making calls for transmitting or receiving data. If this call indicates an invalid handle then you should repeat the
process of opening a socket and obtaining a new device handle. This is only needed when significant interference is present and is
necessary because some operating systems (e.g. Windows) disconnect a USB device which has interference.
To transmit a command string (TransmitString) to the XT2640 the following is an example –
Dim send_data As Byte() = System.Text.Encoding.ASCII.GetBytes(cmd_ Chr(10))
Dim send_len As Integer = cmd_string.Length
Dim written As Integer
HidUart_Write(usbdevice, send_data, se 1, written)
To receive a response string (ReceiveString) from the XT2640 the following is an example –
' The USB only operates with byte arrays - so must handle each byte and detect the LF
' terminator
' Although usually all characters in a response are received in a single array, this cannot be
' relied upon