matanguay
asked on
using vb6 to connect to COM1 to extract data
Hi,
I am currently building an application to get data off a SMDR6 module for my norstar system. the device collects data from my phone system and sends it either to a serial printer or a pc connected via HYPERTERMINAL or similar application.
here is what the output looks like :
N 012 00 DN0221 T026000 09/20 07:17 00:00:11 97767633
N 013 00 T004000 DN0257 09/20 07:17 00:00:03
N 014 00 DN0221 T002000 09/20 07:17 00:00:41
N 015 00 DN0221 T001000 09/20 07:17 00:00:45
I currently use HYPER TERMINAL with screen capture to get the data in excel, and then to be processed in my software, but I would like to build a all included software that would do it all. I checked on EE a little on how to connect with a serial port, and this is what I came up with :
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
Private Sub Form_Load()
' Configure the serial port
With MSComm1
' .Settings = "2400,n,8,1"
' Number of COM port (this COM1)
' .CommPort = 3
' Open the port
.PortOpen = True
.DTREnable = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.DTREnable = False
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
MsgBox "got it"
' Print what you received to the serial port
List1.AddItem MSComm1.Input
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
it works partly as I can force it to get data with this :
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 2
' Read the "OK" response data in the serial port.
tempinput = MSComm1.Input
but I saw in the MSCOMM that I should be able to use the ONCOMM() function instead of having to pull myself .. since the data comes in batch it is easiser to have a ONCOMM function.
please advise on how to use this function if i am not using it right.
thanks
I am currently building an application to get data off a SMDR6 module for my norstar system. the device collects data from my phone system and sends it either to a serial printer or a pc connected via HYPERTERMINAL or similar application.
here is what the output looks like :
N 012 00 DN0221 T026000 09/20 07:17 00:00:11 97767633
N 013 00 T004000 DN0257 09/20 07:17 00:00:03
N 014 00 DN0221 T002000 09/20 07:17 00:00:41
N 015 00 DN0221 T001000 09/20 07:17 00:00:45
I currently use HYPER TERMINAL with screen capture to get the data in excel, and then to be processed in my software, but I would like to build a all included software that would do it all. I checked on EE a little on how to connect with a serial port, and this is what I came up with :
--------------------------
Private Sub Form_Load()
' Configure the serial port
With MSComm1
' .Settings = "2400,n,8,1"
' Number of COM port (this COM1)
' .CommPort = 3
' Open the port
.PortOpen = True
.DTREnable = True
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
MSComm1.DTREnable = False
MSComm1.PortOpen = False
End Sub
Private Sub MSComm1_OnComm()
MsgBox "got it"
' Print what you received to the serial port
List1.AddItem MSComm1.Input
End Sub
--------------------------
it works partly as I can force it to get data with this :
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 2
' Read the "OK" response data in the serial port.
tempinput = MSComm1.Input
but I saw in the MSCOMM that I should be able to use the ONCOMM() function instead of having to pull myself .. since the data comes in batch it is easiser to have a ONCOMM function.
please advise on how to use this function if i am not using it right.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
now it seems to work partly. I can receive some data at load, then after a few seconds all I receive is blank lines. I tried right after with my HYPER TERMINAL software and it worked fine and received data.