フィルターのクリア

MATLAB Serial Port Communication Error

1 回表示 (過去 30 日間)
rohan
rohan 2011 年 4 月 18 日
I was trying to transmit some data(numbers) from my Renesas QSK 62P Plus micro controller to MATLAB through the serial port.
However, if I used the command 'fscanf(s)', it terminates the communication then and there (without the default 10 seconds getting over), displaying that it received nothing in the output variable.
But, if I use 'fread(s)', it gives me the correct ASCII codes of the numbers my micro controller generated. I tried to use both the 'fscanf(s)' and 'fread(s)' together, assigning them different output variables. That makes the communication run for the stipulated 10 seconds. But the data is divided between the 'fscanf(s)' output variable and the 'fread(s)' output variable.
Eg. if my microcontroller transmitted '12345', my output variable for 'fread(s)' contained 9 values in ASCII code, which includes '0' & '10' in the beginning and '10' and '13' at the end. However, on combining the 'fscanf(s)' and 'fread(s)' commands in a single execution, the 'fscanf(s)' takes the first two values, i.e. '0' & '10', and 'fread(s)' takes the rest of the ASCII values.
I am just guessing this scenario as when both the variables are executed together, the 'fscanf(s)' variable shows a 0X0 array, while 'fread(s)' shows all the values (7, in this case) except the first two values of '0' and '13', which it shows if 'fread(s)' command is exclusively executed.
My question is how do I make the 'fscanf(s)' command spit out the numbers? I tried to output characters just in case it had problem with numbers but encountered the same error. I know my communication works well as the data is well received, as shown in the ASCII output.

回答 (1 件)

Jarrod Rivituso
Jarrod Rivituso 2011 年 4 月 18 日
Just a hunch (I haven't worked with this stuff in quite some time), but what is the Terminator property of the serial port object? I think the default is LF (line feed), which is the ASCII value 10. Maybe if you change this to the carriage return (CR), which is the ASCII value 13, then fscanf would read up until it finds a '13' in your data.
s = serial('com1')
s.Terminator = 'CR'
Hope this helps!

カテゴリ

Help Center および File ExchangeAnalog Devices ADALM1000 Support from Data Acquisition Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by