Solved

Garbled/Truncated String Issue

Posted on 2004-10-25
311 Views
Last Modified: 2010-04-23
I have a vb.net windows service running that loops waiting for data from a hardware device connected to a RS232 communication port. When the information comes in, this communication service adds the new information to a queue. There are also scheduled polling intervals where the service initiates communication to the device and requests the current information. When the information is returned, the information is added to the queue as well. A client can initiate a poll as well, by requesting that the communication service retrieve information from the device.

The updates in the queue are then used to update the database. The client is notified and the communication service continues.

There is also an alarm service that is notified when updates occur and the alarm service is used to decide if an alarm condition has occurred. If an alarm has occurred, the alarm service notifies the client and the client screen notifies the user as needed. The alarm service may also request that the communication service send out a text message to a radio if the alarm condition requires it.

My problem is this:

The string message that is being sent out to the radio is being garbled. The data is either missing data in the middle, or it is sending out garbled data.

For example the message should say "West site pump turned off", but instead it will read "West site pu rned off" or it may say "West *200000West site pump turned off".

I have a similar problem where my database sql string is getting garbled and resulting in a sql error. The string manipulation I am performing is simple and should not result in these issues. The problem occurs with a string as simple as:

Dim sql as string = "Insert into tbTransaction (Data, Status) values " & strData & "," & numStatus & ";"

It is almost as though there are two threads trying to perform the same action and they are messing each other up.

Any thoughts?

Troy

0
Question by:tdyck12345
    8 Comments
     
    LVL 2

    Author Comment

    by:tdyck12345
    One more thing I would like to add is that my program runs fine for hours to days with no problem. Then suddenly just starts misbehaving.

    Troy
    0
     
    LVL 13

    Expert Comment

    by:Corey2
    What if instead of strings you use repeated digits.  Thisway the client can convert the digits to a known string.  Say you have 40 different messages each is identified with a unique number you repeat the number 10 times to the server the server parses the string for a complete number that matches your DB of strings. Vica-Versa.

    Corey
    0
     
    LVL 2

    Author Comment

    by:tdyck12345
    I am not quite sure what you mean. Perhaps you could give an example.

    Also there is no problem with the client. The problem lies totally in the communication server. It is as though the server heap/stack is being corrupted. Is this possible? If so what are reasons for the memory getting corrupted this way?

    Troy
    0
     
    LVL 13

    Expert Comment

    by:Corey2
    I mentioned it because it sounds like you are passing a signal over radio signal.  Radio signals over distance can get choppy especially when you are dealing with concrete walls  basements and such.  So if you have the client send a signal like say "Msg251 Msg251 Msg251 Msg251 Msg251 Msg251 Msg251" Then on the server you have a Collection setup on the server

    Public Messages as Collection

    Sub InitiateCollection

    Messages.Add ("West site pump turned off","Msg251")
    Messages.Add ("West site pump turned on","Msg252")
    Messages.Add ("West site pump failed","Msg253")

    end sub

    Then when you receive a message from the client

    'obviously this would be set to whatever the current received message is not a static string as this exampe has.
    dim recvdmsg as string = "Msg251 Msg251 Msg251 Msg251 Msg251 Msg251 Msg251"

    Dim MsgArray as Arraylist()
    Dim i as object
    Dim MsgString as string

    MsgArray = recvdmsg.split(space(1), 7)

    For each i in MsgArray
      'turn on error handling
      on error Goto NxtMsg
      if messages(i.tostring) <> "" then
        MsgString = messages(i.tostring)
        exit for
      end if
    'label a line to goto
    NxtMsg:
    next
    'turn off error handling
    On Error Goto 0
    'prompt the user with the string you received.
    msgbox(MsgString)

    this way you have received the message 7 times for the price of one and if one or 6 of the strings sent get mixed up you still have one good one.  So if your message ends up "MS*2000251 M51 Mg251 Msg251 Msg251 g251 M1" the for loop will discard the first 2 messages and accept the third because it is a key for the collection Messages and then it will exit the for loop.

    Corey
    0
     
    LVL 2

    Author Comment

    by:tdyck12345
    Thats is a good suggestion. However, the problem occurs before sending the message. The string gets garbled inside the application before sending it out to the radio. Also, I am using Kenwood FleetSync radios, and the FleetSync protocol handles all the radio communication.





    0
     
    LVL 2

    Author Comment

    by:tdyck12345
    I have discovered one thing that I think may have been causing the problem:

    The database that I use in my system is an MS Access 2000 database. I compiled the blank database into my service.exe file as an embedded resource. When the service starts, if the service cannot find a database, the service retrieves a copy of the embedded database from memory and creates a new database file. This seemed to work fine, however now I have been having strange and unpredictable issues, such as strings getting garbled or truncated. I am beginning to think that having a copy of an access database in memory is causing my applications heap to become corrupted. I am almost certain that this is a corruption issue, because the problems I have been seeing seem to creep around the application in an unpredictable manner.

    I have recompiled my application without the embedded MS Access database and am in the process of testing.

    Can anyone please give comments on why or why not this could be the problem.

    Thanks,

    Troy
    0
     
    LVL 2

    Author Comment

    by:tdyck12345
    As it turns out all my problems were occurring because of the embedded MS Access database resource. After removing it, everything works fine.

    Troy
    0
     

    Accepted Solution

    by:
    Closed, 460 points refunded.
    PashaMod
    Community Support Moderator
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
    It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now