欢迎来到天天文库
浏览记录
ID:51496768
大小:2.11 MB
页数:33页
时间:2020-03-25
《SCL及DLL上位机编程应用实例培训教材.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、上海安浦鸣志自动化设备有限公司ConfidentialSCL上位机编程概述编程示例C++VBC#DLL介绍Q/AConfidentialSCL语言(Serial/StreamCommandLanguage)请求和应答均以回车符'r'作为结尾VB:"CC"&VBCRC/C#:"CCr"Confidential通讯速率每字节所需时间=1/(波特率/(起始位+数据位+停止位))波特率9600192003840057600115200每字节所需时间(ms)1.040.520.260.170.087发送一条指令并接收到响应所需的时间总字
2、节数=地址+指令+参数+CheckSum+'r'例:1FL200000{XX+回车影响数据接收时间的因素数据发送DSP处理数据接收操作系统调度ConfidentialSCLUtility(只支持COM1~COM16)SCLUtility2(开发中)串口调试助手(只支持COM1~COM4)AccessPort(前台+后台)BusHound(后台监控)Confidential设置基本参数(端口、波特率、数据位等)打开端口发送数据接收数据关闭端口Confidential引用MSComm控件WindowsAPI使用第三方SerialPo
3、rt类Confidential/*Module:SerialPort.HPurpose:InterfaceforanMFCwrapperclassforserialportsCopyright(c)1999-2013byPJNaughter.Allrightsreserved.Copyright/UsageDetails:Youareallowedtoincludethesourcecodeinanyproduct(commercial,shareware,freewareorotherwise)whenyourproductis
4、releasedinbinaryform.Youareallowedtomodifythesourcecodeinanywayyouwantexceptyoucannotmodifythecopyrightdetailsatthetopofeachmodule.Ifyouwanttodistributesourcecodewithyourapplication,thenyouareonlyallowedtodistributeversionsreleasedbytheauthor.Thisistomaintainasingledi
5、stributionpointforthesourcecode.*/ConfidentialOpen打开端口Close关闭端口IsOpen如果端口已经打开,返回true,否则返回falseRead读取数据Write写入数据ConfidentialvoidCVCSampleDlg::SendCommand(CStringstrCommand){if(m_IsOpen==false){return;}CStringcommand=strCommand;if(command[command.GetLength()-1]!='r'){c
6、ommand+='r';}LPTSTRlptCommand=newTCHAR[command.GetLength()+1];strcpy(lptCommand,command);m_SerialPort.Write(lptCommand,command.GetLength());}Confidentialwhile(true){intcount=m_SerialPort.Read(lpbuf,1);if(count>0){for(inti=0;i7、te+=count;}newTickCount=::GetTickCount();if((newTickCount-oldTickCount)>(UINT)nTimeOut){break;}}ConfidentialConfidentialCStringstr;str.Format("JS%.3f",m_JogVelocity);ExecuteCommand(str);str.Format("JA%.3f",m_JogAccel);ExecuteCommand(str);str.Format("JL%.3f",m_JogDecel8、);ExecuteCommand(str);if(pMsg->hwnd==((CButton*)this->GetDlgItem(IDC_BTN_CWJOG))->m_hWnd){ExecuteCommand(_T("DI1"));ExecuteC
7、te+=count;}newTickCount=::GetTickCount();if((newTickCount-oldTickCount)>(UINT)nTimeOut){break;}}ConfidentialConfidentialCStringstr;str.Format("JS%.3f",m_JogVelocity);ExecuteCommand(str);str.Format("JA%.3f",m_JogAccel);ExecuteCommand(str);str.Format("JL%.3f",m_JogDecel
8、);ExecuteCommand(str);if(pMsg->hwnd==((CButton*)this->GetDlgItem(IDC_BTN_CWJOG))->m_hWnd){ExecuteCommand(_T("DI1"));ExecuteC
此文档下载收益归作者所有