⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 vs2005串口编程示例,好多例子,是学习串口编程方面不错的资料
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ex13_11
{
    public partial class Form1 : Form
    {
        short chanel = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            //初始化驱动程序
            long load = DJ160API.LoadDRV();
            //检测通道总数,并为每个通道分配语音缓冲区
            short wuseCh = DJ160API.CheckValidCh();
            short wFileBufLen = 16 * 1024;
            long card = DJ160API.EnableCard(wuseCh, wFileBufLen);
            //设置表格-通道的行数
            dataGridView1.RowCount = wuseCh;
            //检测每个通道类型
            short chanelTpye = 0; //定义通道类型变量
            string strType = "";
            for (short i = 0; i < wuseCh; i++)
            {
                chanelTpye = DJ160API.CheckChType(i);
                dataGridView1[0, i].Value = i;
                switch (chanelTpye)
                {
                    case 0:
                        strType = "内线";
                        break;
                    case 1:
                        strType = "外线";
                        break;
                    case 2:
                        strType = "悬空";
                        break;
                }
                dataGridView1[1, i].Value = strType;
                dataGridView1[2, i].Value = "空闲";
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            short wuseCh = DJ160API.CheckValidCh();
            short wFileBufLen = 16 * 1024;
            long card = DJ160API.EnableCard(wuseCh, wFileBufLen);

            DJ160API.Sig_Init(chanel);
            //检查(外线)是否有振铃信号或(内线)是否有提机
            bool ring = DJ160API.RingDetect(chanel);
            //外线提机
            DJ160API.OffHook(chanel);
            byte[] ss =new byte[textBox1.Text.Length];
            byte[] s ={ 0 };
            for (int i = 0; i < textBox1.Text.Length; i++)
            {
                ss[i] = Convert.ToByte(textBox1.Text.Substring(i, 1));
            }
            DJ160API.Sig_StartDial(chanel, ss, s, 0);
            timer1.Enabled = true;
            dataGridView1[2, chanel].Value = "拨号中...";
            dataGridView1[3, chanel].Value = textBox1.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DJ160API.HangUp(chanel);
            DJ160API.Sig_ResetCheck(chanel);
            DJ160API.StartSigCheck(chanel);
            timer1.Enabled = false;
            dataGridView1[2, chanel].Value = "空闲";
            dataGridView1[3, chanel].Value = "";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DJ160API.Sig_CheckDial(chanel);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            chanel = (short)e.RowIndex;
        }
    }
}

⌨️ 快捷键说明

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