|
-
Jul 25th, 2012, 04:44 AM
#1
Thread Starter
Junior Member
[RESOLVED] MSCOMM and Database Connectivity
I have two AIS Systems connected on serial ports of a computer. I want to combine the output of both systems and want to send to a single serial port. For combining the output, I am sending the incoming serial data of both AIS to MS Access database. Baud rate of AIS is 38400. Data is coming very fast.
I am receiving the data from serial port and then on Timer event I am sending it to the database by spliting the strings line by line. But I am receiving the broken strings in database may be due to time missmatch of timer and MSCOMM receive event.
Then I cut the database connectivity code from timer event and pasted it into MSCOMM receive event. But the problem is still there. My code of mscomm receive event and timer event is as follows:
I tested the program by changing the time of timer. e.g 50 ms,100 ms, 500 ms,1000 ms.
Private Sub MSComm1_OnComm()
Case comEvReceive
Buffer = MSComm1.Input
Text1.Text = Text1.Text & Buffer
Text1.SelStart = Len(Text1.Text)
Timeout = Now() + 1 / 86400# '
Timer1.Enabled = True '
Exit Sub
End Select
End Sub
Private Sub Timer1_Timer()
'----------Database Connectivity----------
Dim pos As Integer
Dim entry() As String
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\DB.mdb"
entry = Split(Buffer, vbCrLf, , vbTextCompare)
pos = 0
Do While pos < UBound(entry)
If Trim$(entry(pos)) <> "" Then
cn.Execute ("insert into ais_data (data) Values ('" & entry(pos) & "')")
End If
pos = pos + 1
Loop
cn.Close
Buffer = "" 'delete the buffer
Timer1.Enabled = False 'turn off the timer
End Sub
After deleting Timer code I am receiving the data and sending it to database like this:
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
'Capture any incoming data and write it to the output box.
Case comEvReceive
Buffer = MSComm1.Input
'----------Database Connectivity----------
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "Database\DB.mdb"
entry = Split(Buffer, vbCrLf, , vbTextCompare)
pos = 0
Do While pos < UBound(entry)
If Trim$(entry(pos)) <> "" Then
cn.Execute ("insert into ais_data (data) Values ('" & entry(pos) & "')")
End If
pos = pos + 1
Loop
cn.Close
Buffer = "" 'delete the buffer
End Select
End Sub
The normal AIS String is something like that
$PSHI,001,32.53823999,,02129,33591,113432.28,2,1220,-073*3B
!AIVDM,1,1,,A,B7P>o@002RUlU8rUV<b13wi5oP06,0*19
$PSHI,001,32.58856534,,04626,30936,113432.31,2,1222,-086*35
!AIVDM,1,1,,B,17OfAD5P0B:GF`abEgS<iww20000,0*56
$PSHI,001,32.66856502,,04622,30770,113432.35,2,1225,-086*36
!AIVDM,1,1,,B,17OfAD5P0B:GF`abEgS<iww20000,0*5
!AIVDM,1,1,,B,17OfAD5P0B:GF`abEgS<iww20000,0*6
$PSHI,001,32.66856502,,04622,30770,113432.35,2,1225,-086*36
!AIVDM,1,1,,A,B7P>o@002RUlU8rUV<b13wi5oP06,0*19
$PSHI,001,32.58856534,,04626,30936,113432.31,2,1222,-086*35
$PSHI,001,32.66856502,,04622,30770,113432.35,2,1225,-086*36
!AIVDM,1,1,,B,17OfAD5P0B:GF`abEgS<iww20000,0*6
$PSHI,001,32.66856502,,04622,30770,113432.35,2,1225,-086*36
But in databse I am receiving something like this
5119409,,03598,24855,034722.21,0,1685*0B
VDM,1,1,,B,18154n001m4>Fpn=f1E93GCb0HNm,0*64
,0,1794*03
fk1b2`P?,0*5A
Please give me some expert opinion to resolve this problem. I will be very thankful to you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|