How to Communicate With Serial Port on a WWAN Modem Using C# -


i have written program in c# allows me communicate (using @ commands) serial ports inside of our computers. code find ports looks this:

managementobjectsearcher searcher = new managementobjectsearcher("root\\cimv2",                 "select * win32_pnpentity");              //this loops through results searcher             foreach (managementobject queryobj in searcher.get())             {                 //if finds port,                  if (queryobj["caption"].tostring().contains("##### wireless at"))                 {                     //it writes file                     sw.writeline("serial port : {0}", queryobj["caption"] + "\n");                     sw.flush();                 } 

this code works splendidly our older modems, searches through com ports , finds @ wireless command port. port send @ commands to. here 2 pictures of device manager of ports searching for

xp

windows 7

the issue is, rolling out our computers newer modems, , these work differently...

the new modems not use serial ports physical listing of ports in device manager. also, serial port not show in win32_pnpentity search... serial port listed under modem properties.

the new modem

my question is, how find serial port of modem using c#?

please let me know if there way can elaborate.

-luke

luke,

you have change how query management tree.

using system.io.ports; using system.managment; using system; private void setport()     {         string[] allports = serialport.getportnames();         bool found = false;         serialport port;          (int = 0; < allports.length; i++)         {             var searcher = new managementobjectsearcher("root\\wmi", "select * msserial_portname");             foreach (managementobject queryobj in searcher.get())             {                 string instancename = queryobj["instancename"].tostring();                  if (instancename.indexof("your modem string", stringcomparison.ordinal) > -1)                 {                     string portname = queryobj["portname"].tostring();                     port = new serialport(portname, 9600, parity.none, 8, stopbits.one);                     found = true;                     break;                 }             }              if (found) break;         }     } 

in loop, code creates serial port @ commands sent. hope helps.

regards, marc


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -