<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>
關(guān) 閉

新聞中心

EEPW首頁(yè) > 工控自動(dòng)化 > 設計應用 > 基于VB的PLC與計算機間串行通信實(shí)現

基于VB的PLC與計算機間串行通信實(shí)現

作者: 時(shí)間:2010-11-05 來(lái)源:網(wǎng)絡(luò ) 收藏

 ?。猧nput:將對方傳送至輸入緩沖區的字符讀入到程序。

 ?。猳utput:將字符寫(xiě)入輸出緩沖區。

 ?。猧nbuffercount:傳回接收緩沖區中的字符數。

 ?。猳utbuffercount:傳回輸出緩沖區中的字符數。

 ?。猧nputlen:設定端口讀入字符串的長(cháng)度。

 ?。猧nputmode:設定接收數據的方式。

 ?。猺threshold:設定引發(fā)接收事件的字符數。

 ?。猚ommevent:傳回ONcomm事件發(fā)生時(shí)的數值碼

 ?。猳ncomm事件:無(wú)論是錯誤或事件發(fā)生,都會(huì )觸發(fā)此事件。

 ?。?) 控件參數的初始化

  初始化程序如下:

  mscomm.comport=2 `使用串口com2

  mscomm.settings=9600, e, 7, 2 `波特率9600,偶校驗,7位數據位,2位停止位

  mscomm.portopen=true `打開(kāi)通信端口,準備通信

 ?。?) 計算校驗碼fcs,計算fcs的vb自定義函數如下:

  function fcs(byval inputSTr as string) as string

  dim slen, i, xorresult as integer

  dim tempfes as string

  slen=len(inputstr) `求輸入字符串長(cháng)度

  xorresult = 0

  for i = 1 to slen

  xorresult = xorresult xor asc(mid$(inputstr, i, 1)) `按位異或

  next i

  tempfes=hex$(xorresult) `轉化為16進(jìn)制

  if len(tempfes)=1then tempfes =“0”+tempfes

  fcs = tempfes

  end function

 ?。?) 通信程序

  主要是一個(gè)自定義函數。

  function readdata(byval inputstr as string, byval num as integer) as string

  dim outputstr as string

  dim instring as string

  dim returnstr as string

  dim endstring as string

  dim fcsstring as string

  dim returnfcsstring as string)

  mscomm.inbuffercount=0

  utputstr=inputstr+fcs(inputstr)+“*” `給出命令幀

  mscomm.output=outputstr+chr$(13) `向傳送命令幀

  do

  doevents

  loop while mscomm.inbuffercount 15

  instring=mscomm.input `獲取的響應幀

 ?。嘟Y束碼判斷

  endstring = mid$(instring, len(instring) -

  num- 5, 2)



關(guān)鍵詞: PLC 計算機 串行 通信實(shí)現

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>