abc

原创 2006年06月13日 17:34:00

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;

namespace mymy
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  
  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
   public struct MyStruct
  {
   public string state;
   public int stateValue;
  }

  private System.ComponentModel.Container components = null;
  MyStruct myState=new MyStruct();
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.Label labState;
  private System.Windows.Forms.Label labType;
  private System.Windows.Forms.Label labStateInfo;
  private System.Timers.Timer timScan;

  
  //通道状态枚举
  
  enum ChanelState
  {
   TRK_IDLE,
   TRK_WAIT_CONNECT,
   TRK_PLAY_WELCOM,
   TRK_CHECK_PLAY_WELCOM,
   TRK_PLAY_SELECT,
   TRK_CHECK_PLAY_PASSWORD,
   TRK_CHECK_REC_END,
   TRK_CHECK_PLAY_BYEBYE,
   TRK_CHECK_PLAY_RECORD,
   TRK_WAIT_USER_HANGUP,
   TRK_WAIT_USER_PICKUP,
   TRK_CHECK_PLAY_SELECT,
   TRK_CHECK_REC_START,
   TRK_NOTRK
  };
  ChanelState[] cs=new ChanelState[100];

  #region DLL函数声明

  [DllImport("SHP_A3.dll")]public static extern int SsmStartCti(string lpSsmCfgFileName, string lpIndexCfgFileName);
  [DllImport("SHP_A3.dll")]public static extern int SsmAddToFileList(int ch, string pszFileName, int nFormat, int dwStartPos, int  dwLen);
  [DllImport("SHP_A3.dll")]public static extern string SsmGetLastErrMsgA();
  [DllImport("SHP_A3.dll")]public static extern int SsmGetMaxCfgBoard();
  [DllImport("SHP_A3.dll")]public static extern int SsmGetMaxUsableBoard();
  [DllImport("SHP_A3.dll")]public static extern int SsmGetMaxCh();
  [DllImport("SHP_A3.dll")]public static extern int SsmGetChState(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmGetChType(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmPickup(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmHangup(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmAutoDial(int ch, string szPhoNum);
  [DllImport("SHP_A3.dll")]public static extern int SsmCheckPlay(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmPlayFileList(int ch);  
  [DllImport("SHP_A3.dll")]public static extern int SsmRecToFile(int ch,string pszFileName, int nFormat, uint dwStartPos, uint   dwLen,uint dwTime,int nMask);
  [DllImport("SHP_A3.dll")]public static extern int SsmPlayFile(int ch,string pszFileName, int nFormat, int dwStartPos, uint dwLen);
  [DllImport("SHP_A3.dll")]public static extern int SsmStopPlay(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmStopPlayFile(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmStopPlayFileList(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmStopPlayIndex(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmStopRecToFile(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmStopRing(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmClearFileList(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmSetDtmfStopPlay(int ch,bool bDsf);
  [DllImport("SHP_A3.dll")]public static extern int SsmPlayIndexString(int ch,string pszIdxStr );
  [DllImport("SHP_A3.dll")]public static extern int SsmClearRxDtmfBuf(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmGetRxDtmfLen(int ch);
  [DllImport("SHP_A3.dll")]public static extern int SsmGet1stDtmf(int ch, byte[] pcDtmf);
  [DllImport("SHP_A3.dll")]public static extern int SsmGetDtmfStr(int ch, string pcDtmfstr);
  [DllImport("SHP_A3.dll")]public static extern int SsmChkRecToFile(int ch);

  #endregion

 


  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.labState = new System.Windows.Forms.Label();
   this.button1 = new System.Windows.Forms.Button();
   this.labType = new System.Windows.Forms.Label();
   this.labStateInfo = new System.Windows.Forms.Label();
   this.timScan = new System.Timers.Timer();
   ((System.ComponentModel.ISupportInitialize)(this.timScan)).BeginInit();
   this.SuspendLayout();
   //
   // labState
   //
   this.labState.Location = new System.Drawing.Point(144, 80);
   this.labState.Name = "labState";
   this.labState.Size = new System.Drawing.Size(288, 24);
   this.labState.TabIndex = 0;
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(184, 336);
   this.button1.Name = "button1";
   this.button1.TabIndex = 1;
   this.button1.Text = "button1";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // labType
   //
   this.labType.Location = new System.Drawing.Point(136, 32);
   this.labType.Name = "labType";
   this.labType.Size = new System.Drawing.Size(280, 23);
   this.labType.TabIndex = 2;
   //
   // labStateInfo
   //
   this.labStateInfo.Location = new System.Drawing.Point(144, 128);
   this.labStateInfo.Name = "labStateInfo";
   this.labStateInfo.TabIndex = 3;
   //
   // timScan
   //
   this.timScan.Enabled = true;
   this.timScan.Interval = 1000;
   this.timScan.SynchronizingObject = this;
   this.timScan.Elapsed += new System.Timers.ElapsedEventHandler(this.timScan_Elapsed);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(656, 493);
   this.Controls.Add(this.labStateInfo);
   this.Controls.Add(this.labType);
   this.Controls.Add(this.button1);
   this.Controls.Add(this.labState);
   this.Name = "Form1";
   this.Text = "Form1";
   this.Load += new System.EventHandler(this.Form1_Load);
   ((System.ComponentModel.ISupportInitialize)(this.timScan)).EndInit();
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
   //检测状态
   checkMode();

  }

  /// <summary>
  /// 检测状态
  /// </summary>
  private void checkMode()
  {
   int startOKFlag;
   startOKFlag=SsmStartCti("ShConfig.ini","Shindex.int");
   if(startOKFlag!=0)
   {
    string error=SsmGetLastErrMsgA();
    MessageBox.Show("NO,Not OK!Error:" + error);
   }
   else
   {
    MessageBox.Show("Yes,IS OK!");
   }
  }


  /// <summary>
  /// 开始
  /// </summary>
  private void MyStart()
  {
   for(int i=0;i<8;i++)
   {
    myState=getChanelState(i);
    labStateInfo.Text=myState.state;
    labType.Text=getChanelType(i);
    labState.Text=ScanChanel(i,myState.stateValue);
    
   }
  }

  #region 获取通道状态
  private MyStruct getChanelState(int index)
  {
   int state=SsmGetChState(index);
   switch(state)
   {
    case 0:
     myState.state="Kong Xian";
     myState.stateValue=0;
     break;
    case 1:
     myState.state="Zhen Ling ";
     myState.stateValue=1;
     break;
    case 2:
     myState.state="Tong Hua";
     myState.stateValue=2;
     break;
    case 3:
     myState.state="Deng Dai Bo Hao Yin";
     myState.stateValue=3;
     break;
    case 4:
     myState.state="Deng Dai Bo Hao Yin";
     myState.stateValue=4;
     break;
    case 5:
     myState.state="Bo Hao";
     myState.stateValue=5;
     break;
    case 6:
     myState.state="Deng Dai Bo Hao Jie Guo";
     myState.stateValue=6;
     break;
    case 7:
     myState.state="Guo Qi";
     myState.stateValue=7;
     break;
    case 9:
     myState.state="Deng Hou Bei Jiao Zhai Ji";
     myState.stateValue=9;
     break;
    default:
     break;
   }
   return myState;
  }
  #endregion

  #region 获取通道类型
  private string getChanelType(int index)
  {
   string reValue=null;
   int type=SsmGetChType(index);
   switch(type)
   {
    case 0:
     reValue="Mo Ni";
     break;
    case 1:
     reValue="Ni Xian";
     break;
    case 2:
     reValue="Zuo Xi";
     break;
    case 3:
     reValue="Lu Yin";
     break;
    case 20:
     reValue="-1";
     break;
    default:
     reValue="-1";
     break;
   }
   return reValue;
  }
  #endregion

  #region 检测通道状态
  /// <summary>
  /// 检测通道状态
  /// </summary>
  /// <param name="ch"></param>
  /// <param name="nstate"></param>
  /// <returns></returns>
  private string  ScanChanel(int ch,int nstate )//
  {  
   string mCurinfo="";
   if (nstate ==7)//挂起
   {
    switch(cs[ch])
    {
     case ChanelState.TRK_CHECK_PLAY_WELCOM:
      SsmStopPlayFileList(ch);
      mCurinfo="停止播放欢迎词";
      break;
   
     case ChanelState.TRK_CHECK_PLAY_PASSWORD:
     case ChanelState.TRK_CHECK_REC_START:
     case ChanelState.TRK_CHECK_PLAY_SELECT:
     case ChanelState.TRK_CHECK_PLAY_BYEBYE:
      SsmStopPlayIndex(ch);
      mCurinfo="停止索引放音";
      break;
   
     case ChanelState.TRK_CHECK_REC_END:
      SsmStopRecToFile(ch);
      mCurinfo="停止录音";
      break;
   
     case ChanelState.TRK_CHECK_PLAY_RECORD:
      SsmStopPlayFile(ch);
      mCurinfo="停止文件放音";
      break;
   
    
    }

   }
   switch(cs[ch])
   { 
    case ChanelState.TRK_IDLE:
     if( nstate == 2 )  //外线振铃
     {
      SsmPickup(ch);      
      cs[ch] = ChanelState.TRK_WAIT_CONNECT;
     }
     break;
    case ChanelState.TRK_WAIT_CONNECT:
     if( nstate == 3 )//通话状态
      cs[ch] = ChanelState.TRK_PLAY_WELCOM;
     mCurinfo="播放欢迎词";
     break;
    case ChanelState.TRK_PLAY_WELCOM:
     SsmClearFileList(ch);
     if((SsmAddToFileList(ch,"DemoVoc//Welcom1.voc",6,0,-1)==-1 ||
      SsmAddToFileList(ch,"DemoVoc//Welcom2.voc",6,0,-1)==-1) )
     {
      SsmHangup(ch);
      MessageBox.Show(SsmGetLastErrMsgA());
      cs[ch] = ChanelState.TRK_IDLE;

     }
     else
      if(SsmPlayFileList(ch) == -1)
     {
      SsmHangup( ch );
      MessageBox.Show(SsmGetLastErrMsgA());
      cs[ch] = ChanelState.TRK_IDLE;
     }      
     else
      cs[ch] = ChanelState.TRK_CHECK_PLAY_WELCOM;
     mCurinfo="播放选择提示音";
     break;
    case ChanelState.TRK_CHECK_PLAY_WELCOM:
     if( SsmCheckPlay(ch) > 0) //end of playing "welcom"
      cs[ch] = ChanelState.TRK_PLAY_SELECT;
     mCurinfo="end of playing welcom";
     break;
    case ChanelState.TRK_PLAY_SELECT:

     SsmSetDtmfStopPlay(ch,true); //enable DTMF-Stop-Play function
     if(SsmPlayIndexString(ch,"Select") == -1)
      
     {
      SsmHangup( ch );
      MessageBox.Show(SsmGetLastErrMsgA());
      cs[ch] = ChanelState.TRK_IDLE;
      
     }
     else
     {
      SsmClearRxDtmfBuf(ch);
      cs[ch] = ChanelState.TRK_CHECK_PLAY_SELECT;
     }
     mCurinfo="选择按键";

     break;

    case ChanelState.TRK_CHECK_PLAY_SELECT:

     /////////////////////////////////////////////////////
     
     if(SsmGetRxDtmfLen(ch) >= 1 && (SsmCheckPlay(ch) == 2 || SsmCheckPlay(ch) == 1))
     {
      string tmp1="";
      tmp1+= '/0'; 
      byte[] str=new byte[1];
      int tt=SsmGet1stDtmf(ch, str);
      SsmClearRxDtmfBuf(ch);
      tmp1=System.Text.Encoding.ASCII.GetString(str);
      char[]tmp=tmp1.ToCharArray();
      switch(tmp[0])
      {
       case '1':   //DTMF=1: record to file "test.voc"
        if(SsmPlayIndexString(ch,"RecPrompt") == -1) //play "press any key to start, and any key again to stop".
        {
         
         SsmHangup( ch );
         MessageBox.Show(SsmGetLastErrMsgA());
         cs[ch] = ChanelState.TRK_IDLE;
        }
        else
        {
         
         cs[ch] = ChanelState.TRK_CHECK_REC_START;
         
        }        


         
        break;

       case '2':   //DTMF=2: play recorded file "test.voc"
        mCurinfo="收听留言";
        if(File.Exists("test.voc"))
         if(SsmPlayFile(ch,"test.voc",6,0,0xFFFFFFFF) == -1)
         {
          SsmHangup( ch );
          MessageBox.Show(SsmGetLastErrMsgA());
          cs[ch] = ChanelState.TRK_IDLE;
         }
         
         else
          cs[ch] = ChanelState.TRK_CHECK_PLAY_RECORD;
        else
         if(SsmPlayIndexString(ch,"FileNotFound") == -1) //play "file not found" message
         
        {
         SsmHangup( ch );
         MessageBox.Show(SsmGetLastErrMsgA());
         cs[ch] = ChanelState.TRK_IDLE;

        }
         
        else
         cs[ch] = ChanelState.TRK_CHECK_PLAY_RECORD;

        break ;

       case '3':   //DTMF=3: play user's password,some sample digital
        mCurinfo="查询密码";
        SsmSetDtmfStopPlay(ch,false); //disable DTMF-Stop-Play function while playing password
        if(SsmPlayIndexString(ch,"YourPasswordIs,1,2,3,4") == -1) //play "your password is 1234".
         
        {
         SsmHangup( ch );
         MessageBox.Show(SsmGetLastErrMsgA());
         cs[ch] = ChanelState.TRK_IDLE;
         mCurinfo=SsmGetLastErrMsgA();

        }
         
        else
         cs[ch] = ChanelState.TRK_CHECK_PLAY_PASSWORD;
        break;
    
       
       case '0':   //DTMF=0:  end of service,play "Byebye"
        mCurinfo="退出";
        if ( SsmPlayIndexString(ch, "Byebye" )== -1 )
             
        {
         SsmHangup( ch );
         MessageBox.Show(SsmGetLastErrMsgA());
         cs[ch] = ChanelState.TRK_IDLE;
        }
        
        else
         cs[ch]= ChanelState.TRK_CHECK_PLAY_BYEBYE;
        break; 
           
       default: 
        break;
      }
     }
    
     break;

    case ChanelState.TRK_CHECK_PLAY_PASSWORD:
     if(SsmCheckPlay(ch) > 0)    //this channel is not playing index now
      cs[ch]= ChanelState.TRK_PLAY_SELECT;
     mCurinfo="this channel is not playing index now";
     break ;

    case ChanelState.TRK_CHECK_REC_START:
     if(SsmGetRxDtmfLen(ch) >= 1)
     {
      SsmClearRxDtmfBuf(ch);
      if( SsmRecToFile(ch,"test.voc",6,0,0xffffffff,0,0) == -1) //start from 16000L,maxmium 10 seconds
      {
       SsmHangup( ch );
       MessageBox.Show(SsmGetLastErrMsgA());
       cs[ch] = ChanelState.TRK_IDLE;
       mCurinfo=SsmGetLastErrMsgA();
      
      }
      else
       cs[ch] = ChanelState.TRK_CHECK_REC_END;
     }
     mCurinfo="录音开始";
     break;

    case ChanelState.TRK_CHECK_REC_END:
     if(SsmGetRxDtmfLen(ch)>=1 || SsmChkRecToFile(ch)==0)
     {
      SsmStopRecToFile(ch);
      cs[ch]= ChanelState.TRK_PLAY_SELECT;
      mCurinfo="录音结束";
     }
     break ;

    case ChanelState.TRK_CHECK_PLAY_RECORD:
     if(SsmCheckPlay(ch) > 0)
      cs[ch] = ChanelState.TRK_PLAY_SELECT;
     break;

    case ChanelState.TRK_CHECK_PLAY_BYEBYE:
     if(SsmCheckPlay(ch) > 0)
     {
      SsmHangup(ch);
      cs[ch] = ChanelState.TRK_IDLE;
     }
     break ;

     //////////////////////////////////////////////////////

 

     

   }//end switch
   return mCurinfo;

  }
  #endregion

  private void button1_Click(object sender, System.EventArgs e)
  {
   Thread myt=new Thread(new ThreadStart(MyStart));
   myt.Start();  
  }

  private void timScan_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  {
   MyStart(); 
  }
 }
}

echo count(“abc”); 输出什么?

”1″count —计算数组中的单元数目或对象中的属性个数int count (mixed$var [, int$mode ] ), 如果 var 不是数组类型或者实现了Countable 接口的对象...
  • guichenglin
  • guichenglin
  • 2010年12月03日 13:33
  • 5078

char *c = "abc"和char c[]="abc"

转自:http://blog.csdn.net/wallwind/article/details/7210474 char *c = "abc"和char c[]="abc",前者改变其内 ...
  • jyl1999xxxx
  • jyl1999xxxx
  • 2016年06月17日 09:38
  • 365

SAP库存管理之ABC分类法

ABC分类法(Activity Based Classification)       ABC分类法又称帕累托分析法或巴雷托分析法、柏拉图分析、主次因分析法 、ABC分析法、分类管理法、重点管理...
  • zhongguomao
  • zhongguomao
  • 2015年06月02日 11:30
  • 2032

[ZT]智能ABC一严重Bug可使任意程序崩溃

    智能ABC是各种版本Windows都默认安装的输入法,因此使用极其广泛。除了输入文字之外,我发现它还另有玄机——程序必杀技。 程序“死”于非命     打开任意一个应用程序,如记事本或者...
  • matrix67
  • matrix67
  • 2005年11月09日 23:21
  • 1329

学习一种新的编程语言ABC

最近空了下来,难得的手里一个项目也没有,作为技术积累,打算了解下COBOL语言。看了几篇介绍COBOL语法的文章,感觉很多文章无从看起。也许是我岁数大了,理解能力退化了,看到的文章大多是给了一堆例子,...
  • fuqd273
  • fuqd273
  • 2008年05月09日 14:19
  • 785

char *p="abc" 与 char p[]="abc" 的区别

1.以字符串形式出现的,编译器都会为该字符串自动添加一个0作为结束符,如在代码中写"abc",那么编译器帮你存储的是"abc\0"  2."abc"是常量吗?  答案:有时是,有时不是  ...
  • yunzhuwu
  • yunzhuwu
  • 2014年03月24日 18:30
  • 1190

用智能ABC关闭程序

一次光论坛,看到一个这样的帖子---------------------只要有任何一个程序在运行的状态下的可输入部分调出智能ABC。输入V,再按一下↑,再按一下DEL键,之后按空格或者回车,该程序立即...
  • allenle
  • allenle
  • 2005年06月05日 08:54
  • 1410

C++基础——抽象基类(ABC)

抽象基类(ABC)即Abstract Base Class利用了基类指针指向派生类对象从而调用派生类方法的思想实现C++的隐藏具体实现则主要用到的是纯虚函数#pragma once #include...
  • mfcing
  • mfcing
  • 2012年04月06日 08:34
  • 2485

(2)Mysql ---- 索引ABC 《MYSQL 5.5从零开始学》笔记

索引是一种特殊的数据库结构,可以用来快速查询数据库表中的特定记录。索引是提高数据库性能的重要方式。 MySQL中,所有的数据类型都可以被索引。 MySQL的索引包括普通索引、唯一性索引、全文索引、...
  • pandajava
  • pandajava
  • 2015年01月13日 10:03
  • 1165

WCF学习-WCF的ABC(2)

在WCF应用程序中,WCF的宿主和客户端那之间的通信或者说构建WCF应用程序都应该遵循ABC,即地址address,绑定binding,契约contract,简称为ABC; A:地址就是服务的地址,...
  • hp412827025
  • hp412827025
  • 2014年04月25日 22:55
  • 957
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:abc
举报原因:
原因补充:

(最多只允许输入30个字)