reading data using serial port

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 14
Reputation: udaywali is an unknown quantity at this point 
Solved Threads: 0
udaywali udaywali is offline Offline
Newbie Poster

Re: reading data using serial port

 
0
  #11
Nov 30th, 2006
Shefali

Your data has a neat pattern and VB is just one of the best languages to handle that kind of stuff


say you have read one line of input
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. dim s as string
  3. dim line as string
  4.  
  5. dim i as integer
  6. dim p2 as string
  7. dim v as integer
  8.  
  9. s = ""
  10.  
  11. s = s & comm1.input
  12. do while (1)
  13.  
  14. 'get one line
  15. do while instr(s, chr(10)) > 0
  16. 'get one line of data
  17. line = left(s, instr(s, chr(10)) -1)
  18. s = mid(s, len(s1)+1) 'remaing part of input
  19.  
  20. 'get first comma
  21. i = instr(s, ",")
  22. p2 = instr(i+1, s, ",")
  23. v = val(p2)
  24.  
  25. addPoint2Plot v
  26.  
  27. loop
  28.  
  29. 'append comm1 input to any remaining trailing chars of last input
  30. s = s & comm1.input
  31.  
  32. 'add some kind of exit code here.
  33.  
  34. loop

I assume addPoint2Plot will plot the data as I has explained in previous example.


Am I clear?

Uday Wali
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 36
Reputation: Shefali is an unknown quantity at this point 
Solved Threads: 0
Shefali Shefali is offline Offline
Light Poster

Re: reading data using serial port

 
0
  #12
Dec 3rd, 2006
hello again
udaywali thanks so much for ur help. ur code has been very helpful for me. i have used the split function to get the particular value of a string. but i used ur code for plotting the stuff and it worked nicely. thanks so much for showing me the way.
a small question.. will it be possible to give titles to the axis? i mean as i get more data the axis shud also get changed accordingly. is that possible? can u give me any code samples?
and one more thing i wanted to ask u is.. as of now the graph needs to refreshed... is it not possible that it automatically shifts towards left and the axis and the grid re-adjust automatically. something like the task-manager (performance) graph in windows.
thanks a lot again
regards.
shefali.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: udaywali is an unknown quantity at this point 
Solved Threads: 0
udaywali udaywali is offline Offline
Newbie Poster

Re: reading data using serial port

 
0
  #13
Dec 7th, 2006
Shefali,

Writing text on X axis is very simple.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. picture1.currentx = 500
  2. picture1.currenty = 10
  3. picture1.print "1000"

will print on the x axis. Trick is writing on the y axis because you need to rotate text. If you need help on that, let me know. I have some ready code, I can share with all. It is big, so i have not included here.

Scrolling is also very difficult and slow in VB. You should have a structure to store the values in say, a collection. Collections maintain data in a linked list, so deleting and adding is easy but it is some what slow. Create a class with two values, one for x and one for y. You could use CPoint for example.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'class module CPoint
  2.  
  3. 'declarations section
  4. Public x as single
  5. public y as single

Create a collection in your code to store instances of this class.


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public sub Timer_time()
  2.  
  3. static dataPts as collection
  4. static cnt as integer
  5.  
  6. private p as CPoint
  7.  
  8.  
  9. if dataPts is nothing then
  10. 'on the first call, create a new collection
  11. set dataPts = new collection
  12. cnt = 0
  13. end if
  14.  
  15. cnt = cnt + 1
  16. set p = New CPoint
  17. p.x = cnt
  18. p.y = ReadPort()
  19.  
  20. dataPts.add p
  21.  
  22. if dataPts.count > 1000
  23. dataPts.remove 1
  24. endif
  25.  
  26. 'you have a max of 1000 points in a collection,
  27. 'which you may now display
  28. DisplayValues dataPts
  29.  
  30. End sub
  31.  
  32.  
  33. Private sub DisplayValues(c as collection)
  34. dim i as integer
  35. dim x0 as integer 'x value at left of graph
  36.  
  37. if c.count > 0 then
  38. x0 = c(1).x
  39. endif
  40. 'clear the screen and display grid
  41. picture1.cls
  42. drawGrid
  43. 'draw set of lines correspoinding to x and y values in the collection
  44. for i = 1 to c.count -1
  45. picture1.line (c(i).x - x0, c(i).y)-(c(i+1).x - x0, c(i+1).y)
  46. next
  47.  
  48. end sub

I have written it quickly without much thought to clarity of idea. Because you know my earlier message, I guess you can guess my thoughts.

If it is not clear, let me know again.


Regards
Uday
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 10
Reputation: Bisaye is an unknown quantity at this point 
Solved Threads: 0
Bisaye Bisaye is offline Offline
Newbie Poster

Re: reading data using serial port

 
0
  #14
May 25th, 2009
I have a kind of problem on filtering data´s which were recorded through serial port. My question is I would like to know if I can take a selected datas to plot a real time graph. The datas are quite a lot of parameters for a time being I want to plot nine parameters. If you want the data format is like this
‹...‚.10D20®B...‚B01DA,20,2,L,49.98,11.96,3.35,2.35,2.55,890,264,93,1205.006,860,P\..
.‚.20D20¨G...‚B02DA,20,2,L,50.06,11.96,3.30,2.45,2.65,865,255,93,1205.008,928,P.ñ..
.‚.10D30«D...‚?01DA,30,2,S,P,L,P,S,P,M,P,P,R,N,N,D,E,S,80010.,99.999,0.08333¾Ÿ..
.‚.20D30¥I...‚?02DA,30,2,L,P,L,P,N,P,M,P,P,R,N,N,D,E,S,1457.6,99.994,0.08333.W..
.‚.10D31©E...‚101DA,31,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,M,0,1¥:...‚.20D31£J..
.‚102DA,31,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,M,0,1vh...‚.10D32§F..
.‚P01DA,32,0,1.00,15,85,31,27,2¬C...
from these datas I only want to read the type of values B01DA,20,2,L,49.98,11.96,3.35,2.35,2.55,890,264,93,1205.006,860, and
B02DA,20,2,L,50.06,11.96,3.30,2.45,2.65,865,255,93,1205.008,928
for information these datas are sequential and they start after three dots and a coma as you can see so I want to select the above ones only. Any information would be greatly appreciated
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 21444 | Replies: 13
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC