Reading Data from Serial Port
Reading Data from Serial Port
(OP)
Hey,
I'm pretty new at VB and programming in general, but I don't think my question is too hard of one.
I want to be able to receive data from a serial port and write that data to a text file until I either tell it to stop or the connection is gone. Now I've never programmed anything to read data from an outside source so this is new ground for me.
So, any help as far as structure and code goes would be greatly appreciated.
Thanks!
I'm pretty new at VB and programming in general, but I don't think my question is too hard of one.
I want to be able to receive data from a serial port and write that data to a text file until I either tell it to stop or the connection is gone. Now I've never programmed anything to read data from an outside source so this is new ground for me.
So, any help as far as structure and code goes would be greatly appreciated.
Thanks!
RE: Reading Data from Serial Port
Private Sub cmdClose_Click()
MSComm1.PortOpen = False
lblStatus.Caption = "Closed"
lblStatus.ForeColor = &HFF&
End Sub
Private Sub cmdOpen_Click()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
lblStatus.Caption = "Open"
lblStatus.ForeColor = &HC000&
End Sub
Private Sub cmdReceive_Click()
Dim Data As Variant
Do
DoEvents
Loop Until MSComm1.InBufferCount > 0
Data = MSComm1.Input
Open "C:\Data.txt" For Append As #1
Write #1, Data
Close #1
End Sub
RE: Reading Data from Serial Port
Private Sub cmdReceive_Click()
Dim Data As Variant
Do
Data = MSComm1.Input
Open "C:\Data.txt" For Append As #1
Write #1, Data
Close #1
Loop Until MSComm1.InBufferCount = 0 'As long as there is data in the buffer OR Returns 0 if user clicks "Close Port"
End Sub
RE: Reading Data from Serial Port
Can you test it with a null modem and a laptop?