C#和硬件驱动交互编程

来源:互联网 发布:ingress是什么软件 编辑:程序博客网 时间:2024/05/22 00:36
源文地址:http://www.cnblogs.com/cnherman/archive/2008/07/08/1237937.html 上一年在公司做了一个小小的IVR项目.觉得这是一个和硬件驱动交互编程的不错例子. 共享一下.也讨论一下. 代码:(这个是调用系统驱动的DLL) using System; using System.Text; using DJVoiceCard.Lib; namespace DJVoiceCard.DL { public class SysFunction { 系统操作#region 系统操作 /**//// /// 初始化系统 /// /// public static bool SysInit(ref string sErr) { try { StringBuilder sSys_INC = new StringBuilder(""); StringBuilder sPrompt_INC = new StringBuilder("Prompt.ini"); int iSysInit = ISUP_Lib.DJISUP_InitSystem(); int iCardInit = DJFunction.DJSys_EnableCard(sSys_INC, sPrompt_INC); bool iPromptInit = DJFunction.DJSys_EnableDtmfSend(); if (iSysInit == 1) { if (iCardInit == 0) { if (iPromptInit) { return true; } else { sErr = "未能加载声音文件" + iPromptInit.ToString(); return false; } } else { sErr = iCardInit.ToString(); return false; } } else { sErr = iSysInit.ToString(); return false; } } catch (Exception ex) { sErr = ex.Message; } return false; } /**//// /// 退出系统 /// public static void SysExit() { DJFunction.DJSys_DisableCard(); ISUP_Lib.DJISUP_ExitSystem(); } #endregion 中继通道操作#region 中继通道操作 /**//// /// 获取中继通道总数 /// /// public static int iTrkTotal() { return DJFunction.DJTrk_GetTotalTrunkNum(); } /**//// /// 信道状态; /// ///////// public static int iRaleyStetes(byte PCM_NO, byte Relay_NO) { return ISUP_Lib.DJISUP_GetChnState(PCM_NO, Relay_NO); } /**//// /// 循环刷新缓存; /// public static void Push_GerEvent() { try { ISUP_Lib.DJISUP_GetEvent(); DJFunction.DJSys_PushPlay(); } catch(Exception Ex) { } } /**//// /// 获得中继号 /// ////// public static int iPCMID(int iTrunkID) { return DJFunction.DJTrk_GetPcmID(iTrunkID); } /**//// /// 被叫号码 /// ///////// public static TC_INI_TYPE GetCallNum(int PCM_NO, int Relay_NO) { TC_INI_TYPE sReVal = new TC_INI_TYPE(); ISUP_Lib.DJISUP_GetCalleeNum((byte)PCM_NO, (byte)Relay_NO, ref sReVal); return sReVal; } /**//// /// 主叫号码 /// ///////// public static TC_INI_TYPE GetCallerNum(int PCM_NO, int Relay_NO) { TC_INI_TYPE sReVal = new TC_INI_TYPE(); ISUP_Lib.DJISUP_GetCallerNum((byte)PCM_NO, (byte)Relay_NO, ref sReVal); return sReVal; } /**//// /// 获取用户按键 /// ////// public static StringBuilder GetUserKeyPress(int Relay_NO) { return ISUP_Lib.DJTrk_GetDtmfCode(Relay_NO); } /**//// /// 设置中继信道的状态; /// //////public static void SetRelayStates(int iTrunkID, int States) { ISUP_Lib.DJISUP_SetChnState(((byte)(iTrunkID / 30)), ((byte)(iTrunkID % 30)), (byte)States); } /**//// /// 呼出 /// //////////// public static bool bCallOut(int iTrunkID, string CalleeNum, string CallerNum, ref string sErr) { StringBuilder Callee = new StringBuilder(CallerNum); StringBuilder Caller = new StringBuilder(CalleeNum); if (iTrunkID != -1) { bool bRel = ISUP_Lib.DJISUP_Callout(iTrunkID / 30, iTrunkID % 30, ref Callee, ref Caller); //sErr = Callee.ToString() + "||" + Caller.ToString()+"||"+iTrunkID.ToString(); return bRel; } else { sErr = "NaN"; return false; } } /**//// /// string /// //////////// public static bool bCallOut(int iTrunkID, string CalleeNum, string CallerNum) { char[] telNum = new char[120]; PR p = new PR(); p.TelarrChar = telNum; telNum = CalleeNum.ToCharArray(); byte[] _telNum = new byte[120]; _telNum = Encoding.ASCII.GetBytes(telNum); char[] CallNum = new char[120]; CallNum = CallerNum.ToCharArray(); byte[] _CallNum = new byte[120]; p.CallarrChar = CallNum; _CallNum = Encoding.ASCII.GetBytes(CallerNum); if (iTrunkID != -1) { return ISUP_Lib.DJISUP_Callout(iTrunkID / 30, iTrunkID % 30, ref CalleeNum, ref CallerNum); } else { return false; } } /**//// /// byte][ /// //////////// public static bool bCallOut(int iTrunkID, byte[] CalleeNum, byte[] CallerNum) { unsafe { if (iTrunkID != -1) { return ISUP_Lib.DJISUP_Callout(iTrunkID / 30, iTrunkID % 30, CalleeNum, CallerNum); } else { return false; } } } /**//// /// char * /// //////////// public static unsafe bool bCallOut(int iTrunkID, StringBuilder calleeNum, StringBuilder callerNum) { unsafe { if (iTrunkID != -1) { return ISUP_Lib.DJISUP_Callout(iTrunkID / 30, iTrunkID % 30, calleeNum, callerNum); } else { return false; } } } /**//// /// char * /// //////////// public static unsafe bool bCallOut(int iTrunkID, string sCalleeNum, string sCallerNum, bool isM, bool isMT) { unsafe { char[] sCallNumarr = sCalleeNum.ToCharArray(); char[] sCallerNumarr = sCallerNum.ToCharArray(); if (iTrunkID != -1) { return ISUP_Lib.DJISUP_Callout(iTrunkID / 30, iTrunkID % 30, sCallNumarr, out sCallerNumarr, out isM, out isMT); } else { return false; } } } /**//// /// ulong /// //////////// public static bool bCallOut(int iTrunkID, ulong CalleeNum, ulong CallerNum) { unsafe { if (iTrunkID != -1) { return ISUP_Lib.DJISUP_Callout(iTrunkID / 30, iTrunkID % 30, ref CalleeNum, ref CallerNum); } else { return false; } } } /**//// /// 初始化索引通道 /// ///public static void PlayFileInit(int TrunkID) { DJFunction.DJVoc_InitIndexPlayFile(TrunkID); } /**//// /// 添加索引文件 /// ///////// public static bool AddIndexFile(int TrunkID, byte[] FileName) { return DJFunction.DJVoc_AddIndexPlayFile(TrunkID, FileName); } /**//// /// 开始播放索引文件 /// ////// public static bool PlayFileStart(int TrunkID) { return DJFunction.DJVoc_StartIndexPlayFile(TrunkID); } /**//// /// 停止播放索引文件 /// ////// public static void PlayFileEnd(int TrunkID) { DJFunction.DJVoc_StopIndexPlayFile(TrunkID); } /**//// /// 检查是否索引播放结束 /// ////// public static bool PlayFileEndCHK(int TrunkID) { return DJFunction.DJVoc_CheckIndexPlayEnd(TrunkID); } #endregion 获取空闲中继信道#region 获取空闲中继信道 /**//// /// 获取空闲中继信道 /// /// public static int iFreePCM() { byte mo_NO = 0, dt_NO = 0; if (ISUP_Lib.DJISUP_GetCalloutChnNew(ref mo_NO, ref dt_NO)) { return (int)(mo_NO * 30 + dt_NO); } return -1; } #endregion 用户#region 用户 /**//// /// 用户通道总数 /// /// public static int iUserTotal() { return DJFunction.DJUser_GetTotalUserNum(); } /**//// /// 呼出状态 /// ///////// public static int iCallOutStates(int iPCMID, int iTrunkID) { return ISUP_Lib.DJISUP_GetCalloutState(iPCMID, iTrunkID); } /**//// /// 获取路径 /// /// //public static byte[] appDIR() //{ // return DJFunction.DJSys_GetInstallDir(); //} /**//// /// 获取路径 /// /// public static StringBuilder appDIRStr() { return DJFunction.DJSys_GetInstallDir(); } /**//// /// 播放语音 /// ////// public static bool bISplayVoice(int iTrunkID, byte[] sVoiceFile) { int iISFree = DJFunction.DJVoc_SFVC_ForPlay_New(iTrunkID, true); if (iISFree == -1) { return false; } //if() bool bISPlayFile = DJFunction.DJVoc_PlayFile(iTrunkID, sVoiceFile); //bool bISLink =DJFunction.DJExg_SetLinkPlayVoiceToTrunk(iTrunkID, iISFree); if (!bISPlayFile) { return false; } //if (!bISLink) //{ // return false; //} return true; } public static int iPlayVoice(int iVoiceChn) { return DJFunction.DJVoc_VoiceStart(iVoiceChn); } /**//// /// 断开语音通道链接 /// /// ////// public static bool ClearCHN(int iTrunkID) { return DJFunction.DJExg_ClearLinkTrunkAndUserByTrunk(iTrunkID); } /**//// /// 初始化用户馈电 /// ///public static void UserPowerOn(int iUserCHNID) { DJFunction.DJUser_SetPowerON(iUserCHNID); } /**//// /// 允许用户通道在摘机时自动送拨号音,这是系统的缺省工作方式。 /// ////// public static bool UserEnableDailSound(int iUserCHNID) { return DJFunction.DJUser_EnableDialSound(iUserCHNID); } /**//// /// 对给定的语音通道循环播放系统提示音。 /// ///////// public static bool LoopVoiceM(int voiceCHNID, StringBuilder voiceFileName) { return DJFunction.DJVoc_LoopPlayPromptFile(voiceCHNID, voiceFileName); } /**//// /// 空闲语音通道 /// /// public static int iFreeVoiceCHNID() { return DJFunction.DJVoc_SearchFreeVoiceChannelForPlay(); } /**//// /// 检查是否正在对用户模块振铃 /// ////// public static bool bIsRingDerctor(int iUserCHNID) { return DJFunction.DJUser_RingDetect(iUserCHNID); } /**//// /// 停止用户通道振铃 /// ////// public static bool bIsStopRing(int iUserCHNID) { return DJFunction.DJUser_StopRing(iUserCHNID); } /**//// /// 断开放音语音通道和用户通道之间的联接 /// ////// public static bool bClearVoiceFromUser(int iUserCHNID) { return DJFunction.DJExg_ClearLinkPlayVoiceFromUser(iUserCHNID); } /**//// /// 复位用户DTMF拨号信息,拨号位数置 0,DTMF缓冲区清空 /// ////// public static bool bIsInitDailBuf(int iUserCHNID) { return DJFunction.DJUser_InitDialBuf(iUserCHNID); } /**//// /// 得用LINK方式联接在本通道上的用户通道号。 /// ////// public static int iLinkUserCHNID(int iTrunkID) { return DJFunction.DJTrk_GetConnectUserID(iTrunkID); } /**//// /// 取得给本通道放音的语音通道号,如果没有放音通道与本中继通道相连,返回-1 /// ////// public static int iVoicePlayForTrunk(int iTrunkID) { return DJFunction.DJTrk_GetTrunkPlayID(iTrunkID); } /**//// /// 断开中继通道和放音语音通道的连通。 /// ////// public static bool bIsClearTrunkVoiceLink(int iTrunkID) { return DJFunction.DJExg_ClearLinkPlayVoiceFromTrunk(iTrunkID); } /**//// /// 清空系统的DTMF缓冲区,如果在缓冲区中有DTMF按键的值,将会丢失 /// ////// public static bool bIsInitDtmfByTrunkID(int iTrunkID) { return DJFunction.DJTrk_InitDtmfBuf(iTrunkID); } /**//// /// 获取CPG返回 /// ////// public static int iCPGReval(int iTrunkID) { return ISUP_Lib.DJISUP_GetEventInfo(iTrunkID / 30, iTrunkID % 30); } /**//// /// 获取ISUP返回 /// ////// public static int ISUPReVal(int iTrunkID) { return ISUP_Lib.DJISUP_GetRecvCauseValue(iTrunkID / 30, iTrunkID % 30); } /**//// /// 检查该语音通道的语音操作是否结束,即录放音是否到达指定的大小。 /// ////// public static bool bIsVocPlayEnd(int iVocCHNID) { return DJFunction.DJVoc_CheckVoiceEnd(iVocCHNID); } /**//// /// 停止文件放音。多次调用本函数没有影响 /// ///public static void StopPlayVocInTrunk(int iTrunkID) { DJFunction.DJVoc_StopPlayFile(iTrunkID); } #endregion } } Code 1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Runtime.InteropServices; 5 6namespace DJVoiceCard.Lib 7{ 8 public class DJFunction 9 { 10 /**//// 11 /// 初始化东进七号信令中继语音卡的硬件 12 /// 13 ///INI系统配置文件名 14 ///提示音对照表文件名,一般使用PROMPT.INI 15 /// 0,成功;其他:-12,在读取INI文件时错误; 16 /// -17,打开驱动程序的设备文件时错误[驱动程序名为:DJPCI-东进七号信令中继语音卡,NT;DJPCI2K 东进七号信令中继语音卡,2000]; 17 /// -18,检查硬件失败; 18 /// -19,读取提示音文件时失败; 19 /// 20 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 21 public static extern int DJSys_EnableCard(StringBuilder sIncFileName, StringBuilder sVoiceIncFileName); 22 23 /**//// 24 /// 结束所有中继语音卡的操作, 释放API所占用的资源, 复位中继语音卡的状态, 应该在程序结束前调用。 25 /// 由于同DJSys_EnableCard类似的原因,当调用本函数之后,你就不能再调用其他的有关数字中继卡的函数。 26 /// 只有DJSys_EnableCard函数成功后,才能调用本函数,并且要求成对出现。 27 /// 28 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 29 public static extern void DJSys_DisableCard(); 30 31 /**//// 32 /// 得到系统内中继通道总数; 33 /// 34 /// 35 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 36 public static extern int DJTrk_GetTotalTrunkNum(); 37 38 39 /**//// 40 /// 维持文件录音和文件放音连续的函数。 41 /// 要求应用程序必须在小于4秒钟内调用本函数一次(允许多次)。 42 /// 在数字中继卡的底层驱动程序中,对每个语音通道开辟了64K的缓冲区。 43 /// 当进行文件方式的录音或放音时,不断的调用函数DJSys_PushPlay可以保证缓冲区的更新。 44 /// 45 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 46 public static extern void DJSys_PushPlay(); 47 48 /**//// 49 /// 获得PCM中继ID 50 /// 51 ///中继通道号; 52 /// 53 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 54 public static extern int DJTrk_GetPcmID(int trunkID); 55 56 57 /**//// 58 /// 根据中继通道号,来断开本中继通道与用户通道之间的双向连通,对应DJExg_SetLinkTrunkAndUser 59 /// 60 ///61 /// 62 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 63 public static extern bool DJExg_ClearLinkTrunkAndUserByTrunk(int trunkID); 64 65 /**//// 66 /// 使能发送DTMF的功能。 67 /// 68 /// 69 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 70 public static extern bool DJSys_EnableDtmfSend(); 71 72 /**//// 73 /// 取用户通道总数。如果是一片D161A/D081A卡,本函数返回16/8,依次类推。 74 /// 函数返回:● 系统内的用户通道数 75 /// 76 /// 系统内的用户通道数 77 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 78 public static extern int DJUser_GetTotalUserNum(); 79 80 /**//// 81 /// 搜索一个空闲的语音通道 82 /// 83 ///84 ///85 /// 86 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 87 public static extern int DJVoc_SFVC_ForPlay_New(int trunkID, bool IsForTrunk); 88 89 /**//// 90 /// 播放语音文件 91 /// 92 ///93 ///94 /// 95 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 96 public static extern bool DJVoc_PlayPromptFile(int voiceID,byte[] voiceName); 97 98 /**//// 99 /// 建立放音语音通道到中继通道的连通。本函数在本质上是一个中继通道去听语音通道。 100 /// 当中继通道处于准备好状态,语音通道已经开始操作(直接或间接调用过DJVoc_VoiceStart 函数), 101 /// 则可通过此函数将语音通道中的语音放给中继通道上的电话用户听。 102 /// 103 ///104 ///105 /// 106 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 107 public static extern bool DJExg_SetLinkPlayVoiceToTrunk(int trunkID, int voiceID); 108 109 /**//// 110 /// 对用户模块馈电,这是系统的初始状态,当userID越界时,调用DJSYS_GetErrCode得到_ERR_InvalidID。 111 /// 只有在直流电源正常工作状态下,用户通道才能正常操作,系统启动后缺省为开电源。 112 /// 如果你正常的接入电源,则调用完本函数后,与该userID相连的电话机将会处于有馈电的状态,拿起话机听筒,在电话机上按键,会听到按键的声音。 113 /// 当该用户通道插入的是中继模块,用来接入模拟电话线时,调用本函数,相当于电话机摘机。 114 /// 由于这是系统的缺省状态,所以,如果是中继模块,在初始化时,需要将所有的中继模块挂机,这可以通过调用函数DJUser_SetPowerOFF来完成。 115 /// 116 ///用户通道号 117 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 118 public static extern void DJUser_SetPowerON(int userID); 119 120 /**//// 121 /// 允许用户通道在摘机时自动送拨号音,这是系统的缺省工作方式。当userID越界时,返回 0,同时置ErrCode=_ERR_InvalidID. 122 /// 当处于使能方式时,用户通道所连接的电话机摘机后,系统自动送拨号音,如果按下电话机上的按键,会自动停止拨号音; 123 /// 电话机挂机,也自动停止拨号音。 124 /// 125 ///126 /// 127 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 128 public static extern bool DJUser_EnableDialSound(int userID); 129 /**//// 130 /// 对给定的语音通道循环播放系统提示音 131 /// 函数返回:1● 操作成功;0 ● 操作失败,调用DJSys_GetErrCode函数将返回失败原因; 132 /// 133 ///语音通道号 134 ///系统提示音名字 135 /// 136 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 137 public static extern bool DJVoc_LoopPlayPromptFile(int voiceID, StringBuilder voiceName); 138 139 /**//// 140 /// 搜索返回一个空闲的用于放音的语音通道 141 /// 142 /// 143 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 144 public static extern int DJVoc_SearchFreeVoiceChannelForPlay(); 145 146 /**//// 147 /// 检查是否正在对用户模块振铃。当userID越界时,返回 0,同时置ErrCode=_ERR_InvalidID 148 /// 函数返回: 149 /// 1● 正在振铃 150 /// 0● 非振铃 151 /// 152 ///用户通道号 153 /// 154 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 155 public static extern bool DJUser_RingDetect(int userID); 156 157 /**//// 158 /// 使用户通道开始振铃。当userID越界时,返回 0,同时置ErrCode=_ERR_InvalidID。 159 /// 调用本函数,将会对用户模块所连接的电话机振铃,该振铃是断续的振铃声,由底层驱动程序来控制振铃的时间间隔. 160 /// 函数返回 161 /// 1● 操作成功 162 /// 0● 操作失败,调用DJSys_GetErrCode()将返回失败原因 163 /// 如果要使电话机振铃,必须正确的接入外接电源和铃流源。 164 /// 165 ///用户通道号 166 /// 167 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 168 public static extern bool DJUser_StartRing(int userID); 169 170 /**//// 171 /// 停止用户模块的振铃。当userID越界时,返回 0,同时置ErrCode=_ERR_InvalidID。 172 /// 函数返回: 173 /// 1● 操作成功 174 /// 0● 操作失败,调用DJSys_GetErrCode()将返回失败原因 175 /// 176 ///用户通道号 177 /// 178 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 179 public static extern bool DJUser_StopRing(int userID); 180 181 /**//// 182 /// 断开放音语音通道和用户通道之间的联接 183 /// 184 ///185 /// 186 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 187 public static extern bool DJExg_ClearLinkPlayVoiceFromUser(int userID); 188 189 /**//// 190 /// 复位用户DTMF拨号信息,拨号位数置 0,DTMF缓冲区清空。当userID越界时,返回 0,同时置ErrCode=_ERR_InvalidID。 191 /// 参考函数DJUser_GetDialCode的功能描述。 192 /// 函数返回: 193 /// 1● 操作成功 194 /// 0● 操作失败,调用DJSys_GetErrCode()将返回失败原因 195 /// 196 ///用户通道号 197 /// 198 /// 199 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 200 public static extern bool DJUser_InitDialBuf(int userID); 201 202 203 /**//// 204 /// 得用LINK方式联接在本通道上的用户通道号。 205 /// 206 ///207 /// 208 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 209 public static extern int DJTrk_GetConnectUserID(int trunkID); 210 211 /**//// 212 /// 取得给本通道放音的语音通道号,如果没有放音通道与本中继通道相连,返回-1 213 /// 214 ///215 /// 216 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 217 public static extern int DJTrk_GetTrunkPlayID(int trunkID); 218 219 220 /**//// 221 /// 断开中继通道和放音语音通道的连通。 222 /// 223 ///224 /// 225 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 226 public static extern bool DJExg_ClearLinkPlayVoiceFromTrunk(int trunkID); 227 228 /**//// 229 /// 清空系统的DTMF缓冲区,如果在缓冲区中有DTMF按键的值,将会丢失 230 /// 231 ///232 /// 233 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 234 public static extern bool DJTrk_InitDtmfBuf(int trunkID); 235 236 /**//// 237 /// 检查该语音通道的语音操作是否结束,即录放音是否到达指定的大小。 238 /// 239 ///240 /// 241 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 242 public static extern bool DJVoc_CheckVoiceEnd(int voiceChannelID); 243 244 /**//// 245 /// 停止文件放音。多次调用本函数没有影响 246 /// 247 ///248 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 249 public static extern void DJVoc_StopPlayFile(int trunkID); 250 251 /**//// 252 /// 得到当前软件开发系统的安装目录。该目录等于INI配置文件中的InstallDir的设置。 253 /// 254 /// 255 //[DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 256 //public static extern byte[] DJSys_GetInstallDir(); 257 /**//// 258 /// 得到当前软件开发系统的安装目录。该目录等于INI配置文件中的InstallDir的设置。 259 /// 260 /// 261 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 262 public static extern StringBuilder DJSys_GetInstallDir(); 263 264 /**//// 265 /// 放音 266 /// 267 ///268 ///269 /// 270 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 271 public static extern bool DJVoc_PlayFile(int trunkID, byte[] FileName); 272 /**//// 273 /// 开始放音 274 /// 275 ///276 /// 277 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 278 public static extern int DJVoc_VoiceStart(int voiceChannelID); 279 /**//// 280 /// 初始化中继通道索引放音 281 /// 282 ///中继通道 283 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 284 public static extern void DJVoc_InitIndexPlayFile(int trunkID); 285 286 /**//// 287 /// 增加索引放音文件。失败的可能原因有文件不存在,或者文件索引数组已满(最多100个)。 288 /// 289 ///中继通道 290 ///文件路径 291 /// 292 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 293 public static extern bool DJVoc_AddIndexPlayFile(int trunkID, byte[] FileName); 294 295 296 /**//// 297 /// 开始一次文件索引放音。 298 /// 299 ///中继通道 300 /// 301 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 302 public static extern bool DJVoc_StartIndexPlayFile(int trunkID); 303 304 305 /**//// 306 /// 停止索引文件放音。该函数停止指定中继通道的索引文件放音,使用DJVoc_StartIndexPlayFile函数进行多文件放音结束,一定要调用该函数来停止放音 307 /// 308 /// 309 ///310 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 311 public static extern void DJVoc_StopIndexPlayFile(int trinkID); 312 313 /**//// 314 /// 检查索引文件放音是否结束,并维护索引文件放音的持续。当进行索引文件放音时,必须调用该函数,以保证索引文件放音的连续性 315 /// 316 ///317 /// 318 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 319 public static extern bool DJVoc_CheckIndexPlayEnd(int trunkID); 320 } 321} 322 Code 1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Runtime.InteropServices; 5 6namespace DJVoiceCard.Lib 7{ 8 public struct TC_INI_TYPE 9 { 10 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] 11 public byte[] bCallNum; 12 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] 13 public byte[] bCalleeNum; 14 } 15 public struct FL_PA 16 { 17 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] 18 public byte[] bFilePath; 19 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] 20 public byte[] bVoiceFile; 21 } 22 public class ISUP_Lib 23 { 24 /**//// 25 /// 26 /// 27 ///本机内的PCM逻辑编号,从0开始 28 ///PCM内的中继通道号,0-29 29 ///本中继通道要采取的动作 30 ///31 ///32 ///33 ///34 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 35 public static extern void DJISUP_SetChnState(byte mo_num, byte dt_num, byte state); 36 37 /**//// 38 /// 七号信令系统接口初始化,在应用程序初始化时调用。 39 /// 调用本函数,首先检查在本机内是否已经启动了七号信令链路的处理程序CCS7SERVER.EXE; 40 /// 如果已经运行,则初始化本程序和CCS7SERVER.EXE之间的接口,以便能够通过CCS7SERVER.EXE来收发有关七号信令的信息包。 41 /// 本函数应在DJSys_EnableCard之前调用 42 /// 43 /// 1● 初始化成功;-1● 没有七号信令处理程序CCS7SERVER运行,或者在读取TC-NO7.INI时发生错误。 44 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 45 public static extern int DJISUP_InitSystem(); 46 47 48 49 /**//// 50 /// 本函数在程序退出时调用,用以释放调用初始化函数DJISUP_InitSystem时所分配的内存。 51 /// 52 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 53 public static extern void DJISUP_ExitSystem(); 54 55 56 /**//// 57 /// 中继通道(mo_num,dt_num)的当前状态,可能的返回值是: 58 /// #define ISUP_CH_FREE 1  // 空闲状态 59 /// #define ISUP_CH_WAIT_RELEASE 2  // DLL等待应用程序同步释放资源 60 /// #define ISUP_CH_LOCAL_BLOCK 3  // 本地闭塞状态 61 /// #define ISUP_CH_REMOTE_BLOCK 4  // 远端闭塞状态 62 /// #define ISUP_CH_LOCAL_AND_REMOTE_BLOCK 5 //本地和远端锁闭状态 63 /// #define ISUP_CH_UNAVIABLE 6  // 不可用态(网络不通等原因导致) 64 /// #define ISUP_CALLER_WAIT_ANM 7  //被叫闲,等待被叫应答 65 /// #define ISUP_CALLER_CONNECT 8  // 去话连通状态 66 /// #define ISUP_CALLEE_RECV_IAM 9  // 呼叫到达,接收全地址 67 /// #define ISUP_CALLEE_CONNECT 10  // 摘机,来话连通 68 /// #define ISUP_CH_LOCAL_SUSPEND 11  // 本地暂停 69 /// #define ISUP_CH_REMOTE_SUSPEND 12  // 远端暂停 70 /// 注意: 71 /// 应用层程序应循环调用该函数,并根据取得的状态采取相应的动作。 72 /// 73 ///本机内的PCM逻辑编号,从0开始 74 ///PCM内的中继通道号,0-29 75 /// 76 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 77 public static extern int DJISUP_GetChnState(byte PCM_NO, byte Relay_NO); 78 79 /**//// 80 /// 获取呼出的主叫号码 81 /// ref 参数所指的就是呼出主叫号码 82 /// 83 ///84 ///85 ///86 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 87 public static extern void DJISUP_GetCallerNum(byte PCM_NO, byte Relay_NO, ref TC_INI_TYPE Call_NO); 88 89 /**//// 90 /// 呼叫到达时,用本函数来取得被叫号码。 91 /// 当函数返回后,在call_id所指向的字符串数组中,存放有已经收到的号码。 92 /// 注意,call_id所指向的字符串数组必须事先分配好空间。 93 /// 94 ///95 ///96 ///97 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 98 public static extern void DJISUP_GetCalleeNum(byte PCM_NO, byte Relay_NO, ref TC_INI_TYPE Callee_NO); 99 100 101 /**//// 102 /// 处理中继通道的事件,改变中继通道的状态。 103 /// 此函数要在主流程的大循环中调用,一般同函数DJSys_PushPlay放在一起。 104 /// 通过本函数,系统的状态才能发生变迁。 105 /// 106 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 107 public static extern void DJISUP_GetEvent(); 108 109 /**//// 110 /// 维持文件录音和文件放音连续的函数。 111 /// 要求应用程序必须在小于4秒钟内调用本函数一次(允许多次)。 112 /// 在数字中继卡的底层驱动程序中,对每个语音通道开辟了64K的缓冲区。 113 /// 当进行文件方式的录音或放音时,不断的调用函数DJSys_PushPlay可以保证缓冲区的更新。 114 /// 115 [DllImport("Tce1_32.dll", CharSet = CharSet.Auto)] 116 public static extern void DJSys_PushPlay(); 117 118 119 /**//// 120 /// 获取Dtmf号码 121 /// 122 ///123 /// 124 [DllImport("Tce1_32.dll", CharSet = CharSet.Ansi)] 125 public static extern StringBuilder DJTrk_GetDtmfCode(int trunkID); 126 127 128 /**//// 129 /// 对某一个中继通道启动一次呼出 130 /// 131 ///本机内的PCM逻辑编号,从0开始 132 ///PCM内的中继通道号,0-29 133 ///呼出时的被叫号码 134 ///呼出时的主叫号码 135 /// 136 /// 137 //[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)] 138 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 139 public static extern bool DJISUP_Callout(int nPCM, int nCHN, char[] szCalleeNumber, out char[] szCallerNumber, out bool bCalleeSignalTerminal, out bool bCallerSignalTerminal); 140 /**//// 141 /// 对某一个中继通道启动一次呼出 142 /// 143 ///本机内的PCM逻辑编号,从0开始 144 ///PCM内的中继通道号,0-29 145 ///呼出时的被叫号码 146 ///呼出时的主叫号码 147 /// 148 /// 149 //[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)] 150 [DllImport("TCISUP.dll", CharSet = CharSet.Ansi)] 151 public unsafe static extern bool DJISUP_Callout(int nPCM, int nCHN,StringBuilder szCalleeNumber,StringBuilder szCallerNumber); 152 /**//// 153 /// 对某一个中继通道启动一次呼出 154 /// 155 ///本机内的PCM逻辑编号,从0开始 156 ///PCM内的中继通道号,0-29 157 ///呼出时的被叫号码 158 ///呼出时的主叫号码 159 /// 160 /// 161 //[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)] 162 [DllImport("TCISUP.dll", CharSet = CharSet.Ansi)] 163 public unsafe static extern bool DJISUP_Callout(int nPCM, int nCHN, ref ulong szCalleeNumber, ref ulong szCallerNumber); 164 /**//// 165 /// 对某一个中继通道启动一次呼出 166 /// 167 ///本机内的PCM逻辑编号,从0开始 168 ///PCM内的中继通道号,0-29 169 ///呼出时的被叫号码 170 ///呼出时的主叫号码 171 /// 172 /// 173 //[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)] 174 [DllImport("TCISUP.dll", CharSet = CharSet.Ansi)] 175 public unsafe static extern bool DJISUP_Callout(int nPCM, int nCHN, ref StringBuilder szCalleeNumber, ref StringBuilder szCallerNumber); 176 /**//// 177 /// 对某一个中继通道启动一次呼出 178 /// 179 ///本机内的PCM逻辑编号,从0开始 180 ///PCM内的中继通道号,0-29 181 ///呼出时的被叫号码 182 ///呼出时的主叫号码 183 /// 184 /// 185 //[MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] 186 [DllImport("TCISUP.dll", CharSet = CharSet.Ansi)] 187 public unsafe static extern bool DJISUP_Callout(int nPCM, int nCHN, ref char[] szCalleeNumber, ref char[] szCallerNumber); 188 /**//// 189 /// 对某一个中继通道启动一次呼出 190 /// 191 ///本机内的PCM逻辑编号,从0开始 192 ///PCM内的中继通道号,0-29 193 ///呼出时的被叫号码 194 ///呼出时的主叫号码 195 /// 196 /// 197 //[MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)] 198 [DllImport("TCISUP.dll", CharSet = CharSet.Ansi)] 199 public unsafe static extern bool DJISUP_Callout(int nPCM, int nCHN, ref string szCalleeNumber, ref string szCallerNumber); 200 201 202 /**//// 203 /// 对某一个中继通道启动一次呼出 204 /// 205 ///本机内的PCM逻辑编号,从0开始 206 ///PCM内的中继通道号,0-29 207 ///呼出时的被叫号码 208 ///呼出时的主叫号码 209 /// 210 /// 211 //[MarshalAs(UnmanagedType.ByValArray,SizeConst=32)] 212 [DllImport("TCISUP.dll", CharSet = CharSet.Ansi)] 213 public unsafe static extern bool DJISUP_Callout(int nPCM, int nCHN, byte[] szCalleeNumber, byte[] szCallerNumber); 214 215 216 /**//// 217 /// 调用DJISUP_Callout对某通道启动一次呼出之后, 218 /// 通过调用该函数获取呼出状态, 219 /// 其返回值以如下位掩码的形式存放, 220 /// 故将返回值与下列值做与(&)运算,即可知当前呼出状态。 221 /// 222 ///223 ///224 /// 225 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 226 public static extern int DJISUP_GetCalloutState(int nPCM, int nCHN); 227 228 /**//// 229 /// 该函数用来在单信令点时选择一个用来呼出的中继通道, 230 /// 此函数较DJISUP_GetCalloutChn增加了处理同抢的功能, 231 /// 且可选的呼出通道范围为本机内的所有通道。一般情况, 232 /// 应用程序也可以自己来查找一个空闲的中继通道。 233 /// 234 ///235 ///236 /// 237 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 238 public static extern bool DJISUP_GetCalloutChnNew( ref byte mo_num, ref byte dt_num ); 239 240 /**//// 241 /// 本函数用于获取CPG消息的事件信息,协议规定的事件信息 242 /// 243 ///244 ///245 /// 246 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 247 public static extern int DJISUP_GetEventInfo(int nPCM, int nCHN); 248 249 /**//// 250 /// 对收到的ISUP消息,获取其中的原因值 251 /// 252 ///253 ///254 /// 255 [DllImport("TCISUP.dll", CharSet = CharSet.Auto)] 256 public static extern int DJISUP_GetRecvCauseValue(int nPCM, int nCHN); 257 258 } 259} 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, } /**//// /// 信道状态 /// public enum RelayStates : int { /**//// /// // 空闲状态 /// ISUP_CH_FREE=1,   /**//// /// // DLL等待应用程序同步释放资源 /// ISUP_CH_WAIT_RELEASE=2 ,   /**//// /// // 本地闭塞状态 /// ISUP_CH_LOCAL_BLOCK=3 ,   /**//// /// // 远端闭塞状态 /// ISUP_CH_REMOTE_BLOCK=4 ,   /**//// /// //本地和远端锁闭状态 /// ISUP_CH_LOCAL_AND_REMOTE_BLOCK=5 , /**//// /// // 不可用态(网络不通等原因导致) /// ISUP_CH_UNAVIABLE=6 ,   /**//// /// //被叫闲,等待被叫应答 /// ISUP_CALLER_WAIT_ANM=7 ,   /**//// /// // 去话连通状态 /// ISUP_CALLER_CONNECT=8 ,   /**//// /// // 呼叫到达,接收全地址 /// ISUP_CALLEE_RECV_IAM=9 ,   /**//// /// // 摘机,来话连通 /// ISUP_CALLEE_CONNECT=10 ,   /**//// /// // 本地暂停 /// ISUP_CH_LOCAL_SUSPEND=11,   /**//// /// // 远端暂停 /// ISUP_CH_REMOTE_SUSPEND=12, /**//// /// IAM消息到达 /// CALLEE_IAM_REACHED=0xf0, /**//// /// SAM消息到达提示 /// CALLEE_SAM_REACHED=0xf1, } /**//// /// 语音资源类型 /// public enum VoiceResourcesType:int { /**//// /// 没有语音资源 /// Res_NoRes = 0, /**//// /// 文件型语音资源 /// Res_File = 1, /**//// /// 系统内存型语音资源 /// Res_Xms = 2, }; /**//// /// 语音资源操作类型 /// public enum VoiceOperatorType { /**//// /// //没有语音操作 /// OP_NoOperator = 0, /**//// /// //普通放音 /// OP_Play = 1, /**//// /// //循环放音 /// OP_LoopPlay = 2, }; /**//// /// 用户状态类型 /// public enum USER_STATE { /**//// /// 未摘机 /// USR_OFFHOOK=0, /**//// /// 等待拨号 /// USR_WAITDIAL=1, /**//// /// 拨号 /// USR_DIAL=2, /**//// /// 结束 /// USR_ENDSESSION=3, /**//// /// 等待语音 /// USR_WAITONHOOK=4, /**//// /// 振铃 /// USR_RING=5, /**//// /// 通话 /// USR_CONNECT=6, /**//// /// 摘机中 /// USR_ONHOOK = 50, /**//// /// 取消振铃 /// USR_EXRING=51, /**//// /// 退出通话 /// USR_EXCONNECT=52 }; /**//// /// 中继信道状态 /// public enum TRUNK_ST { /**//// /// 空闲状态 /// TRK_FREE=0, //free state /**//// /// 准备状态 /// TRK_READY=1, //mfc stop state /**//// /// 振铃状态 /// TRK_RING=2, //ring user /**//// /// 拨号状态 /// TRK_CALLOUT=3, //user dial over, callout /**//// /// 等待摘机 /// TRK_WAITUSEROFFHOOK=4, //ring user, wait offhok /**//// /// 摘机状态 /// TRK_WAITUSERONHOOK=5, /**//// /// 结束谈话 /// TRK_ENDSESSION=6, //end a talk /**//// /// 链接状态 /// TRK_CONNECT=7, /**//// /// 为初始化状态 /// TRK_NULLSTATE=8, /**//// /// 播放状态 /// TRK_PLAY=9, /**//// /// 呼入状态 /// TRK_CALLIN=10, /**//// /// 摘机状态 /// TRK_ONHOOK=11, /**//// /// 挂机状态 /// TRK_HANGUP=12, }; /**//// /// 用户状态 /// public struct UR_ST { public int ConnUrID; public USER_STATE ST; public int ConnTrID; } /**//// /// 对收到的ISUP消息,获取其中的原因值 /// public enum CAUSE_VALUE:int { /**//// /// 中继通道的范围越界 /// RSN_PCMNULL_CALLER=-1, /**//// /// 收到的消息中不含有原因指示码,或没有新的ISUP消息到达 /// RSN_UNKOWNNUM_ISUP=0, /**//// /// //空号 /// RSN_UNALLOCATED_NUMBER = 0x01, /**//// /// //正常的呼叫清除 /// RSN_NORMAL_CALL_CLEARING = 0x10, /**//// /// //用户忙 /// RSN_USER_BUSY = 0x11, /**//// /// //无用户响应 /// RSN_NO_USER_RESPONDING = 0x12, /**//// /// //被叫无应答,超时未摘机 /// RSN_USER_ALERTING_NO_ANSWER = 0x13, /**//// /// //呼叫拒绝 /// RSN_CALL_REJECTED = 0x15, /**//// /// //不完整的号码 /// RSN_INCOMPLETE_NUMBER = 0x1c, /**//// /// //正常,未规定 /// RSN_NORMAL_NO_SET = 0x1f, /**//// /// //无可用的电路 /// RSN_NO_CIRCUIT_CHANNELAVAILABLE = 0x22, /**//// /// //请求的电路不可用 /// RSN_REQUESTEDCIRCUIT_CHANNEL_NOTAVAILABLE = 0x2c, /**//// /// //定时器超时恢复 /// RSN_RECOVERY_ON_TIME_EXPIRY = 0x66, /**//// /// //本地释放电路 /// RSN_LOCAL_RLC = 0x20, /**//// /// //电路复原 /// RSN_RECEIVE_RSC = 0x21, }; /**//// /// 信道状态 /// 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; } }
原创粉丝点击