FAQ TWedge
How to Send Data to a Device
How to Send Data to a Device
TWedge V2
Solution: TWedge provides the function WriteToDevice () for this purpose. WriteToDevice () accepts two parameters:
- The first one specifies the data which should be sent to the device.
- The second parameter specifies the timeout (in milliseconds) for this operation.
The following example sends two lines of text: The first line prompts the device for accepting the username, the second line sends the username. Each line is terminated by a newline character (\n line feed):
WriteToDevice ("user\n", 1000);
WriteToDevice ("sysadmin\n", 1000);
TWedge V3
Solution: For this purpose TWedge provides the Javascript member function WriteData (). This function exists in two variants with different parameters.:
- Integer WriteData (Array arrData, Integer nTimeout)
- Integer WriteData (String sData, Integer nTimeout, String sEncoding = "Latin1")
The following example sends data one time as binary array and one time as string. Inside of a string you can encode a line feed with the escape sequence \n:
var arrSend = [0x48, 0x65, 0x6c, 0x6c, 0x6f]; hConn.WriteData (arrSend, 200);
hConn.WriteData ("Hello\n", 1000);
hConn is the actual connection object.