tcpclient Sending Nested Strings

2 visualizaciones (últimos 30 días)
Robert Stephens
Robert Stephens el 1 de Jun. de 2024
Respondida: Hassaan el 1 de Jun. de 2024
I'm trying to send the string below using the Matlab tcpclient. I need to send a string that contains two strings as shown below. I tried converting the entire string below to an asciiArray using the uint8(stringBelow) function and then fwrite(t, asciiArray, 'uint8') but that didn't work either.
Is there a way to send the exact composite string shown below in tcpclient?
>> writeline(t,"Unit.CommandAsText("myFile",1,"Millisecond")")
writeline(t,"Unit.CommandAsText("myFile",1,"Millisecond")")
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error.
To construct matrices, use brackets instead of parentheses.

Respuestas (1)

Hassaan
Hassaan el 1 de Jun. de 2024
An initial idea:
% Create the tcpclient object (assuming you have already connected)
% t = tcpclient('192.168.1.1', 12345);
% Properly escape the nested quotes in the string
compositeString = 'Unit.CommandAsText("myFile",1,"Millisecond")';
% Send the composite string directly
writeline(t, compositeString);
% Alternatively, convert the string to a uint8 array and use fwrite
asciiArray = uint8(compositeString);
write(t, asciiArray, 'uint8');
If you are still facing issues, ensure that:
  1. The TCP connection is properly established and configured.
  2. The server on the other end can interpret the received data correctly.

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by