labwindowscvi6第七章串行口通信和网络数据传输_第1页
labwindowscvi6第七章串行口通信和网络数据传输_第2页
labwindowscvi6第七章串行口通信和网络数据传输_第3页
labwindowscvi6第七章串行口通信和网络数据传输_第4页
labwindowscvi6第七章串行口通信和网络数据传输_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

10一月2025labwindowscvi6第七章串行口通信和网络数据传输串行口通讯RS-232端口定义载波检测接收数据发送数据数据终端就绪信号地数据装置就绪请求发送清除发送振铃指示1234567891/10/2025数据传输格式电气特性负逻辑:1=-5V~-15V,0=+5V~+15V最高速率:20kbit/s最远距离:15m起始位奇偶校验位停止位ASCII码1/10/2025打开配置和关闭intOpenComConfig(intCOM_Port,charDevice_Name[],longBaud_Rate,intParity,intData_Bits,intStop_Bits,intInput_Queue_Size,intOutput_Queue_Size);i=OpenComConfig(1,“”,14400,0,7,1,512,512);intCloseCom(intCOM_Port);i=CloseCom(1);读写intComRd(intCOM_Port,charBuffer[],intCount);i=ComRd(1,buf,128);intComWrt(intCOM_Port,charBuffer[],intCount);i=ComWrt(1,buf,128);intComRdByte(intCOM_Port);intComWrtByte(intCOM_Port,intByte);控制intFlushInQ(intCOM_Port);intFlushOutQ(intCOM_Port);1/10/2025状态查询intGetInQLen(intCOM_Port);i=GetInQLen(1);intGetOutQLen(intCOM_Port);i=GetOutQLen(1);事件处理intInstallComCallback(intCOM_Port,intEvent_Mask,intNotify_Count,intEvent_Character,ComCallbackPtrCallback_Function,void*Callback_Data);

notifyCount=50;//Waitforatleast50bytesinqueueeventChar=13;//WaitforLFeventMask=LWRS_RXFLAG|LWRS_RECEIVE;InstallComCallback(comport,eventMask,notifyCount,eventChar,ComCallbackFunction,NULL);1/10/2025网络通讯TCP协议(TransmissionControlProtocol传输控制协议)使用TCP进行网络通信时每个连接包括一个服务器和一个客户。TCP服务器能通过网络向客户应用程序发送数据或从客户应用程序接收数据,客户应用程序也可以向服务器应用程序发送数据或从服务器应用程序接收数据;TCP服务器应用程序一旦向系统注册,就等待客户应用程序的连接请求;而客户应用程序只能向已经存在的服务器应用程序请求连接。每个TCP服务器需要主机名(如:aaa.bbb.ccc)或主机IP地址(如:123.456.78.90)和这个主机的唯一端口号1/10/2025服务器函数intRegisterTCPServer(unsignedintPort_Number,tcpFuncPtrCallback_Function,void*Callback_Data);i=RegisterTCPServer(200,ServerTCPCB,0);回调函数:int(*tcpFuncPtr)(unsignedhandle,intxType,interrCode,void*callbackData);TCP_CONNECTTCP_DISCONNECTTCP_DATAREADYintCVICALLBACKServerTCPCB(unsignedhandle,intevent,interror,void*callbackData);intUnregisterTCPServer(unsignedintPort_Number);intServerTCPRead(unsignedintConversation_Handle,void*Data_Buffer,unsignedintData_Size,unsignedintTime_Out);dataSize=ServerTCPRead(g_hconversation,receiveBuf,dataSize,1000);1/10/2025intServerTCPWrite(unsignedintConversation_Handle,void*Data_Pointer,unsignedintData_Size,unsignedintTime_Out);i=ServerTCPWrite(g_hconversation,transmitBuf,strlen(transmitBuf)+1,1000);intDisconnectTCPClient(unsignedintConversation_Handle);客户机函数intConnectToTCPServer(unsignedint*Conversation_Handle,unsignedintPort_Number,charServer_Host_Name[],tcpFuncPtrCallback_Function,void*Callback_Data,unsignedintTime_Out);i=ConnectToTCPServer(&g_hconversation,200,tempBuf,ClientTCPCB,NULL,5000);回调函数:int(*tcpFuncPtr)(unsignedhandle,intxType,interrCode,void*callbackData);intCVICALLBACKClientTCPCB(unsignedhandle,intevent,interror,void*callbackData);TCP_DISCONNECTTCP_DATAREADY1/10/2025intDisconnectFromTCPServer(unsignedintConversation_Handle);intClientTCPRead(unsignedintConversation_Handle,void*Data_Buffer,unsignedintData_Size,unsignedintTime_Out);i=ClientTCPRead(g_hconversation,receiveBuf,dataSize,1000);intClientTCPWrite(unsignedintConversation_Handle,void*Data_Pointer,unsignedintData_Size,unsignedintTime_Out);ClientTCPWrite(g_hconversation,transmitBuf,strlen(transmitBuf)+1,1000);支持函数intGetTCPHostAddr(charBuffer[],intBuffer_Size);intGetTCPHostName(charBuffer[],intBuffer_Size);intGetTCPPeerAddr(unsignedintConnection_Handle,charBuffer[],intBuffer_Size);intGetTCPPeerName(uns

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论