Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Go Back  Xtreme Visual Basic Talk > > > Stuck in serial communication with Fire Alarm System


Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2010, 12:21 PM
albertleng albertleng is offline
Regular
 
Join Date: Aug 2006
Posts: 79
Default Stuck in serial communication with Fire Alarm System


Hi all. I'm writing a program which is connected to Fire Alarm System via serial port. The Fire Alarm System will send me data like shown below. I also attach a screenshot of the data from FAS received in Hyper Terminal.

COMMON TRBL RST :: 22:18:50 16/06/2010 P:06 C:02 D:0137
Z6-4-9_BV_CLOSED 4S Corridor

COMMON TRBL ACT :: 22:18:50 16/06/2010 P:06 C:02 D:0137
Z6-4-9_BV_CLOSED 4S Corridor

My program needs to send "0" or "1" via DDE to another program based on the FAS message. Referring to the above message and the screenshot,
"COMMON TRBL RST" is the message to reset an alarm, "COMMON TRBL ACT" is the message to activate an alarm and "D:0137" is the locationID.
My program needs to send the status via DDE based on the "... RST" or "...ACT" message and the locationID.

Upon startup, my program will read from a config file for the available ACT message, RST message and a list of locationIDs.

I am encountering a few issues:
1) In my MSCOMM1_OnComm event, using breakpoint, i notice that my program always receives just the portion of the FAS message, for e.g., I'll receive only "COM" at one time and then, I press F5 to carry on. Next time, I'll receive another portion of the whole chunk like "MON TRBL RST... ...". Because of this, i can't capture any alarm ACT or alarm RST at all. How can i ensure i don't lose any data from FAS?

2) If I can solve the first issue, please suggest to me the most efficient way to process the chunk of data received by my program.

Below are my code. Please help.
Private Sub MSComm1_OnComm()
Static strBuffer As String
Dim strData As String
Dim normalLocation1 As Integer
Dim alarmLocation1 As Integer
Dim normalLocation2 As Integer
Dim alarmLocation2 As Integer
Dim normalLocation3 As Integer
Dim alarmLocation3 As Integer
Dim normalLocation As Integer
Dim alarmLocation As Integer
Dim normalMsg As String
Dim alarmMsg As String
Dim finalNormalLocation As Integer
Dim finalAlarmLocation As Integer
Dim pointIndex As Integer
Dim i As Integer
Dim j As Integer



Select Case MSComm1.CommEvent
Case comEvReceive
strData = MSComm1.Input
strBuffer = strBuffer & strData

tTerminal.Text = tTerminal.Text & strBuffer

//This is the part where i put breakpoint and notice that my program keeps receiving only part of the FAS message.
If Len(tTerminal.Text) > (Len(normalMsg1) + 1) Then

//normalMsg1, normalMsg2, normalMsg3, alarmMsg1, alarmMsg2 and alarmMsg3 are the possible Alarm ACT and RST messages
//defined in the config files.
For i = 1 To Len(tTerminal.Text)
normalLocation1 = InStr(i, Mid$(tTerminal.Text, i, Len(normalMsg1) + 1), normalMsg1)
alarmLocation1 = InStr(i, Mid$(tTerminal.Text, i, Len(alarmMsg1) + 1), alarmMsg1)

If normalMsg2 <> "" Then
normalLocation2 = InStr(i, Mid$(tTerminal.Text, i, Len(normalMsg2) + 1), normalMsg2)
Else
normalLocation2 = 0
End If

If alarmMsg2 <> "" Then
alarmLocation2 = InStr(i, Mid$(tTerminal.Text, i, Len(alarmMsg2) + 1), alarmMsg2)
Else
alarmLocation2 = 0
End If

If normalMsg3 <> "" Then
normalLocation3 = InStr(i, Mid$(tTerminal.Text, i, Len(normalMsg3) + 1), normalMsg3)
Else
normalLocation3 = 0
End If

If alarmMsg3 <> "" Then
alarmLocation3 = InStr(i, Mid$(tTerminal.Text, i, Len(alarmMsg3) + 1), alarmMsg3)
Else
alarmLocation3 = 0
End If


//FindSmallest is a method i wrote to find the smallest number of the 3 numbers
normalLocation = FindSmallest(normalLocation1, normalLocation2, normalLocation3)

If normalLocation <> 0 Then
If normalLocation1 = normalLocation Then
normalMsg = normalMsg1
ElseIf normalLocation2 = normalLocation Then
normalMsg = normalMsg2
ElseIf normalLocation3 = normalLocation Then
normalMsg = normalMsg3
End If
End If

alarmLocation = FindSmallest(alarmLocation1, alarmLocation2, alarmLocation3)
If alarmLocation <> 0 Then
If alarmLocation1 = alarmLocation Then
alarmMsg = alarmMsg1
ElseIf alarmLocation2 = alarmLocation Then
alarmMsg = alarmMsg2
ElseIf alarmLocation3 = alarmLocation Then
alarmMsg = alarmMsg3
End If
End If

//totalPoint is the total venues/LocationIDs
For j = 1 To totalPoint
If alarmLocation <> 0 Then
//Send 1 via DDE to a program if point j is an alarm
If InStr(strBuffer, PointAddress(j)) > 0 Then
txtPoint(j).Text = "1"
txtPoint(j).LinkMode = vbLinkManual
txtPoint(j).LinkPoke
End If
ElseIf normalLocation <> 0 Then
//Send 0 via DDE to a program if point j is an alarm
If InStr(strBuffer, PointAddress(j)) > 0 Then
txtPoint(j).Text = "0"
txtPoint(j).LinkMode = vbLinkManual
txtPoint(j).LinkPoke
End If
Else
Exit For
End If
Next j
Next i
tTerminal.Text = ""
strBuffer = ""
End If
End Select


End Sub
Attached Images
File Type: jpg SampleData.JPG (79.4 KB, 2 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
 
Stuck in serial communication with Fire Alarm System
Stuck in serial communication with Fire Alarm System
 
-->