原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