使用Conexant USB CX93010调制解调器从串行端口获取Callerid?

时间:2014-05-01 07:42:20

标签: c# serial-port modem

我有一个C#代码但是当我将线路连接到手机时,它不需要来自拨号调制解调器连接到USB端口的CallerID。它获得了CallerID,但是在程序运行和阅读线上我只有RING。

这是我的代码:

public partial class Form1 : XtraForm
{
    public Form1()
    {
        InitializeComponent();            
    }

    SerialPort sp ;
    private void simpleButton1_Click(object sender, EventArgs e)
    {            
        sp = new SerialPort(textEdit1.Text);
        sp.NewLine = "\r\n";
        sp.Parity = Parity.None;
        sp.DataBits = 8;
        sp.StopBits = StopBits.One;
        sp.DtrEnable = true;
        sp.WriteBufferSize = 1024;

        sp.Open();
        sp.WriteLine("AT+VCID=1");
        sp.RtsEnable = true;
        timer1.Start();
    }

    void sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {

    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        sp.Close();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        memoEdit1.Text += "\n" + sp.ReadExisting();
    }

    private void simpleButton2_Click(object sender, EventArgs e)
    {
        sp.Close();
    }

3 个答案:

答案 0 :(得分:1)

当您的调制解调器支持来电显示时,请使用AT + CLIP = 1。这将导致在调用调制解调器时显示未经请求的+ CLIP消息。

+ CLIP未经请求的消息通常表述如下:

+CLIP: <number>,<type>,,,,<cli validity>

其中<number>是一个字符串,其中包含<type>定义的格式的数字。地址八位字节<type>,例如国际号码为145. <cli validity>确定该号码是否被保留等。

答案 1 :(得分:0)

科胜讯USB CX93010 ACF调制解调器没有FSK协议

答案 2 :(得分:0)

基于我对Conexant USB CX93010进行的一些测试,我将在下面发布代码。下面的代码在C(而不是C#)中,并且在Linux(而不是Windows)上运行。但是它应该为C#程序提供一个良好的基线。

该代码基于Sawdust编写的另一个Stack Overflow answer,并具有该程序的测试结果。

您还可以在http://www.arcelect.com处找到适用于科胜讯调制解调器的完整AT命令集。它的日期是2001年,但是它对调制解调器的AT命令比我在网上其他地方看到的要多。


这是代码。

#include <errno.h>
#include <fcntl.h> 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

#define DISPLAY_STRING 1

int set_interface_attribs(int fd, int speed)
{
    struct termios tty;

    if (tcgetattr(fd, &tty) < 0) {
        printf("Error from tcgetattr: %s\n", strerror(errno));
        return -1;
    }

    cfmakeraw (&tty);
    cfsetospeed(&tty, (speed_t)speed);
    cfsetispeed(&tty, (speed_t)speed);

    if (tcsetattr(fd, TCSANOW, &tty) != 0) {
        printf("Error from tcsetattr: %s\n", strerror(errno));
        return -1;
    }
    return 0;
}

void write_command(int fd, const void* cmd, size_t len)
{
    if (len == ~(size_t)0)
        len = strlen((const char*)cmd);

    printf("Send %d: %s\n", (int)len, (const char*)cmd);

    int wlen = write(fd, cmd, len);

    if (wlen != len) {
        printf("Error from write: %d, %d\n", wlen, errno);
    }
    tcdrain(fd);    /* delay for output */
}

void read_response(int fd)
{
    char buf[256];
    int rlen = read(fd, buf, sizeof(buf) - 1);

    if (rlen > 0) {
#ifdef DISPLAY_STRING
        buf[rlen] = 0;
        printf("Read %d: \"%s\"\n", rlen, buf);
#else /* display hex */
        unsigned char *p;
        printf("Read %d:", rlen);
        for (p = buf; rlen-- > 0; p++)
            printf(" 0x%x", *p);
        printf("\n");
#endif
    } else if (rlen < 0) {
        printf("Error from read: %d: %s\n", rlen, strerror(errno));
    } else {  /* rlen == 0 */
        printf("Timeout from read\n");
    }
}

int main(int argc, char* argv[])
{
    int fd;
    const char portname[] = "/dev/ttyACM0";

    fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
    if (fd < 0) {
        printf("Error opening %s: %s\n", portname, strerror(errno));
        return -1;
    }

    /*baudrate 115200, 8 bits, no parity, 1 stop bit */
    set_interface_attribs(fd, B115200);

    write_command(fd, "ATZ\r", 4); /* Reset */

    read_response(fd);

    write_command(fd, "ATE0\r", -1);  /* Echo off */

    read_response(fd);

    write_command(fd, "AT+VCID=?\r", -1);  /* Query CallerID caps */

    read_response(fd);

    write_command(fd, "AT+CLIP=?\r", -1);  /* Query CallerID caps */

    read_response(fd);

    write_command(fd, "AT+VCID=1\r", -1);  /* Set CallerID */

    read_response(fd);

    printf("Entering loop, CTRL+C to break...\n\n");

    while (1)
    {
        read_response(fd);
    }

    return 0;
}

这是使用手机的测试结果。我更改了姓名和电话号码;否则,它将是程序的确切输出。

$ sudo ./modem.exe
Send 4: ATZ
Read 6: "
OK
"
Send 5: ATE0
Read 11: "ATE0
OK
"
Send 10: AT+VCID=?
Read 15: "
(0-2)

OK
"
Send 10: AT+CLIP=?
Read 9: "
ERROR
"
Send 10: AT+VCID=1
Read 6: "
OK
"

Entering loop, CTRL+C to break...

Read 8: "
RING
"
Read 67: "
DATE = 0214
TIME = 2116
NMBR = 2025551212
NAME = JANE DOE
"
Read 8: "
RING
"
Read 67: "
DATE = 0214
TIME = 2116
NMBR = 2025551212
NAME = JANE DOE
"
Read 8: "
RING
"
Read 8: "
RING
"
Read 8: "
RING
"

此外,您可以发送AT+GSR来获取实际的调制解调器修订版本,而不是Windows提供的版本(这似乎有点不准确):

Send 7: AT+GMR
Read 44: "AT+GMR
+GMR: CX93001-EIS_V0.2013-V92

OK"