/////////////////////////////////////////////////////////////////////////////// // File: port.cs // // Contents: // A sample script that searches COM ports 1 through 6 to determine which one // has a modem attached. It will only find the first such COM port. // // Originated by P. Clark, Century Software 5/04/1999 /////////////////////////////////////////////////////////////////////////////// // initialize variables var modemok; var success; var portfind = 0; // clear screen and configure for serial connection te.cls(); te.connectiontype = 2; te.baud = 19200; te.duplexmode = 0; te.parity = 0; te.stopbits = 1; te.wordlength = 8; // starting with COM1:, check serial ports until a modem is found do { portfind = portfind + 1; modemok = "COM" + _str(portfind) + ":"; te.display("Checking port "); te.displaynl(modemok); // if the port is in use, it won't show as existing if (exists(modemok)) { // set COM port and connect te.display("Port "); te.display(modemok); te.displaynl(" exists. Checking for modem . . ."); te.comport = portfind; te.connect(); // set modem to echo, then send AT and wait for OK Sleep(1); te.xmit("ATE1Q0\r"); Sleep(1); te.xmit("AT\r"); success = te.wait("OK",5); if (success == 0) { te.displaynl("Modem found!"); } else { te.displaynl("No response."); } te.displaynl(""); } else { te.display("Port "); te.display(modemok); te.displaynl(" not found."); te.displaynl(""); te.disconnect(); Sleep(1); } } while ((success != 0) && (portfind != 6)); te.displaynl(""); // checks to see if a modem was found, or if it's out of COM ports to test if ((success != 0) && (portfind == 6)) { te.displaynl("No modem found!!!"); } else { te.display(modemok); te.displaynl(" valid and assigned."); }