labwindowscvi串行口通信和網絡數據傳輸_第1頁
labwindowscvi串行口通信和網絡數據傳輸_第2頁
labwindowscvi串行口通信和網絡數據傳輸_第3頁
labwindowscvi串行口通信和網絡數據傳輸_第4頁
labwindowscvi串行口通信和網絡數據傳輸_第5頁
已閱讀5頁,還剩6頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

LabWindows/CVI教程(6)串行口和網絡通訊主講:喬立巖Email:qiaoliyan@(交作業)

MSN:qiaoliyan@(在線交流)Tel:86413532ext.8611(逸夫樓611)5/19/2023串行口通訊RS-232端口定義載波檢測接收數據發送數據數據終端就緒信號地數據裝置就緒請求發送清除發送振鈴指示1234567895/19/2023數據傳輸格式電氣特性負邏輯:1=-5V~-15V,0=+5V~+15V最高速率:20kbit/s最遠距離:15m起始位奇偶校驗位停止位ASCII碼5/19/2023打開配置和關閉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);5/19/2023狀態查詢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);5/19/2023網絡通訊TCP協議(TransmissionControlProtocol傳輸控制協議)使用TCP進行網絡通信時每個連接包括一個服務器和一個客戶。TCP服務器能通過網絡向客戶應用程序發送數據或從客戶應用程序接收數據,客戶應用程序也可以向服務器應用程序發送數據或從服務器應用程序接收數據;TCP服務器應用程序一旦向系統注冊,就等待客戶應用程序的連接請求;而客戶應用程序只能向已經存在的服務器應用程序請求連接。每個TCP服務器需要主機名(如:aaa.bbb.ccc)或主機IP地址(如:123.456.78.90)和這個主機的唯一端口號5/19/2023服務器函數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);5/19/2023intServerTCPWrite(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_DATAREADY5/19/2023intDisconnectFromTCPServer(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(unsignedintConnection_Handle,charBuffer[],intBuffer_Size);5/19/2023DataSocketNI公司定義的網絡數據通訊協議DataSocket庫為NI的DataSocket編程提供了支持,也簡化了應用程

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論