c# - SerialPort.GetPortNames() returns incorrect port names -
while c# not primary programming language, i'm maintaining such program couple of years now. program connects device on serial port , works windows xp 8.1. 1 specific "feature" uses .net framework 2.0.
with users upgrading windows 10 we've got complains program cannot detect/open com port of device. have confirmed on our own test systems clean win10 installation.
it turns out function serialport.getportnames() returns incorrect port names , adds 'strange' characters after port name. example:
- com3吀
- com3䡢
- com3゠
etc. when refresh list, every time character (or two) shows after number. test code super straightforward:
string[] portnames = system.io.ports.serialport.getportnames(); log("available ports:"); foreach (string portavailable in portnames) { log(portavailable); }
where log function mearly adds line standard textbox on form:
txtlog.text += msg + environment.newline;
this works in every other windows version. i've checked registry , looks fine there also. has idea this?
i'm suspecting .net framework 2.0 not 100% compatible anymore, although can enable in windows features , seems program runs fine (besides serial port problem). i'm bit scared upgrade newer .net, let alone we've visualstudio 2008 c# (max=.net 3.5). note program still needs run on windows xp (pos version still maintained microsoft).
added: i've "upgraded" test program .net 3.5, , still having same issue. next step install new visualstudio (it appears free nowadays?? should check privacy settings in studio also? ;-).
added 2: installed visualstudio 2015 , made multiple builds different .net framework versions. v2.0 , 3.5 still adding strange character. in v4.0 , issue seems te solved! original program compiled , working newer framework. find issue strange , expect hit more .net functions , more programs.
i've seen strange characters too. solution using regular expressions filter out number portion of comm port name.
dim ports new devices.ports each s string in ports.serialportnames s = regex.replace(s, "\d*(\d+)\d*", "$1") debug.writeline(s) next
Comments
Post a Comment