Results 1 to 7 of 7

Thread: Converting Serial port data into pixel number for plotting graph

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2017
    Posts
    73

    Converting Serial port data into pixel number for plotting graph

    Hello All,

    I'am using VS2015 community and making an application in Visual Basic.

    I'am trying to plot a real time waveform on a picture box using draw line method based on my incoming serial data.

    In my Picture box , My X-axis is time in seconds and I have kept 50 pixels Difference in between every second. ( upto 6 seconds)
    For example : 0sec - 50pixels - 1sec so my per pixel resolution is 20mS


    Similarly Y-Axis is Volume in Litres and there is 50 pixels difference between each litre so each pixel on my Y-axis represents 20 ml .
    Now , If I get even quantity like 20,40,60,80 ml then it is easy to plot on y axis


    Iam receiving data after every 20ms from microcontroller so everytime serial data comes in , I increase X-axis pixel by 1

    Now , plotting on Y axis is easy whenever I get volume in even numbers like 20ml,40ml,60ml,80ml etc. ( every pixel is 20ml)

    However, When I get odd volume like 10ml,30ml,50ml then How can I plot it on Y axis. For example at 30ml I cannot plot 1.5 pixel as pixel are in integer and not floating point.

    kindly help!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Converting Serial port data into pixel number for plotting graph

    Divide the number by 20 to get a Double and call Math.Round on that to round it to the nearest Integer.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2017
    Posts
    73

    Re: Converting Serial port data into pixel number for plotting graph

    but it is not true representation of data!! There will be always be loss of 10ml

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Converting Serial port data into pixel number for plotting graph

    The only other option would to use what amounts to antialiasing. If the value is 50 then you could colour the 40 and 60 pixels halfway between the background colour and the foreground colour. If the value is 55 then you could colour the 60 pixel three quarters of the way from the background colour to the foreground colour and the 40 pixel one quarter from background to foreground. Etc.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2017
    Posts
    73

    Re: Converting Serial port data into pixel number for plotting graph

    ok, will be studying antialiasing in graphics and try implementing it.
    thanks for the suggestion!

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2017
    Posts
    73

    Re: Converting Serial port data into pixel number for plotting graph

    ok, will be studying antialiasing in graphics and try implementing it.
    thanks for the suggestion!

  7. #7
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: Converting Serial port data into pixel number for plotting graph

    The only way to do it better is to change the scaling. If a 10ml plotting error is not acceptable then you need to have a smaller quantity per pixel. You could always plot the data on to a large bitmap and then scale it to fit your picturebox. That way you could implement a zoom feature to allow the operator to see small changes more clearly.

Posting Permissions

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



Click Here to Expand Forum to Full Width