override fun send()

in code/4diac-integration/src/main/kotlin/org/fbme/ide/integration/fordiac/deploy/communication/TCPDeviceCommunicationHandler.kt [95:124]


    override fun send(destination: String, request: String): String {
        val response: StringBuilder

        try {
            if (outputStream == null || inputStream == null) {
                throw DeploymentException(message = "$errorMessagePrefix trying to send but was not connected.")
            }
            outputStream?.writeByte(IEC_STRING_TAG)
            outputStream?.writeShort(destination.length)
            outputStream?.writeBytes(destination)
            outputStream?.writeByte(IEC_STRING_TAG)
            outputStream?.writeShort(request.length)
            outputStream?.writeBytes(request)
            outputStream?.flush()

            inputStream?.readByte()
            val size = inputStream?.readUnsignedShort() ?: 0
            response = StringBuilder(size)
            for (i in 0 until size) {
                response.append(inputStream?.readByte()?.toInt()?.toChar())
            }
        } catch (e: IOException) {
            throw DeploymentException(
                message = "Failed to send request to destination: '$destination'. ${e.message}",
                cause = e
            )
        }

        return response.toString()
    }