Write a mobile phone Chinese short message with C #

zhaozj2021-02-16  41

I recently bought a NOKIA3210 data cable on the computer city, playing a few days to change LOGO, and then throw the data line aside after the ringing. Until a few days, I saw the secondary development control with a mobile phone short message on http://oxygensoftware.com, I remembered how many data cables don't have to be used, and I have recently learned C #, I feel that a short message is made with C #. Normal, after a multi-day test, finally realize the mode of using computer data cable mobile phone, and realize the short message on the local area network platform.

Since there are many places where the mobile phone short message is used, it may be from the web page, it may be a form in Outlook, or some system of a host of a non-Windows operating system, so after thinking, I feel the most A good solution is to use Windows "Services", and the corresponding information is read from the fixed format text file in a directory and sent it. Other clients only need to write text messages to this directory. Let us start after thinking down!

Let's explain the development platform first: Windows 2000 Advance Server operating system, Visual Studio .NET, Oxygen SMS ActiveX Control V2.3 (Share Ware), NOKIA 3210 mobile phone is connected to COM1 through the data cable. Run Visual Studio .NET, create a new C # project, select the "Windows Server" type project, named "SMSServer". At the design screen of Server1, "ServerName" is named "SMSServer". Click the "View Designer button" to switch to the design screen, drag the clock control in the "Windows Forms" toolbox, name "SmStimer", drag a "EventLog" control in the "Components" toolbox. Name "EventLog1". Click "Add Reference" in the Project menu, select the "COM" page, browse to the directory where the Oxygen SMS ActiveX Control V2.3 program is installed, and find SMSControl.ocx to add to "Selected Components".

Replace Server1.cs code to

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.IO; using System.Text; namespace SmsServer {public class SmsServer: System.ServiceProcess.ServiceBase {private System.Timers.Timer SmsTimer; private System.Diagnostics.EventLog eventLog1; public O2SMSXControl.O2SMSX SmsX1; // define SMS objects ///

/// Required designer variable /// private. System.ComponentModel.Container components = null; public SmsServer () {// This call is required by the Windows.Forms Component Designer InitializeComponent (); // TODO:. Add any initialization after the InitComponent call} // The main entry point for the process static void Main () {System.ServiceProcess.ServiceBase [] ServicesToRun; // More than one user Service may run within the same process to add // another service to this process, change the following line to // create. A Second Service Object. f or example, // // ServicesToRun = New System.ServiceProcess.ServiceBase [] {new Service1 (), new MySecondUserService ()}; // ServicesToRun = new System.ServiceProcess.ServiceBase [] {new SmsServer ()}; System. ServiceProcess.serviceBase.Run (ServiceStorun);} /// /// Required Method for Designer Support - do not modifi //////// private void InitializeComponent () {this.smstimer = new system.timers.timer (); this.EventLog1 = new system.diagnostics.eventlog

); ("This.smstimer). Begininit (); (THISTEM.EVENTMODEL.IsupportInitialize)). Begininit (); // // smstimer // this.smstimer .Enabled = true; this.SmsTimer.Elapsed = new System.Timers.ElapsedEventHandler (this.SmsTimer_Elapsed); // // SmsServer // this.ServiceName = "SmsServer"; ((System.ComponentModel.ISupportInitialize) (this. SMSTIMER). Endinit (); ((System.comPonentModel.isUpportInitialize) (this.EventLog1)). Endinit ();} ///

/// clean up any resources being used. /// Protected override void dispose (bool disposing) {if (disponents! = Null) {components.dispose ();}} Base.dispose (4);} /// /// set things In Motion So Your Service Can Do ITs Work. /// protected =///////////> Start your service. SMSX1 = New o2smsxcontrol.o2smsxclass (); smsx1.connectionMode = 0; // Online type Cable smsx1.comNumber = 1; // The coupling port is COM 1 SMSX1.MODEL = 0; // Mobile phone type 3210 SMSX1.Open (); // Database SMSX1.SETSMSCNUMBER (" 8613800754500"); // Information Center Number} /// /// stop this service. ///

protected override void OnStop () {// TODO:. Add code here to perform any tear-down necessary to stop your service SmsX1.Close ();} private void SmsTimer_Elapsed (object sender, System.Timers.ElapsedEventArgs e) {// When f: / sms / data / filetosend has a file, turn off the clock first, send it out, and remove the file and then start the clock this.smstimer.Enabled = false; // directory object DirectoryInfo CD = new system.io.directoryInfo ("F: // sms // data // filetosend"); // Database record variable string rsid; string rsphonenum; string rsSMSText; string strsql; // First, list all current SMS files in the current directory (FileInfo Filesend In CD.GetFiles ()) {Try {// Open each file read file content fileStream Fs = new filestream (cd.fullname "//" filesend.name, filemode.open, fileaccess.read), FileAccess.Read; StreamReader Sr; SR = New StreamReader (FS, UnicodeEncoding.getencoding ("GB2312")); RSID = filesend.name .tostring (); rsid = rsid.replace (".sms", "); rsid = rsid.trim (); Rsphonenum = sr.readline (); rsphonenum = rsphonenum.trim (); if (rsphonenum.length> 11) rsphonenum = rsphonenum.substring (0, 10); rsSMSText = SR .ReadToend (); rsSMSText = rsSMSText.trim (); if (rsSMSText.length> 50) rsSMSText.Substring (0,49); fs.close (); sr.close (); // Send Short information SMSX1.SendunicodesMsmessage (RSPHONENUM.TOSTRING (), RSSMSText.toString (), 6, false, ""); // Back up and delete file fiesend.copyto ("

F: // SMS // Data // Hadbeensend // " Filesend.Name, true); Filesend.Delete ();} catch (system.exception e) {// error dialog file EventLog1.writeentry (E.MESSAGE .Tostring ());}} // Restart the clock this.smstimer.enabled = true;}}} On the server1.cs switching design screen, click "Add Installer" under the Properties window, the system automatically adds the ProjectInstaller.cs file, Click ServiceInstaller1, set "Server Name" to "SMSServer", click "ServiceProcessInstaller1", set the Account to "Localsystem". Select "Generate SMSServer" in the menu "Generate", correct the possible error. Perform a DOS command line, Under the / bin / debug directory of the project directory, execute "installutil smsserver", if the installutil program is not found, first Path. At this time, "SMSServer" service can be found under "Services" of the management tool. Start the service The default source is the directory f: / SMS / data / filetosend, if this directory has a .sms file, read the mobile phone number sent by its first behavior, the second line to the text end as a short message content, and then send short information , Back up the text to F: / SMS / DATA / HADBEENSEND /. Let's look back at the code in Server1.cs. First, in command space, you should add "Using System.io; use System.Text;" Convenient to handle files. And text objects, at the time of name

public class SmsServer: System.ServiceProcess.ServiceBase {private System.Timers.Timer SmsTimer; private System.Diagnostics.EventLog eventLog1; public O2SMSXControl.O2SMSX SmsX1; // define the object SMS ...... Oxygen control in reference to the definition of SMSX1 object, then initialize the phone object Protected Override void onstart (String [] args) {// Todo: add code here to start your service. SMSX1 = New o2smsxControl.O2SMSXClass () SMSX1.ConnectionMode = 0; // Online type Cable smsx1.comNumber = 1; // The coupling port is COM 1 SMSX1.MODEL = 0; // Mobile phone type 3210 SMSX1.Open (); // Joint mobile phone SMSX1.SetsMscnumber (" 8613800754500"); // Information center number}

转载请注明原文地址:https://www.9cbs.com/read-25165.html

New Post(0)