Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Pls pls pls help me been working on it for weeks

Pls pls pls help me been working on it for weeks

Scheduled Pinned Locked Moved C#
helpcsharpgraphicstestingbeta-testing
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yefeng_law
    wrote on last edited by
    #1

    hi, this is exactly my first program, i will be using C#. The device i am using is a usb connected PC digital TV receiver this receiver software actually have a function which measure the signal strength, BER and these data are save into an log file (thus it real time measurement data) once i start the device (start watch TV). I am suppose to use C# to get the real time measurement and convert it into graphic (line chart). I have try to get the data for the log file and display it in the textbox using the following code using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Testing_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { StreamReader objstream = new StreamReader("c:\\measurement.log"); textBox1.Text = objstream.ReadToEnd(); } but this is the error i got : the file been use by another program. I also try another method which is directly from the usb port which the device is connected to but i am unable to start working on it coding. i had been looking into example of usb_hib and ICSHARPUSBlib but i was unable to get anything out. Thus please help me, if i am in the right direction (get the data from usb directly?) or do you have any better item on how i should get this done, any code to refer to. thank so much

    H 1 Reply Last reply
    0
    • Y yefeng_law

      hi, this is exactly my first program, i will be using C#. The device i am using is a usb connected PC digital TV receiver this receiver software actually have a function which measure the signal strength, BER and these data are save into an log file (thus it real time measurement data) once i start the device (start watch TV). I am suppose to use C# to get the real time measurement and convert it into graphic (line chart). I have try to get the data for the log file and display it in the textbox using the following code using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Testing_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { StreamReader objstream = new StreamReader("c:\\measurement.log"); textBox1.Text = objstream.ReadToEnd(); } but this is the error i got : the file been use by another program. I also try another method which is directly from the usb port which the device is connected to but i am unable to start working on it coding. i had been looking into example of usb_hib and ICSHARPUSBlib but i was unable to get anything out. Thus please help me, if i am in the right direction (get the data from usb directly?) or do you have any better item on how i should get this done, any code to refer to. thank so much

      H Offline
      H Offline
      Harvey Saayman
      wrote on last edited by
      #2

      Because your new here and to programming i wont be too sarcastic but here area a few pointers when posting here... 1.) Please use a subject related to your question 2.) Please use pre tags when posting code Have a look at my article - How to use the code project forums[^] Now on to your question :) Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time. Thats why you get the FileAccessException, because the program that logs the signal strenght is constantly updating the file. Now that i think about it, you can open a file that a program is writing too and view it in notepad... so u might be able to do this, as long as you dont try to write to the file. What strikes me as strange in your code is your using just the stream reader... maybe this is the problem... try this

      FileStream fs = new FileStream(@"c:\measurement.log", FileMode.Open);
      StreamReader reader = new StreamReader(fs);

      string fileContents = reader.ReadToEnd();

      as for the graphical part, have a look at GDI+ it involves the use of the OnPaint(object Sender, EventArgs e) event handler of a component like a panel, because youll be updating it continuously your going to have to paint on a Double Buffered Panel so that it wont flicker! Well that should keep u busy for a while if this is your 1st C# program, if u have any questions ill be glad to help if i can. Good luck!

      Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

      C Y 2 Replies Last reply
      0
      • H Harvey Saayman

        Because your new here and to programming i wont be too sarcastic but here area a few pointers when posting here... 1.) Please use a subject related to your question 2.) Please use pre tags when posting code Have a look at my article - How to use the code project forums[^] Now on to your question :) Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time. Thats why you get the FileAccessException, because the program that logs the signal strenght is constantly updating the file. Now that i think about it, you can open a file that a program is writing too and view it in notepad... so u might be able to do this, as long as you dont try to write to the file. What strikes me as strange in your code is your using just the stream reader... maybe this is the problem... try this

        FileStream fs = new FileStream(@"c:\measurement.log", FileMode.Open);
        StreamReader reader = new StreamReader(fs);

        string fileContents = reader.ReadToEnd();

        as for the graphical part, have a look at GDI+ it involves the use of the OnPaint(object Sender, EventArgs e) event handler of a component like a panel, because youll be updating it continuously your going to have to paint on a Double Buffered Panel so that it wont flicker! Well that should keep u busy for a while if this is your 1st C# program, if u have any questions ill be glad to help if i can. Good luck!

        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Harvey Saayman wrote:

        Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time

        Not strictly true. It is possible to set a sharing mode for the file. If you open the file as Exclusive (aka DenyAll or ShareNone) then nothing else can access it. If you open the file as ShareRead then multiple things can open the file as Read Only (so long as they all allow other processes to read the file too)

        Harvey Saayman wrote:

        What strikes me as strange in your code is your using just the stream reader

        What struck me was that the file never gets closed. The OP needs a using block around that stream. That is the most likely reason as the program that generates the file is probably expecting readers simultaneous with it writing the file and will have the file open accordingly.

        Recent blog posts: *SQL Server / Visual Studio install order *Installing SQL Server 2005 on Vista *Crazy Extension Methods Redux * Mixins My Blog

        Y 1 Reply Last reply
        0
        • H Harvey Saayman

          Because your new here and to programming i wont be too sarcastic but here area a few pointers when posting here... 1.) Please use a subject related to your question 2.) Please use pre tags when posting code Have a look at my article - How to use the code project forums[^] Now on to your question :) Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time. Thats why you get the FileAccessException, because the program that logs the signal strenght is constantly updating the file. Now that i think about it, you can open a file that a program is writing too and view it in notepad... so u might be able to do this, as long as you dont try to write to the file. What strikes me as strange in your code is your using just the stream reader... maybe this is the problem... try this

          FileStream fs = new FileStream(@"c:\measurement.log", FileMode.Open);
          StreamReader reader = new StreamReader(fs);

          string fileContents = reader.ReadToEnd();

          as for the graphical part, have a look at GDI+ it involves the use of the OnPaint(object Sender, EventArgs e) event handler of a component like a panel, because youll be updating it continuously your going to have to paint on a Double Buffered Panel so that it wont flicker! Well that should keep u busy for a while if this is your 1st C# program, if u have any questions ill be glad to help if i can. Good luck!

          Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

          Y Offline
          Y Offline
          yefeng_law
          wrote on last edited by
          #4

          hi, I had try the code you have given to me but I get the following error IOException was unhandled Is there an solution for my problem? Thanks

          1 Reply Last reply
          0
          • C Colin Angus Mackay

            Harvey Saayman wrote:

            Your trying to get the data from a flat text file, and these can only be accessed by one program / thread / object at a time

            Not strictly true. It is possible to set a sharing mode for the file. If you open the file as Exclusive (aka DenyAll or ShareNone) then nothing else can access it. If you open the file as ShareRead then multiple things can open the file as Read Only (so long as they all allow other processes to read the file too)

            Harvey Saayman wrote:

            What strikes me as strange in your code is your using just the stream reader

            What struck me was that the file never gets closed. The OP needs a using block around that stream. That is the most likely reason as the program that generates the file is probably expecting readers simultaneous with it writing the file and will have the file open accordingly.

            Recent blog posts: *SQL Server / Visual Studio install order *Installing SQL Server 2005 on Vista *Crazy Extension Methods Redux * Mixins My Blog

            Y Offline
            Y Offline
            yefeng_law
            wrote on last edited by
            #5

            hi Colin Angus Mackay thank for your reply I am not very sure and clear on what you are trying to tell me as I am very new to programming sorry about it.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups