H.Wong

P.

导航

C#和硬件驱动交互编程<一> --东进语音卡项目例子.

上一年在公司做了一个小小的IVR项目.觉得这是一个和硬件驱动交互编程的不错例子.
共享一下.也讨论一下.
代码:(这个是调用系统驱动的DLL)

using System;
using System.Text;
using DJVoiceCard.Lib;

namespace DJVoiceCard.DL
{
    
public class SysFunction
    
{
        
系统操作

        
中继通道操作

        
获取空闲中继信道

        
用户
    }

}

 

Code

Code

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using DJVoiceCard.Lib;

namespace DJVoiceCard.DL
{
    
class DataInc
    
{

    }

    
public enum RelaySet : int 
    
{
            ISUP_CH_SET_FREE
=1,
        
//锁闭通道
            ISUP_CH_SET_BLOCK=2,
        
//解除锁闭
            ISUP_CH_SET_UNBLOCK=3,
        
//来话方动作,来话到达后,送被叫闲信号,话路接通,但不送应答信号
            ISUP_CALLEE_SET_ACM=4,
        
//被叫摘机信号
            ISUP_CALLEE_SET_ANM=5,
        
//来话方动作,来话到达后,送被叫闲信号,话路接通,送应答信号
            ISUP_CALLEE_SET_CON    =6,
        
//送线路释放信号
            ISUP_CH_SET_REL    =7,
        
//群锁闭
            ISUP_CH_SET_CGB    =8,
        
//群解除锁闭
            ISUP_CH_SET_CGU    =9,
        
//后续地址
            ISUP_CALLER_SET_SAM=10,
        
//暂停
            ISUP_CH_SET_SUS=11,
        
//恢复
            ISUP_CH_SET_RES=12,
        

        
//锁闭通道证实
         ISUP_CH_SET_BLA=0x81,
        
//解除锁闭证实
         ISUP_CH_SET_UBA=0x82,
        
//电路复原
         ISUP_CH_SET_RSC=0x83,
        
//信息请求
         ISUP_CH_SET_INR=0x84,
        
//信息
         ISUP_CH_SET_INF=0x85,
        
//群锁闭证实
         ISUP_CH_SET_CGBA=0x92,
        
//群解除锁闭证实
         ISUP_CH_SET_CGUA=0x94,
        
//群复原
         ISUP_CH_SET_GRS=0x95,
        
//群复原证实
         ISUP_CH_SET_GRA=0x96,
        
//群问讯
         ISUP_CH_SET_CQM=0x97,
        
//群问讯响应
         ISUP_CH_SET_CQR=0x98,
        
//释放完成
         ISUP_CH_SET_RLC=0x99,
        
//混淆
         ISUP_CH_SET_CFN=0x9a,
        
//呼叫进展
         ISUP_CALLEE_SET_CPG=0xa2,
    }

    
/// <summary>
    
/// 信道状态
    
/// </summary>

    public enum RelayStates : int 
    
{
        
/// <summary>
        
/// // 空闲状态
        
/// </summary>

         ISUP_CH_FREE=1,   
        
/// <summary>
        
/// // DLL等待应用程序同步释放资源
        
/// </summary>

         ISUP_CH_WAIT_RELEASE=2 ,     
        
/// <summary>
        
/// // 本地闭塞状态
        
/// </summary>

         ISUP_CH_LOCAL_BLOCK=3 ,     
        
/// <summary>
        
/// // 远端闭塞状态
        
/// </summary>

         ISUP_CH_REMOTE_BLOCK=4 ,     
        
/// <summary>
        
/// //本地和远端锁闭状态
        
/// </summary>

         ISUP_CH_LOCAL_AND_REMOTE_BLOCK=5 ,     
        
/// <summary>
        
/// // 不可用态(网络不通等原因导致)
        
/// </summary>

         ISUP_CH_UNAVIABLE=6   ,   
        
/// <summary>
        
/// //被叫闲,等待被叫应答
        
/// </summary>

         ISUP_CALLER_WAIT_ANM=7 ,     
        
/// <summary>
        
/// // 去话连通状态
        
/// </summary>

         ISUP_CALLER_CONNECT=8  ,    
        
/// <summary>
        
/// // 呼叫到达,接收全地址
        
/// </summary>

         ISUP_CALLEE_RECV_IAM=9  ,    
        
/// <summary>
        
/// // 摘机,来话连通
        
/// </summary>

         ISUP_CALLEE_CONNECT=10 ,   
        
/// <summary>
        
/// // 本地暂停
        
/// </summary>

         ISUP_CH_LOCAL_SUSPEND=11,   
        
/// <summary>
        
/// // 远端暂停
        
/// </summary>

         ISUP_CH_REMOTE_SUSPEND=12,
        
/// <summary>
        
/// IAM消息到达
        
/// </summary>

        CALLEE_IAM_REACHED=0xf0,
        
/// <summary>
        
/// SAM消息到达提示
        
/// </summary>

        CALLEE_SAM_REACHED=0xf1,
    
    }



    
/// <summary>
    
/// 语音资源类型
    
/// </summary>

    public enum VoiceResourcesType:int
    
{
        
/// <summary>
        
/// 没有语音资源
        
/// </summary>

        Res_NoRes = 0,
        
/// <summary>
        
/// 文件型语音资源
        
/// </summary>

        Res_File = 1,
        
/// <summary>
        
/// 系统内存型语音资源
        
/// </summary>

        Res_Xms = 2,
    }
;

    
/// <summary>
    
/// 语音资源操作类型
    
/// </summary>

    public enum VoiceOperatorType
    
{
        
/// <summary>
        
/// //没有语音操作
        
/// </summary>

        OP_NoOperator = 0,
        
/// <summary>
        
/// //普通放音
        
/// </summary>

        OP_Play = 1,
        
/// <summary>
        
/// //循环放音
        
/// </summary>

        OP_LoopPlay = 2,
    }
;

    
/// <summary>
    
/// 用户状态类型
    
/// </summary>

    public enum USER_STATE
    
{
        
/// <summary>
        
/// 未摘机
        
/// </summary>

        USR_OFFHOOK=0,
        
/// <summary>
        
/// 等待拨号
        
/// </summary>

        USR_WAITDIAL=1,
        
/// <summary>
        
/// 拨号
        
/// </summary>

        USR_DIAL=2,
        
/// <summary>
        
/// 结束
        
/// </summary>

        USR_ENDSESSION=3,
        
/// <summary>
        
/// 等待语音
        
/// </summary>

        USR_WAITONHOOK=4,
        
/// <summary>
        
/// 振铃
        
/// </summary>

        USR_RING=5,
        
/// <summary>
        
/// 通话
        
/// </summary>

        USR_CONNECT=6,
        
/// <summary>
        
/// 摘机中
        
/// </summary>

        USR_ONHOOK = 50,
        
/// <summary>
        
/// 取消振铃
        
/// </summary>

        USR_EXRING=51,
        
/// <summary>
        
/// 退出通话
        
/// </summary>

        USR_EXCONNECT=52

    }
;

    
/// <summary>
    
/// 中继信道状态
    
/// </summary>

    public enum TRUNK_ST
    
{
        
/// <summary>
        
/// 空闲状态
        
/// </summary>

        TRK_FREE=0,        //free state
        /// <summary>
        
/// 准备状态
        
/// </summary>

        TRK_READY=1,        //mfc stop state
        /// <summary>
        
/// 振铃状态
        
/// </summary>

        TRK_RING=2,        //ring user
        /// <summary>
        
/// 拨号状态
        
/// </summary>

        TRK_CALLOUT=3,    //user dial over, callout
        /// <summary>
        
/// 等待摘机
        
/// </summary>

        TRK_WAITUSEROFFHOOK=4,    //ring user, wait offhok
        /// <summary>
        
/// 摘机状态
        
/// </summary>

        TRK_WAITUSERONHOOK=5,
        
/// <summary>
        
/// 结束谈话
        
/// </summary>

        TRK_ENDSESSION=6,            //end a talk
        /// <summary>
        
/// 链接状态
        
/// </summary>

        TRK_CONNECT=7,
        
/// <summary>
        
/// 为初始化状态
        
/// </summary>

        TRK_NULLSTATE=8,
        
/// <summary>
        
/// 播放状态
        
/// </summary>

        TRK_PLAY=9,
        
/// <summary>
        
/// 呼入状态
        
/// </summary>

        TRK_CALLIN=10,
        
/// <summary>
        
/// 摘机状态
        
/// </summary>

        TRK_ONHOOK=11,
        
/// <summary>
        
/// 挂机状态
        
/// </summary>

        TRK_HANGUP=12,
    }
;

    
/// <summary>
    
/// 用户状态
    
/// </summary>

    public struct UR_ST
    
{
        
public int ConnUrID;
        
public USER_STATE ST;
        
public int ConnTrID;
        
    }



    
/// <summary>
    
/// 对收到的ISUP消息,获取其中的原因值
    
/// </summary>

    public  enum CAUSE_VALUE:int
    
{
        
/// <summary>
        
/// 中继通道的范围越界
        
/// </summary>

        RSN_PCMNULL_CALLER=-1,
        
/// <summary>
        
/// 收到的消息中不含有原因指示码,或没有新的ISUP消息到达
        
/// </summary>

        RSN_UNKOWNNUM_ISUP=0,
        
/// <summary>
        
/// //空号
        
/// </summary>

        RSN_UNALLOCATED_NUMBER = 0x01
        
/// <summary>
        
///        //正常的呼叫清除
        
/// </summary>

        RSN_NORMAL_CALL_CLEARING = 0x10
        
/// <summary>
        
///  //用户忙
        
/// </summary>

        RSN_USER_BUSY = 0x11,    
        
/// <summary>
        
///  //无用户响应
        
/// </summary>    

        RSN_NO_USER_RESPONDING = 0x12
        
/// <summary>
        
/// //被叫无应答,超时未摘机
        
/// </summary>

        RSN_USER_ALERTING_NO_ANSWER = 0x13
        
/// <summary>
        
///  //呼叫拒绝
        
/// </summary>

        RSN_CALL_REJECTED = 0x15
        
/// <summary>
        
///    //不完整的号码
        
/// </summary>

        RSN_INCOMPLETE_NUMBER = 0x1c,
        
/// <summary>
        
///  //正常,未规定
        
/// </summary>

        RSN_NORMAL_NO_SET = 0x1f,
        
/// <summary>
        
/// //无可用的电路
        
/// </summary>

        RSN_NO_CIRCUIT_CHANNELAVAILABLE = 0x22
        
/// <summary>
        
/// //请求的电路不可用
        
/// </summary>

        RSN_REQUESTEDCIRCUIT_CHANNEL_NOTAVAILABLE = 0x2c,
        
/// <summary>
        
///     //定时器超时恢复
        
/// </summary>

        RSN_RECOVERY_ON_TIME_EXPIRY = 0x66,
        
/// <summary>
        
/// //本地释放电路
        
/// </summary>

        RSN_LOCAL_RLC = 0x20,
        
/// <summary>
        
/// //电路复原
        
/// </summary>               

        RSN_RECEIVE_RSC = 0x21,                                 

    }
;

    
/// <summary>
    
/// 信道状态
    
/// </summary>

    public struct TRK_ST
    
{
        
public TRUNK_ST ST;
        
public int ConnUrID;
        
public int ConnTrID;
        
public string DialNum;
    }


    
public struct PR
    
{
        [MarshalAs(UnmanagedType.ByValArray,SizeConst
=32)]
        
public char[] TelarrChar;
        
public char[] CallarrChar;
    }


    
public struct TelNum
    
{
        [MarshalAs(UnmanagedType.ByValArray, SizeConst 
= 32)]
        
public byte[] arrTelNum;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst 
= 32)]
        
public byte[] arrCallNum;
    }

}


这几个类是所有代码的核心内容.先贴出来,下一篇会详细说说在交互编程中遇到的问题.

posted on 2008-07-08 09:37  H.Wong  阅读(6815)  评论(21编辑  收藏  举报