XT2640OperatingManual 13July2016 Page134of187
SincetheXT2640communicatesentirelyusingthestandardASCIIcharacterset,methodsforsendingandreceivingcharacterstrings
mustbeused,rememberingtoalwaysterminatebothtransmittedandreceivedstringswiththe<CR>and/or<LF>characters.
Totransmitacommandstring(TransmitString)totheXT2640thefollowingisanexample–
Dim send_data As Byte() = System.Text.Encoding.ASCII.GetBytes(TransmitString + Chr(10))
Dim send_len As Integer = cmd_string.Length
enet_socket.GetStream.Write(send_data, 0, send_len + 1)
Toreceivearesponsestring(ReceiveString)fromtheXT2640thefollowingisanexample–
Dim sr As New System.IO.StreamReader(enet_socket.GetStream())
Dim ReceiveString as String = sr.ReadLine()
24.1.3 USB INTERFACE
Connector USBBconnector
Cablerequired USB2.0A‐BCable
Compatibility CompatiblewithWindowsXPandlateroperatingsystems
USBSpeed Full‐speed
USBDevice EnumeratesasaHumanInterfaceDevice(HID)oftheVendor‐specifictype
Driver Nonerequired
24.1.3.1 CONNECTINGTOTHEUSBINTERF ACE
TheUSBconnectorlocatedontherearpaneloftheXT2640mustbeconnectedtothecomputerorahubusingastandardUSBAB
typecable.Theuseofaqualitycableisparticularlyrecommendedifinterferenceislikely,aslowerqualitycableshavepoor
shielding(ifany)andhaveahighRFimpedanceinthegroundconnection.
TheXT2640doesnotrequireavendorsupplieddriver,sonoinstallationisrequired.WhentheXT2640isfirstconnectedtoa
computer(sometimestoeachspecificUSBportofacomputer)theoperatingsystemofthecomputermustloaditsnativeHIDdevice
driver,thismaytakeashortwhile.DuringthattimetheXT2640cannotbecommunicatedwithviatheUSB.TheXT2640appearsasa
standardHIDInputDevicewithVendor‐specificproperties,itisshownintheWindowsDeviceManagerasaHumanInterfaceDevice
‐>USBInputDevice.
24.1.3.2 WRITINGSOFTWARETOCONTROLTHEXT2640VIAUSB
SincetheXT2640appearsasastandardHIDDevicewithVendor‐specificproperties,youmustcommunicatethroughthestandard
Windows®interfaceforsuchdevices.Thiscanbeadifficulttask,soXiTRONincludesapairofDLLfilestoeasethiscommunication
(SLABHIDtoUART.dllandSLABHIDDevice.dll,bothofwhichmustbeaccessibletoyourprogram).Allattemptstoopentheport,
transmitstringsthroughtheport,receivestringsthroughtheportandclosetheportshouldbedirectlymadethroughsimplecallsto
theseDLLfiles.HeaderfilesdefiningthesecallsforVB.NET,forC#andforC/C++arealsoprovided(SLABCP2110.vb,SLABCP2110.cs
andSLABCP2110.hrespectively).
WhencompilingapplicationsusingtheVisualStudiodevelopmentplatformyoushouldcompileforx86processorsotherwisethere
maybeconflictswiththesuppliedDLLfiles.
NotethatmostcommunicationsrequireknowledgeoftheUSBVID(VendorID)andPID(ProductID)numbersusedbytheXT2640.
Theseare4292and34869respectivelyforallXT2640units.
BeforeyoursoftwarecancommunicatewiththeXT2640itgenerallymustcreateanobjectforthesocketandthenconfigureand
openit.
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
Toclosetheconnectionthefollowingisanexample.
HidUart_Close(usbdevice)
SincetheXT2640communicatesentirelyusingthestandardASCIIcharacterset,methodsforsendingandreceivingcharacterstrings
mustbeused,rememberingtoalwaysterminatebothtransmittedandreceivedstringswiththe<CR>and/or<LF>characters.
Althoughnotshownhere,itisrecommendedthatyoushouldcheckifthedevicehandleisactivebyusingthe
HidUart_IsOpened
functioncallpriormakingcallsfortransmittingorreceivingdata.Ifthiscallindicatesaninvalidhandlethenyoushouldrepeatthe
processofopeningasocketandobtaininganewdevicehandle.Thisisonlyneededwhensignificantinterferenceispresentandis
necessarybecausesomeoperatingsystems(e.g.Windows)disconnectaUSBdevicewhichhasinterference.
Totransmitacommandstring(TransmitString)totheXT2640thefollowingisanexample–
Dim send_data As Byte() = System.Text.Encoding.ASCII.GetBytes(cmd_string + Chr(10))
Dim send_len As Integer = cmd_string.Length
Dim written As Integer
HidUart_Write(usbdevice, send_data, send_len + 1, written)
Toreceivearesponsestring(ReceiveString)fromtheXT2640thefollowingisanexample–
' 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