Problems to read from serial port using Port FTDI USB to Serial RS232 Adapter Cable
21 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm using Matlab R2022a. As part of a guide project, I'm trying to read data from a balance (baxtran bt1500) using a serial port adapter (https://www.startech.com/en-es/cards-adapters/icusb2321f). The problem is that when I try to read the data the time run out (Timeout=10, see below) and readline(serialDevice) is empty. I have tried to increase the waiting time, but it never read the port.
My code:
serialDevice=serialport("COM5",9600)
configureTerminator(serialDevice,"CR/LF")
data=readline(serialDevice)
Output:
serialDevice =
Serialport with properties:
Port: "COM5"
BaudRate: 9600
NumBytesAvailable: 0
Show all properties, functions
Port: "COM5"
BaudRate: 9600
NumBytesAvailable: 0
ByteOrder: "little-endian"
DataBits: 8
StopBits: 1
Parity: "none"
FlowControl: "none"
Timeout: 10
Terminator: "LF"
BytesAvailableFcnMode: "off"
BytesAvailableFcnCount: 64
BytesAvailableFcn: []
NumBytesWritten: 0
ErrorOccurredFcn: []
UserData: []
Warning: The specified amount of data was not returned
within the Timeout period for 'readline'.
'serialport' unable to read any data. For more
information on possible reasons, see serialport Read
Warnings.
data =
[]
Is there any way to solve this conexion problem?
Thank you very much
0 Commenti
Risposte (1)
Sachin Lodhi
il 6 Set 2023
Hello José,
Based on my understanding of your issue, it seems that you are facing difficulties reading data from a serial port using Port FTDI USB to Serial RS232 Adapter Cable. Specifically, you are encountering empty data.
Typically, users configure a FIFO read block in their model's serial I/O to execute faster than the model receives data. This configuration helps prevent the receive FIFO buffer from overflowing. However, it is important to consider the possibility that a FIFO Read block may not have a message on its output which may cause empty data.
The receive FIFOs may have too few characters for a FIFO read operation. In such cases, a model that receives serial I/O can have a FIFO Read block that handles this situation. Depending on your configuration, the FIFO Read block can either return the last message it received or return a zero-length message.
To get a better understanding about handling a FIFO Read block that does not have a message on its output, please refer to the following MATLAB documentation: RS-232 Legacy Drivers - MATLAB & Simulink (mathworks.com).
I hope this information helps you resolve your issue.
Thanks,
Sachin
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!