在没有串行通信设备的情况下通过com端口测试通信的串行监视方法 [英] serial monitoring method to test communication via com ports without a serial communication device
问题描述
我有一个在ISE设计工具包上模拟和综合的Verilog代码.我有一个用于实现的FPGA spartan 6器件.但是设备存在问题(可能是电源问题),当我将其连接到PC时,这使得该设备无法在任何COM端口中使用.因此,我想检查我为通过设备进行串行通信而编写的Matlab代码是否可以完成所需的工作.因此,我需要一种方法来测试通过任何COM端口进行的串行通信,而无需将串行com设备连接到PC.有什么方法可以将Matlab的串行数据发送到COM端口?任何软件或任何其他方法将不胜感激:)
我找到了一种使用虚拟串行端口测试Matlab串行通信的方法.
从以下位置下载免费的虚拟COM端口仿真器":
执行以下Matlab代码示例以验证其正常工作:
s3 = serial('COM3','BaudRate',115200);s4 =串行('COM4','BaudRate',115200);fopen(s3);fopen(s4);fwrite(s3,uint8([1,2,3,4,5]));%fprintf(s3,'12345');暂停(0.1);RxBuf = fread(s4,5)fclose(s3);删除(s3);清除s3fclose(s4);删除(s4);清除s4
输出为:
RxBuf =1个2个345
绕过了仅在单个测试会话中停留"的问题.
使用该软件创建一对虚拟端口时出现问题,它仅在单个测试会话中存在.
我想这是COM端口仿真软件的问题.
以下解决方案不是一个好习惯(也不是真正的解决方案).
- 将串行对象声明为
global
,以保持该对象的持久性. - 仅在未创建串行对象的情况下创建它.
- 不要删除也不清除串行对象.
请参见以下代码示例:
全局s3 s4如果为空(s3)s3 = serial('COM3','BaudRate',115200);结尾如果为空(s4)s4 =串行('COM4','BaudRate',115200);结尾fopen(s3);fopen(s4);fwrite(s3,uint8([1,2,3,4,5]));暂停(0.1);RxBuf = fread(s4,5)fclose(s3);%delete(s3);%clear s3fclose(s4);%delete(s4);%clear s4
您还可以寻找更好的虚拟COM端口软件.
I have a Verilog code simulated and synthesized on ISE design toolkit. I've got an FPGA spartan 6 device which is to be used for the implementation. But there is a problem with the device (probably a power issue) which makes the device unavailable in any of the COM ports when I connected it to my PC. So I want to check whether my Matlab code which I made for serial communication through the device does the desired job. So I need a method to test serial communication via any of the COM ports without connecting a serial com device to the PC. Is there any such method that I can Tx Rx serial data from Matlab to COM ports? Any software or any other method would be highly appreciated :)
I found a way to test Matlab serial communication using virtual serial ports.
Download "Freeware Virtual COM Ports Emulator" from: http://freevirtualserialports.com/
I installed it in Windows 10, and it's working (as trial).
Add a pair of two serial ports:
Execute the following Matlab code sample to verify it's working:
s3 = serial('COM3','BaudRate',115200);
s4 = serial('COM4','BaudRate',115200);
fopen(s3);
fopen(s4);
fwrite(s3, uint8([1, 2, 3, 4, 5]));
%fprintf(s3, '12345');
pause(0.1);
RxBuf = fread(s4, 5)
fclose(s3);
delete(s3);
clear s3
fclose(s4);
delete(s4);
clear s4
The output is:
RxBuf =
1
2
3
4
5
Bypassing the problem "it only stays for a single test session".
There is a problem when creating a pair of virtual ports using the software, it only stays for a single test session.
I guess it's a problem with the COM port emulation software.
The following solution, is not a good practice (and not a true solution).
- Declare the serial object as
global
, keeping the object persistent. - Create the serial object only if it's not created.
- Don't delete and don't clear the serial object.
See the following code sample:
global s3 s4
if isempty(s3)
s3 = serial('COM3','BaudRate',115200);
end
if isempty(s4)
s4 = serial('COM4','BaudRate',115200);
end
fopen(s3);
fopen(s4);
fwrite(s3, uint8([1, 2, 3, 4, 5]));
pause(0.1);
RxBuf = fread(s4, 5)
fclose(s3);
%delete(s3);
%clear s3
fclose(s4);
%delete(s4);
%clear s4
You can also look for a better virtual COM port software.
这篇关于在没有串行通信设备的情况下通过com端口测试通信的串行监视方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!