Serial Comms
Serial Comms
(OP)
Hi,
I am looking at using access (using VBA) to recieve a text file from a data logger though the serial port.
In the past I have created a program using MSCOMM to recieve data from a bar code scanner, but the amount of data was small and im unsure how it would cope with a large amount of data.
I basically used a timer that checked the buffer, if it wasn't empty then it recieved the data into a function that used the data. But how big is the buffer etc?
The code is used was:-
If mscomm1.InBufferCount >= 1 Then
wait
found (mscomm1.Input)
End If
Anybody got any ideas?
Thanks
Ben
I am looking at using access (using VBA) to recieve a text file from a data logger though the serial port.
In the past I have created a program using MSCOMM to recieve data from a bar code scanner, but the amount of data was small and im unsure how it would cope with a large amount of data.
I basically used a timer that checked the buffer, if it wasn't empty then it recieved the data into a function that used the data. But how big is the buffer etc?
The code is used was:-
If mscomm1.InBufferCount >= 1 Then
wait
found (mscomm1.Input)
End If
Anybody got any ideas?
Thanks
Ben





RE: Serial Comms
Try something like these examples. You must trigger for individual sources. First see if you can get data to write to a file your ocx creates.
You will have to customize with your own variables in place of "DATA". These may not be functional as is and need to be massaged for your application. As far as the buffer size I'm not sure, maybe in hardware properties. It will help to keep data organized if you identify and write individual files created for each source. I'm no expert here but these examples have helped me in the past. Good Luck
Private Sub Timer1_Timer()
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
If ReadData1 Then
If MSComm1.InBufferCount >= 1 Then
temp_data1 = MSComm1.Input
lastword1 = temp_data1 Returns "Data"
Open "c:\Data1" For Output As #1
Print #1, "Data,Data1"
Print #1, "Data1," + lastword1
Close #1
End If
MSComm3.InputLen = 0
End If
End Sub
OR....
Private Sub Timer1_Timer()
If SAVEDATA Then
Dim Fso As New FileSystemObject
JULIANDATE = Format(Date, "Y")
JULIANDATE3 = Format(JULIANDATE, "000")
If Not Fso.FolderExists("c:\data") Then
Fso.CreateFolder "c:\data\"
End If
If Not Fso.FolderExists("c:\data\" & DATA & "\") Then
Fso.CreateFolder "c:\data\" & DATA & "\"
End If
FileName = "c:\data\" & Date & ".csv"
If Not Fso.FileExists(FileName) Then
Open FileName For Append As #1
Print #1, "Time, DATA,"
Close #1
End If
Open FileName For Append As #1
Print #1, JULIANDATE & "," & JULISNDATE3 & "," & Time & "," & DATA
Close #1
Set Fso = Nothing
End If
End Sub
RE: Serial Comms
What you did with a Timer is called hardware-polling. Another approach is to use interrupts. In VB it is done using "events". Investigate about "OnComm" event in MSComm control. There are examples in MSDN.
Yeasir Rahul
www.voltsmith.com
Yeasir Rahul
http://www.voltsmith.com