How to read COM port caption
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Parth-Raj Singh
el 1 de Mzo. de 2019
Comentada: Parth-Raj Singh
el 7 de Feb. de 2022
I want to connect a device with multiple COM ports at different baud rate. However, every time I change HW or USB port, the COM port changes and I have to look into the device manager and then change COM ports in my script to make it work. However, I noticed that in the device manager the COM ports have captions which don't change with COM port number. I would like to know how can I automatically select the COM ports based on their captions.
0 comentarios
Respuesta aceptada
Abhishek Singh
el 5 de Mzo. de 2019
Hello Parth,
It is not possible to address the COM ports with the captions.
However as a work-around for this problem, before your actual code on your devices, you could continuously publish a particular value.
Simulink can search for these values across all COM ports and assign the COM ports accordingly.
For example, if you have an Arduino Uno and an Arduino Mega, you could publish '1' continuously from the Uno and '2' continuously from the Mega.
Simulink can sniff through all COM ports and look for a '1' or a '2', and assign the COM port to the device
0 comentarios
Más respuestas (2)
Madhu Govindarajan
el 5 de Mzo. de 2019
seriallist command is used to detect additions to the COM port #s (only available starting R2017a). However in this technique you are assuming that no other COM port devices gets added at the time of addition and you know the order in which you are adding the devices in. If these two can be guaranteed, then seriallist command output can be saved as a variable and see how it is changing and assign COM ports to appropriate devices based on the order.
0 comentarios
Parth-Raj Singh
el 21 de Mzo. de 2019
2 comentarios
chrisw23
el 4 de Feb. de 2022
Editada: chrisw23
el 7 de Feb. de 2022
asm = NET.addAssembly("System.Management");
mngmtQuery = System.Management.ObjectQuery();
mngmtQuery.QueryString = "SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%'";
mngmtSearcher = System.Management.ManagementObjectSearcher(mngmtQuery);
mngmtObjColl = mngmtSearcher.Get();
comRep = repmat("",mngmtObjColl.Count,2);
enMngmtObjColl = mngmtObjColl.GetEnumerator;
i = 0;
while enMngmtObjColl.MoveNext()
i = i + 1;
com = enMngmtObjColl.Current;
caption = com.GetPropertyValue("Caption");
comRep(i,1) = string(caption).extract("COM" + digitsPattern);
comRep(i,2) = string(com.GetPropertyValue("Description"));
end
disp(comRep)
...works for me
Best regards
Christian
Ver también
Categorías
Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!