[RESOLVED] Capturing data from Com Port (mscomm)-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] Capturing data from Com Port (mscomm)

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Resolved [RESOLVED] Capturing data from Com Port (mscomm)

    Hi Friends,

    I am basically a Oracle D2K programmer. I've worked a bit in VB a long time back. I need some help with com port data capturing. the data is comming continuesly. I need to capture it properly and extract the useful party of it.


    VB Code:
    1. Private Sub Command1_Click()
    2.     MSComm1.CommPort = 1
    3.     If MSComm1.PortOpen = True Then
    4.         MSComm1.PortOpen = False
    5.     End If
    6.     MSComm1.PortOpen = True
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10. Text1.Text = MSComm1.Input
    11. End Sub

    I've used a very simple form with 2 command buttons and 1 text box

    the 1st command button opens the port and command button 2 assigns the value of mscomm1.input to text1.text

    the result which i get each time is

    set1
    -------------

    ':0 0000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000


    set2
    -----------------

    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 0000000000

    set3
    ---------------
    :0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000
    ':0 000000000000

    as you can see there is a symetry in data but it can not be used directly as when the application runs real fast 1/100 times it also captures junk values. can anybody please suggest me how can I regularise the dataflow in such a way that I can extract the useful value from input everytime I press the command button 2

    If you need any further information or details, please feel free to ask me.

    Hope to get a reply soon

    Warm Regards
    Vivek Bajaj

  2. #2
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Capturing data from Com Port (mscomm)

    A better understanding of the device and the specifics of it's protocol output will help you better design code to capture the charactors.
    What is the device that you are trying to communicate with?
    Truly, you have a dizzying intellect.

  3. #3
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Capturing data from Com Port (mscomm)

    You might try using the mid and instr functions to capture at know points ie
    the :
    if you know your data that you want is after the colon then get the len(input)
    and use instr, mid, len(input) to assign to a string and it should be pretty consistant judging from the data you posted.
    Truly, you have a dizzying intellect.

  4. #4
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Capturing data from Com Port (mscomm)

    Actually not the len(input)
    More like a fixed value 14 since this appears to be the data count to the right of the :
    between carriage returns
    Truly, you have a dizzying intellect.

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Capturing data from Com Port (mscomm)

    Hi gtilles

    Thanks for the reply. I am capturing this data from a weigh scale. I've already used the mid, instr and len functions. the basic problem is that as the data is continuesly flowing in the moment I capture it, sometimes it is not proper and 1 out of 100 times gives junk/wrong value. junk value can be taken care of but if the value itself is wrong then it creates a big problem. IF there any way by which I can put the input to a loop and extract the proper value from the input?

    any suggestions are welcome.

    Thanks and Regards
    Vivek Bajaj

  6. #6
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Capturing data from Com Port (mscomm)

    A few years ago I did an rs232 scale capture program
    and also had some captures that had bad data.
    It's been awhile but as I recall the scale I used would find a stable weight and wasn't in constant motion.
    I did a loop where I captured the data and I checked the sample for isnull,isnumeric for each charactor of the len
    if there was bad data I would loop until I had a good sample.
    I eventually was able to weed out the bad data and come up with good samples. GT
    Truly, you have a dizzying intellect.

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    6

    Re: Capturing data from Com Port (mscomm)

    Quote Originally Posted by gtilles
    A few years ago I did an rs232 scale capture program
    and also had some captures that had bad data.
    It's been awhile but as I recall the scale I used would find a stable weight and wasn't in constant motion.
    I did a loop where I captured the data and I checked the sample for isnull,isnumeric for each charactor of the len
    if there was bad data I would loop until I had a good sample.
    I eventually was able to weed out the bad data and come up with good samples. GT
    Thanks gtilles for you constant support. I think I've almost cracked it. All this happened when I was asking suggestions in forums. Actually the data which was displayed in text box of VB did not had any breaks/caridge. there was a constant pattern and I ried to follow that patteren but it only worked 95 times in 100. I was getting errors. When for the suggestions form the forum members I pasted the results here in the box I found that the symbol ~'~ got converted into carridge then it striked me that the VB textbox was unable to read the carridge from Weighscale. When I converted the data to Asc format I even got 13 for the symbol ~'~. Now I knew what I had to do. After the first carridge the data was always perfect.

    Thanks once again for your support

    Warm Regards
    Vivek Bajaj

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.