public bytreceivebyte() as byte
public intreceivelen as integer
public intput as integer
public strset as string
public inttime as integer
public blnautosendflag as boolean
public blnreceiveflag as boolean
public intoutmode as integer
public strsend as string
public bytsendbyte() as byte
public bytinput() as byte
public recopy as integer
'發準備送模組
private sub cmdsend_click()
if txtsend.text = "" then
list1.additem "傳送緩衝區無資料"
exit sub
end if
frmmain.ctrmscomm.output = txtsend.text '寫入位元組
end sub
'關閉模組
private sub cmdquit_click()
unload me
end sub
'串列埠初始化
private sub form_load()
ctrmscomm.commport = 1
ctrmscomm.settings = "9600,n,8,1"
ctrmscomm.inputlen = 0
'埠開啟
ctrmscomm.portopen = true
ctrmscomm.rthreshold = 1
ctrmscomm.sthreshold = 1
end sub
'激發mscomm控制項的oncomm事件,進行傳送
private sub ctrmscomm_oncomm()
select case ctrmscomm.commevent
case comevreceive
'接受緩衝區裡有字元的處理,即收到外來字元便顯示
dim intinputlen as integer
if blnreceiveflag then
if not frmmain.ctrmscomm.portopen then
frmmain.ctrmscomm.commport = intport
frmmain.ctrmscomm.settings = strset
frmmain.ctrmscomm.portopen = true
end if
end if
frmmain.ctrmscomm.inputmode = cominputmodebinary
intinputlen = frmmain.ctrmscomm.inbuffercount
redim bytinput(intinputlen)
bytinput = frmmain.ctrmscomm.input
call inputmanage(bytinput, intinputlen)
case comevsend
'傳送緩衝區裡字元,顯示有字元
list1.additem "傳送緩衝區有資料"
end select
end sub
'文字寫入,儲存的處理
public sub inputmanage(bytinput() as byte, intinputlenth as integer)
dim n as integer
redim preserve bytreceivebyte(intreceivelen + intinputlenth)
for n = 1 to intinputlenth
bytreceivebyte(intreceivelen + n - 1) = bytinput(n - 1)
next n
intreceivelen = intreceivelen + intinputlenth
recopy = intinputlenth - 1
call display
end sub
'文字顯示的處理
public sub display()
dim i as integer
for i = 0 to recopy
txtreceive.text = txtreceive.text & chr(bytinput(i))
next i
end sub
串列埠通訊 RS232與RS485互連
rs232與rs485通訊 rs485只有a b或 腳兩個引腳時 485gnd只用來遮蔽,不參與通訊 單向傳送時 單工 只接一根線就可以 1.rs232傳送時 pin3腳接485的b腳 2.rs485傳送時 pin2腳接485的b腳。雙向傳送時 半雙工 將232端的p2 3腳短接後與485的b腳 只...
RS232串列埠通訊詳解
rs232串列埠通訊詳解 引腳定義,電氣特性,傳輸格式,接收過程,微控制器晶振,rs485,rs422 轉 2010 03 13 15 47 串列埠是計算機上一種非常通用的裝置通訊協議。串列埠的引腳定義 9芯訊號方向來自 縮寫描述 1數據機 cd載波檢測 2數據機 rxd接收資料3pc txd傳送資...
RS232串列埠通訊模組
應為工作需要自己編寫的rs232通訊模組,該模組已經編寫了蠻久,在實際使用中可能有沒有考慮和不完善的地方。如果使用該模組請保留該注釋,如果被修改或編輯請將修改後的 傳送乙份給我 編寫 戴琪英 e mail qiyingdai 163.com 2000 09 01 unit r232comm inte...