modelica-3rdparty / Modelica_DeviceDrivers

Free library for interfacing hardware drivers to Modelica models. There is support for joysticks, keyboards, UDP, TCP/IP, LCM, MQTT, shared memory, AD/DA converters, serial port and other devices.
BSD 3-Clause "New" or "Revised" License
77 stars 31 forks source link

How to handle a telnet-like protocol? #359

Closed kvid closed 2 years ago

kvid commented 2 years ago

I've tried Modelica_DeviceDrivers.Blocks.Communication.TCPIP_Client_IO in OMEdit to access an existing remote service that has a telnet-like protocol where both the request and the response are ASCII/ANSI encoded strings terminated with CR+LF. Capturing the whole response as a single string seems to work as long as the expected receiving packet size is larger than the actual response, but I've not yet found a way to send the request string without including one or more zero bytes at the end of the string. The current code seems to require one zero byte to terminate a string, and also fill the following bytes with zeros up to a packet size that seems to be fixed for the whole session.

Can any of you suggest how I can use any of the existing library blocks or functions to send a string request without zero bytes to my remote service. In my use case, I don't really need the packaging concept, but is of course willing to use it if that makes things easier. I've tried writing my own blocks calling the same library functions as e.g. the Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.AddString, but these library functions seems to be very tightly coupled with the packaging concept and fixed size packets, so I've not yet found a way to enforce sending a pure string packet without the zero bytes.

bernhard-thiele commented 2 years ago

As you mentioned, the communication is rather tightly coupled with the packaging concept. The main use case for the library is exchanging fixed size packages holding Integers and Reals. Strings are supported, but string processing during simulation sometimes had issues in Modelica tools (might have improved, not used that feature in more recent times). Unfortunately, I don't have a good suggestion for your use case with what is available in MDD and since nobody else jumped in, I will close this issue.