Problem with serialport communication

14 views (last 30 days)
René Lampert
René Lampert on 24 Jul 2021
Answered: dpb on 24 Jul 2021
Hello,
I have the following problem with the serialport command. My goal is to connect a device - in my case a water cooling system - with Matlab to communicate and later on to create a GUI. To communicate I have used the serialport command . The creation of the serialport object was fine, but the problem ist that I only can send one command (in ASCII code) with the writeline command. This first command gets executed correctly and I can read the answer from the device. But when I send another command to the device it will not get executed anymore and reading the answer is also not possible. In a terminal program- in my case hTerm - everything works fine. The settings for my serialport object are:
I'm not sure what the last six properties are in detail and from the documentaion side I dont really get in to it to be honest. I guess something is wrong with the settings of these properties. Do you have any suggestions what the cause of my problem is?
Thanks in advance

Accepted Answer

dpb
dpb on 24 Jul 2021
Extremely difficult to debug what we can't simulate in cases like this without access to the instrument...
But, the last properties of the serialport object are just what the doc says they are -- the BytesAvailableFcn stuff is related to how you set up the interface to have and use (or not) a callback function to handle the BytesAvailable condition -- it's either 'off' (no callback so the other two are immaterial or 'byte' (trigger the callback function when get the specified number of bytes in the device buffer) or 'terminator' (trigger the callback function when get the specified terminator 'Terminator').
The 'NumBytes' values would seem self-evident as to what are; the last is just an error condition callback function to handle a read/write error. I'm guessing without having used it (this machine doesn't even have a serial port so it's a little tough) that without anything there, errors are silently ignored so you might ought to have something there even if it's just a simple echo to the screen function to let you know...it might have something associated with the callback that could give you some klews as to what's going on.
You might try to see if you can code the functionality with the old serial() device and get it working there and then transition...I've seen a number of postings about new serialport implementation that lead one to think that since it is pretty new yet there may well be bugs and/or unknown warts inside it as yet.
There are some examples at the "Transition Your Code..." link that can get to from the doc under the "Compatibility Considerations" link -- some of those might help in setting up your code.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!