Operator Reference

send_dataT_send_dataSendDataSendDatasend_data (Operator)

send_dataT_send_dataSendDataSendDatasend_data — Send arbitrary data to external devices or applications using a generic socket communication.

Signature

send_data( : : Socket, Format, Data, To : )

Herror T_send_data(const Htuple Socket, const Htuple Format, const Htuple Data, const Htuple To)

void SendData(const HTuple& Socket, const HTuple& Format, const HTuple& Data, const HTuple& To)

void HSocket::SendData(const HString& Format, const HTuple& Data, const HTuple& To) const

void HSocket::SendData(const HString& Format, const HString& Data, const HString& To) const

void HSocket::SendData(const char* Format, const char* Data, const char* To) const

void HSocket::SendData(const wchar_t* Format, const wchar_t* Data, const wchar_t* To) const   ( Windows only)

static void HOperatorSet.SendData(HTuple socket, HTuple format, HTuple data, HTuple to)

void HSocket.SendData(string format, HTuple data, HTuple to)

void HSocket.SendData(string format, string data, string to)

def send_data(socket: HHandle, format: str, data: HTupleType, to: MaybeSequence[Union[int, str]]) -> None

Description

send_datasend_dataSendDataSendDatasend_data sends arbitrary data over a socket connection. The sent data is converted to a binary network packet from a value (or a tuple of values) using the parameter FormatFormatFormatformatformat as specification and is well-suited to communicate with external devices or applications. This operator does not support the standard 'HALCON'"HALCON""HALCON""HALCON""HALCON" protocol, but is intended for arbitrary data transfer.

The parameter FormatFormatFormatformatformat specifies how to convert the given tuples to a binary packet. It uses one or multiple qualifier characters each followed by an optional modifier and repeat count. Most qualifiers require a single value in the DataDataDatadatadata parameter which will be converted.

The following characters are allowed in this format string:

Integer values:

'c':

One byte = 8 bit, signed.

'C':

Same as 'c' but unsigned.

's':

Two bytes = 16 bit, signed.

'S':

Same as 's' but unsigned.

'i':

Four bytes = 32 bit, signed.

'I':

Same as 'i' but unsigned.

'q':

Sight bytes = 64 bit, signed (only available on 64bit architectures).

'Q':

Same as 'q' but unsigned.

Float values:

'f':

Float, 4 bytes = 32 bit.

'd':

Double, 8 bytes = 64 bit.

String values:

'A':

String (default length 1024 bytes), padded with spaces.

'a':

String with arbitrary binary data. When sending data, the whole memory block will be transmitted and the size will be determined automatically. When receiving, the length argument must always be provided explicitly.

'Z':

String (default length 1024 bytes), padded with NULL-Bytes and will be NULL terminated when sending.

'z':

String with variable length, the length modifier specifies the maximum length (default length 1024 bytes).

Special characters which do not require a value as DataDataDatadatadata parameter:

'-':

A single byte is written as binary NULL or when reading, a NULL-Byte is skipped.

'_':

A single byte is written as space (binary 0x20) or when reading, a space byte is skipped.

' ':

Ignored, can be used to enhance readability of the format string.

Modifiers which can be used after one of the qualifiers above:

'n':

Convert the integer or float value when writing to or when reading from network byte order (big endian) to host byte order.

'N':

Convert the integer or float value when writing to or when reading from Intel byte order (little endian) to host byte order.

'0-n':

Specify a repeat count for the preceding qualifier, e.g., 'c5' means the same as 'ccccc' (and requires therefore a tuple of 5 values) but 'A10' means a string with a size of 10 bytes (and requires only one value).

The modifiers 'n' and 'N' can also be used as first character in the format string and set the default byte order. 'n', which means network byte order, is the default byte order when nothing else is specified.

For UDP connections the binary data must be transferred in one network packet so that the size of the binary data must not be bigger than one network packet. Usually this means it should be smaller than the MTU (maximum transfer unit) of the interface, which is usually about 1500 bytes, but only 576 bytes are guaranteed (1280 bytes for IPv6).

The parameter ToToTototo should be left empty for socket connections that are already bound (all TCP connections and bound UDP connections), but in case of an unbound UDP connection it must be used to specify the IP address or host name and port number of the communication partner.

Execution Information

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

Parameters

SocketSocketSocketsocketsocket (input_control)  socket HSocket, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Socket number.

FormatFormatFormatformatformat (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Specification how to convert the data.

Default: 'z' "z" "z" "z" "z"

DataDataDatadatadata (input_control)  string(-array) HTupleHTupleTypeHTupleHtuple (string / real / integer / handle) (string / double / int / long / HHandle) (HString / double / Hlong / HHandle) (char* / double / Hlong / handle)

Value (or tuple of values) holding the data to send.

ToToTototo (input_control)  string(-array) HTupleMaybeSequence[Union[int, str]]HTupleHtuple (string / integer) (string / int / long) (HString / Hlong) (char* / Hlong)

IP address or hostname and network port of the communication partner.

Default: []

List of values: [], ['localhost',3000]["localhost",3000]["localhost",3000]["localhost",3000]["localhost",3000]

Possible Predecessors

open_socket_connectopen_socket_connectOpenSocketConnectOpenSocketConnectopen_socket_connect, socket_accept_connectsocket_accept_connectSocketAcceptConnectSocketAcceptConnectsocket_accept_connect, get_socket_paramget_socket_paramGetSocketParamGetSocketParamget_socket_param, set_socket_paramset_socket_paramSetSocketParamSetSocketParamset_socket_param

Possible Successors

close_socketclose_socketCloseSocketCloseSocketclose_socket

See also

receive_datareceive_dataReceiveDataReceiveDatareceive_data

Module

Foundation