- Firstly, sending data over a serial port depends on a lot about the format accepted by the receiving device i.e. Digitimer DS5 and its interpretation to generate the desired waveforms.
- Secondly, to get a continuous representation of data is dependent on the way the serial communication is formatted as it is inherently packet based communication which leads to you observing intermittent signals.
- Lastly, the device i.e. Digitimer DS5 that is to be controlled and communicated via serial ports usually have some specific protocols and commands to establish the communication format and set configurations.
Serial port Communication - Send Numeric Values
11 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm trying to control the electric stimulator Digitimer DS5 with Matlab through the serial port. I got a cable that goes from serial port to BNC. Serial port on my computer, BNC on the electrical stimulator. For now I just try to look on an oscilloscope (TekTronix TDS 320) that the signal I'm sending is correct.
I'm writing a simple array or a sine in double, and write in the serial port, and observing in the oscilloscope. I keep have an intermitting signal, instead of something continuous. I followed two ways (Version 1 and 2 below), one just by reading the explication in the help for the serialport function, and the second one following another Matlab tutorial, but I didn't understood what all the strings that I had to write meant.
Basically my goal is to define an array of double (sine wave, square wave) and to send it throught the serial port.
I looking for help, thank you in advance !
Exemple of what happen when I use write(device,WaveForm, "double") from the version 1
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1645986/image.jpeg)
% Version 1 based on the elements from the function https://uk.mathworks.com/help/matlab/ref/serialport.html#mw_8342f8eb-6599-4493-9013-3e7bd707194c
WaveForm = ones(1,2000)*10;
freeports = serialportlist("available");
device = serialport(freeports(1),9600);
device.Parity = 'none';
device.StopBits = 1;
device.DataBits = 8;
device.FlowControl ="none";
device.ByteOrder = 'little-endian';
write(device,WaveForm, "double")
flush(device);
clear device
% Version 2 based on the tutorial:
% https://uk.mathworks.com/help/instrument/write-and-read-serial-port-data.html
s = serialport("COM1",9600);
write(s,"Data:Destination RefB","string");
write(s,"Data:Encdg SRPbinary","string");
write(s,"Data:Width 2","string");
write(s,"Data:Start 1","string");
t = (0:2999) .* 8 * pi / 500;
data = round(sin(t) * 90 + 127);
write(s,"CURVE #3500","string");
write(s,data,"int16")
clear s
0 个评论
回答(1 个)
Ayush
2024-3-28
编辑:Ayush
2024-3-28
Hi Mikael,
From what I could gather from your problem is that you want to define an array of type “double” and send it through the serial port to the connected electric stimulator Digimeter DS5. I went over the two approaches you have taken and found some discrepancies in the underlying concept.
Additionally, I found that the device i.e. Digitimer DS5 that you are trying to communicate through a serial port is not supported by MATLAB as of now. You can check the same from the following link:
Furthermore, there are some controls and settings that you can still configure from the instrument company’s own GUI based software called the “DS5 Control Software”. You can learn more about it from the FAQ answered in the product page link:
You can also refer to the below example to know more about how to read a waveform from the scope on your oscilloscope (TekTronix TDS 320):
Hope this helps!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!