以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 关于串口通信 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=56288) |
-- 作者:2lg -- 发布时间:2014/9/2 16:28:00 -- 关于串口通信 原VB代码定义如下: MSComm1.CommPort = 1 If MSComm1.PortOpen = True Then MSComm1.PortOpen = False MSComm1.InputMode = comInputModeBinary MSComm1.PortOpen = True MSComm1.RThreshold = 12 MSComm1.InputMode = comInputModeBinary \'启用称重端口 Private Sub ChengzhongON_Click() Dim bufr$, weight$ Dim inbyte() As Byte Dim k As Integer If MSComm1.PortOpen = False Then MSComm1.PortOpen = True Exit Sub End If inbyte = MSComm1.Input For k = LBound(inbyte) To UBound(inbyte) bufr = bufr + Hex(inbyte(k)) + Chr(32) Next k Text6.Text = bufr + Chr(13) + Chr(10) Text1.Text = weight End Sub Private Sub MSComm1_OnComm() Dim J As Integer Dim bufra$, weighta$ Dim inbytea() As Byte Select Case MSComm1.CommEvent Case comEvReceive inbytea = MSComm1.Input weighta = Chr("&H" & Hex(inbytea(2))) & Chr("&H" & Hex(inbytea(3))) & Chr("&H" & Hex (inbytea(4))) & Chr("&H" & Hex(inbytea(5))) & Chr("&H" & Hex(inbytea(6))) & Chr("&H" & Hex (inbytea(7))) & Chr("&H" & Hex(inbytea(8))) & " " For J = LBound(inbytea) To UBound(inbytea) bufra = bufra + Hex(inbytea(J)) + Chr(32) Next J Text1.Text = weighta Text6.Text = Chr(13) + Chr(10) + bufra \'vbCrLf End Select End Sub 请教 一下foxtable 里面如何定义端口 Ports.Add("COM1") With Ports("COM1") .Close() .Encoding = Encoding.ASCII .Parity = Parity.None .Handshake = Handshake.None .StopBits = StopBits.One .BaudRate = 9600 .DataBits = 8 .ReadBufferSize() = 4096 .WriteBufferSize() = 2048 .Open End With |
-- 作者:有点甜 -- 发布时间:2014/9/2 16:37:00 -- 你开启端口,直接读取即可。
http://www.foxtable.com/help/topics/1967.htm
http://www.foxtable.com/help/topics/1979.htm
|
-- 作者:2lg -- 发布时间:2014/9/2 16:52:00 -- 谢谢楼上的,还想问一下读取的数据是否还要按VB6的做法进行数据转换啊? |
-- 作者:有点甜 -- 发布时间:2014/9/2 16:55:00 -- 你按照说明书规则,去读取信息,如果不知道怎么读取,你也可以照抄例子的代码,改成vb.net的代码在foxtable里面使用 |