Unable to set a custom terminator using configureTerminator
6 views (last 30 days)
Show older comments
Hey everybody, I'm having an issue that seems simple on the surface but I haven't been able to get any insight google searching. I'm using R2023b to communicate with a serial device, which we've already gotten to work before using python. In python, we have the read and write terminators as ">"and "\r", which work and were recommended to us by the manufacturers of the device. In matlab, the configureterminator function only allows us to use certain terminators however, and ">" and "\r" both gave me error messages when trying to set them as they're not valid inputs. I was able to work around this issue partially, by adding \r to the end of each writeline message I send. However, I'm lost as to how I can get readline to work with the proper terminator.
function init(~)
pause('on')
%define serial object and init settings
self = serialport("COM3",9600,"Databits",8,"Parity","none","StopBits",1,"Timeout",40);
%configure ascii terminator, CR/LF is not used because it
%apparently causes unintended results, and >, \r works based on
%additional documentation
%configureTerminator(self,">","\r");
writeline(self,'!PORTIN A \r');
pause(1);
readline(self)
writeline(self,'!PORTOUT C \r');
pause(10);
readline(self)
end
0 Comments
Answers (1)
Poorna
on 30 Apr 2024
Hi Jason,
I see you are trying to set the read and write terminators to read and write to your serial port. I see that you are getting errors while trying to set '>' and '\r' as read and write terminators respectively.
This is because '>' and '\r' are not valid inputs for the "configureTerminator" function. The inputs to this function should either be "CR" or "LF" or "CR?LF" or 0 to 255. So, instead of trying to set the terminators to '>' and '\r', trying setting them to their corresponding ascii values.
It is to be noted that '\r' is called 'carriage return' and it's ascii code is 13. So, instead of trying to set '\r' as the write terminator, try setting it to the value 13 or "CR". Similarly, instead of trying to set the read terminator as '>', try setting it to its ascii value which is 62.
So, you can configure the terminators something like below:
configureTerminator(self,13,62);
To know more about the "configureTerminator" function refer to the following documentation:
You can find the ascii codes of all the characters here:
Hope this Helps!
0 Comments
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!