发表于:2001/5/17 13:47:00
#0楼
本人用VB编程与FX2N通信软件如下:
可是,不知为何总是PC与FX2N联系不上?
请问高手,问题到底出在哪儿?
Option Explicit
Private STX, ETX, ENQ, ACK, NAK As String
Private Sub Command1_Click()
Dim sd1, sd2, rd, pd, js As String
Dim com As String
Dim Dummy As Variant
If MSComm1.PortOpen = False Then
MSComm1.InBufferSize = 1024
MSComm1.PortOpen = True
End If
sd1 = ENQ & "00FFBR0X000001" + SumChk("00FFBR0X000001")
MSComm1.Output = sd1
Do
Dummy = DoEvents()
Loop Until MSComm1.InBufferCount >= 5
rd = MSComm1.Input
If Mid(rd, 1, 1) = Chr(2) Then
MsgBox "receive ok!"
sd2 = ACK & "00FF"
MSComm1.Output = sd2
MsgBox Mid(rd, 6, Len(rd) - 5)
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
STX = Chr(2)
ETX = Chr(3)
ENQ = Chr(5)
ACK = Chr(6)
NAK = Chr(21)
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,7,1"
Text1.Text = ""
MSComm1.InputLen = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Function SumChk(Dats$) As String
Dim i&
Dim CHK&
For i = 1 To Len(Dats)
CHK = CHK + Asc(Mid(Dats, i, 1))
Next i
SumChk = Right(Hex$(CHK), 2)
End Function
可是,不知为何总是PC与FX2N联系不上?
请问高手,问题到底出在哪儿?
Option Explicit
Private STX, ETX, ENQ, ACK, NAK As String
Private Sub Command1_Click()
Dim sd1, sd2, rd, pd, js As String
Dim com As String
Dim Dummy As Variant
If MSComm1.PortOpen = False Then
MSComm1.InBufferSize = 1024
MSComm1.PortOpen = True
End If
sd1 = ENQ & "00FFBR0X000001" + SumChk("00FFBR0X000001")
MSComm1.Output = sd1
Do
Dummy = DoEvents()
Loop Until MSComm1.InBufferCount >= 5
rd = MSComm1.Input
If Mid(rd, 1, 1) = Chr(2) Then
MsgBox "receive ok!"
sd2 = ACK & "00FF"
MSComm1.Output = sd2
MsgBox Mid(rd, 6, Len(rd) - 5)
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
STX = Chr(2)
ETX = Chr(3)
ENQ = Chr(5)
ACK = Chr(6)
NAK = Chr(21)
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,7,1"
Text1.Text = ""
MSComm1.InputLen = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Function SumChk(Dats$) As String
Dim i&
Dim CHK&
For i = 1 To Len(Dats)
CHK = CHK + Asc(Mid(Dats, i, 1))
Next i
SumChk = Right(Hex$(CHK), 2)
End Function