Serial port reading function fread(obj) is giving output empty matrix 1 by 0
1 view (last 30 days)
Show older comments
i have a query regarding reading of serial port data. i am using a usb rs232 cable and has also been detected by matlab instrhwinfo.
actually, i just need to trigger a matlab program when the pin-2 (rx) of rs232 recieves a high voltage. can i do this by just connecting a battery power supply to pin-2(rx) and ground to pin-5(GND) of rs232 without the use of any microcontroller, pic,etc. can or cannot, i have tried this, and did not get an output as 1 or any other output.
when i typed fread(obj), output is empty matrix 1 by 0 and when other reading functions like fscanf, fgetl, get, i got an empty string.
i dont know where am i going wrong?
2 Comments
Answers (1)
Walter Roberson
on 23 Mar 2014
If your baud rate is wrong then the serial port will not be able to properly sense the message.
Have you considered wiring to CD (Carrier Detect) instead of Receive ? Then you can query the pin status; see http://www.mathworks.com/help/matlab/matlab_external/pinstatus.html
2 Comments
Walter Roberson
on 23 Mar 2014
I suggest +5V, it should be enough for all modern receivers.
You will not be able to detect characters using the shorting scheme. You might be able to detect BREAK. But Carrier Detect would be a lot easier, and can be done by shorting as well.
See Also
Categories
Find more on Simscape Electrical 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!