3041|7

61

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

WinCE串口程序发送正确,串口上却没有波形 [复制链接]

几乎完全相同的代码,在VC下调试发送接收完全正确
在EVC下调试WinCE就不对
我只把         szBaud.Format("baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits);
         BuildCommDCB(szBaud, &PortDCB);
改成了:
        PortDCB.BaudRate = baud;              // Current baud
       
        PortDCB.Parity = FALSE;//parity;            // 0-4=no,odd,even,mark,space
        PortDCB.ByteSize = databits;                 // Number of bits/bytes, 4-8
        PortDCB.StopBits = stopbits;        // 0,1,2 = 1, 1.5, 2
这一改VC下就SetCommState (m_hPort, &PortDCB)不了了,但是ECV却可以通过,WriteFile也可以执行,但是示波器测没波形
而在PC上用VC是有波形的,请问应该怎么解决?

请看代码
BOOL CMySerialPort::Open(  UINT  portnr,                // portnumber (1..4)
                                                   UINT  baud,                        // baudrate
                                                   char  parity,                // parity
                                                   UINT  databits,                // databits
                                                   UINT  stopbits,                // stopbits
                                                   DWORD dwCommEvents,        // EV_RXCHAR, EV_CTS etc
                                                   UINT  writebuffersize,        // size to the writebuffer
                                                   UINT  readbuffersize)        // size to the readbuffer
{
        DCB PortDCB;
        COMMTIMEOUTS CommTimeouts;
        TCHAR strPortName[15];       
        //CString strPortName;
        //CString szBaud;
        TCHAR szBaud[29];

        Close();

        // Open the serial port.
        //strPortName.Format("COM%d", portnr);
        wsprintf(strPortName, L"COM%d:", portnr);
        /*
        m_hPort = CreateFile (strPortName, // Pointer to the name of the port
                                          GENERIC_READ | GENERIC_WRITE, // Access (read/write) mode
                                          0,            // Share mode
                                          NULL,         // Pointer to the security attribute
                                          OPEN_EXISTING,// How to open the serial port
                                          0,            // Port attributes
                                          NULL);        // Handle to port with attribute
                                                                        // to copy
                                                                        */

                m_hPort = CreateFile(
                strPortName,
                GENERIC_READ | GENERIC_WRITE,        //允许读和写
                0,                                                                //独占方式(共享模式)
                NULL,
                OPEN_EXISTING,                                        //打开而不是创建(创建方式)
                0,
                NULL
                );

        // If it fails to open the port, return FALSE.
        if ( m_hPort == INVALID_HANDLE_VALUE )
        {               
         return FALSE;
        }

        PortDCB.DCBlength = sizeof (DCB);     

          // Get the default port setting information.
          
        if (!GetCommState (m_hPort, &PortDCB))
        {       
                return FALSE;
        }
               
         //szBaud.Format("baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits);
/*
        wsprintf(szBaud, L"baud=%d parity=%c data=%d stop=%d", baud, parity, databits, stopbits);
         if(!BuildCommDCB(szBaud, &PortDCB))
                 AfxMessageBox(L"sk");
*/

        // Change the DCB structure settings.

        PortDCB.BaudRate = baud;              // Current baud
       
        PortDCB.Parity = FALSE;//parity;            // 0-4=no,odd,even,mark,space
        PortDCB.ByteSize = databits;                 // Number of bits/bytes, 4-8
        PortDCB.StopBits = stopbits;        // 0,1,2 = 1, 1.5, 2


        PortDCB.fBinary = TRUE;               // Binary mode; no EOF check
        PortDCB.fParity = TRUE;               // Enable parity checking.  
        PortDCB.fOutxCtsFlow = FALSE;         // No CTS output flow control
        PortDCB.fOutxDsrFlow = FALSE;         // No DSR output flow control

        PortDCB.fDtrControl = DTR_CONTROL_ENABLE;  // DTR flow control type
        PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity
        PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx
        PortDCB.fOutX = FALSE;                // No XON/XOFF out flow control
        PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control
        PortDCB.fErrorChar = FALSE;           // Disable error replacement.
        PortDCB.fNull = FALSE;                // Disable null stripping.
        PortDCB.fRtsControl = RTS_CONTROL_ENABLE;  // RTS flow control
        PortDCB.fAbortOnError = FALSE;        // Do not abort reads/writes on
                                                                                // error.

        if (!SetCommState (m_hPort, &PortDCB))
        {               
        return FALSE;
        }

        // Retrieve the time-out parameters for all read and write operations
        // on the port.
        GetCommTimeouts (m_hPort, &CommTimeouts);

        CommTimeouts.ReadIntervalTimeout = 1000;//MAXDWORD;  
        CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
        CommTimeouts.ReadTotalTimeoutConstant = 0;   
        CommTimeouts.WriteTotalTimeoutMultiplier = 1000;  
        CommTimeouts.WriteTotalTimeoutConstant = 1000;

        if (!SetCommTimeouts (m_hPort, &CommTimeouts))
        {
        return FALSE;
        }

        SetCommMask(m_hPort, dwCommEvents);
        // Direct the port to perform extended functions SETDTR and SETRTS.
        // SETDTR: Sends the DTR (data-terminal-ready) signal.
        // SETRTS: Sends the RTS (request-to-send) signal.
        EscapeCommFunction (m_hPort, SETDTR);
        EscapeCommFunction (m_hPort, SETRTS);

        return TRUE;
}

最新回复

连一个懂RS232的人都没有吗? 是CST没接地!  详情 回复 发表于 2008-11-25 09:15
点赞 关注

回复
举报

73

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
还处在奥运兴奋期,
没有情绪看这么长的代码啊。

先问一下,你的确收到数据了吗?
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
LS,LZ只说了发送正确,可没有说接收到数据。
如果接收到数据,且没有波形的话,这就奇怪了。其实也可能不奇怪,因为测量串口波形的方式搞错了,呵呵~

发送的代码呢?可能是这里出错了。
 
 
 

回复

53

帖子

0

TA的资源

一粒金砂(初级)

4
 

对啊,
你修改代码的时候有没有把unicode全部转换啊?
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

5
 
呵呵,如果接收到数据了,但是没有波形,那很可能就是接触不良了。。。。
 
 
 

回复

57

帖子

0

TA的资源

一粒金砂(初级)

6
 
我在电脑上用串口调试器的确正确地接到了ARM上WinCE程序发送的数据
但是WinCE接到的PC发回来的数据只有第一个字节是正确的,后面是乱的
是不是波特率不准的问题?
怎么解决?
 
 
 

回复

45

帖子

0

TA的资源

一粒金砂(初级)

7
 
串口发送需要ASNII,不能使用Unicode
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

8
 
连一个懂RS232的人都没有吗?
是CST没接地!
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
有奖直播报名| TI 面向楼宇和工厂自动化行业的毫米波雷达解决方案
【内容简介】TI 60GHz IWRL6432和 IWRL1432毫米波雷达传感器如何帮助解决楼宇和工厂自动化应用中的感应难题
【直播时间】5月28日(周三)上午10:00
【直播礼品】小米双肩包、contigo水杯、胶囊伞、安克充电器

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网 4

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表