class1.cs

来自「GSM 模块软件开发包 开发包说明 开发包基于GSM模块开发」· CS 代码 · 共 65 行

CS
65
字号
using System;
using System.Threading;

using System.Runtime.InteropServices; // DllImport所在的名字空间
unsafe public class AscendSMS 
{
	[DllImport("AscendSMS.dll")]	public static extern int OpenComm(int x);
	[DllImport("AscendSMS.Dll")]	public static extern int CloseComm(int x);
	[DllImport("AscendSMS.Dll")]	public static extern int SendMsg(int ComIndex,string Msg,string Mobile,int Msg_Index,bool Chinese);
	[DllImport("AscendSMS.Dll")]	public static extern bool GetSCA(int ComIndex,char* SCA);
	[DllImport("AscendSMS.Dll")]	public static extern bool GetNewMsg(int ComIndex,char* NewMsg);
	[DllImport("AscendSMS.Dll")]	public static extern int GetUnSendCount(int ComIndex);
	[DllImport("AscendSMS.Dll")]	public static extern bool SetSCA(int ComIndex,string SCA);
	[DllImport("AscendSMS.Dll")]	public static extern bool GetFailedMsg(int ComIndex,char* Msg);
	[DllImport("AscendSMS.Dll")]	public static extern bool GetNextSendMsg(int ComIndex,char* Msg,bool DeleteAfterRead);
	[DllImport("AscendSMS.Dll")]	public static extern int ForceCloseComm(int ComIndex);
	[DllImport("AscendSMS.Dll")]	public static extern bool GetSerialNo(int ComIndex,char*SerialNo);
}
namespace ConsoleApplication1
{

	class Welcome
	{
	
		unsafe static void Main()
		{
	
			char* tempchar=stackalloc char[100];
			byte* tempbyte=stackalloc byte[100];
			for (int i=0;i<100;i++)
			{
				tempbyte[i]=(byte)'\x0';
			}

			int rtn=AscendSMS.OpenComm(1);
			if(rtn==0)
			{
				Console.WriteLine("Open success!");
				Console.Write("GetSCA:");

				Thread.Sleep(1000);

				bool brtn=AscendSMS.GetSCA(1,(char*)tempbyte);

				for(int i=0;i<100;i++)
				{
					if(tempbyte[i]==(byte)('\x0'))
						break;
					Console.Write("{0}",(char)tempbyte[i]);
				}
				Console.WriteLine("\nFinish!");
				//				AscendSMS.SendMsg(1,"Hi Yale","13958002360",1,false);
			}
			if(rtn!=0)
				Console.WriteLine("Open Fail!");
			for(int i=0;i<5;i++)
			{
				Thread.Sleep(1000);
			}
			AscendSMS.CloseComm(1);

		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?