i am writing a c# programming to receive data through serial port. Data receiving is going fine. But first to enable data flow i have to type "datafrm f1a4" and then press "Enter" key in the hyperterminal. then i have to run the c# program. Can I get this done within the program. I tried as below using following method. but couldn't get it done.Can any one help me. The code is below.

private void SendData()
    {
        byte[] datafrmf1a4 = new byte[13];
        //ASCII characters for "datafrm f1a4" and "Enter"
        datafrmf1a4[0] = 100;
        datafrmf1a4[0] = 97;
        datafrmf1a4[0] = 116;
        datafrmf1a4[0] = 97;
        datafrmf1a4[0] = 102;
        datafrmf1a4[0] = 114;
        datafrmf1a4[0] = 109;
        datafrmf1a4[0] = 32;
        datafrmf1a4[0] = 102;
        datafrmf1a4[0] = 49;
        datafrmf1a4[0] = 97;
        datafrmf1a4[0] = 53;
        datafrmf1a4[0] = 13;

        string datafrm = Convert.ToString(datafrmf1a4);
        comport.Write(datafrm);


    }

Recommended Answers

All 8 Replies

i am writing a c# programming to receive data through serial port. Data receiving is going fine. But first to enable data flow i have to type "datafrm f1a4" and then press "Enter" key in the hyperterminal. then i have to run the c# program. Can I get this done within the program. I tried as below using following method. but couldn't get it done.Can any one help me. The code is below.

1.
      private void SendData()
   2.
      {
   3.
      byte[] datafrmf1a4 = new byte[13];
   4.
      //ASCII characters for "datafrm f1a4" and "Enter"
   5.
      datafrmf1a4[0] = 100;
   6.
      datafrmf1a4[0] = 97;
   7.
      datafrmf1a4[0] = 116;
   8.
      datafrmf1a4[0] = 97;
   9.
      datafrmf1a4[0] = 102;
  10.
      datafrmf1a4[0] = 114;
  11.
      datafrmf1a4[0] = 109;
  12.
      datafrmf1a4[0] = 32;
  13.
      datafrmf1a4[0] = 102;
  14.
      datafrmf1a4[0] = 49;
  15.
      datafrmf1a4[0] = 97;
  16.
      datafrmf1a4[0] = 53;
  17.
      datafrmf1a4[0] = 13;
  18.
       
  19.
      string datafrm = Convert.ToString(datafrmf1a4);
  20.
      comport.Write(datafrm);
  21.
       
  22.
       
  23.
      }

At line 19 you use Convert.ToString(datafrmf1a4); and change the data to Unicode, so the data sent to the port is no longer what you want.
Remove line 19 and try using comport.Write(datafrmf1a4,0,datafrmf1a4.Length); (writing bytes not string).

Just as an aside, you can get the ASCII equivalent of a string using ASCIIEncoding.

string dataStr = "datafrm f1a4\r";
byte[] datafrmf1a4 = System.Text.ASCIIEncoding.ASCII.GetBytes(dataStr);

Thanxx Nick.. I tried "comport.Write(datafrmf1a4,0,datafrmf1a4.Length);" but couldn't get it done. But i didn't try "comport.Write(datafrmf1a4,0,datafrmf1a4.Length);"
I'll try both and reply then.. thanx again..

heyy Thanx nick.. i solved my problem.
Can u give me some example how to plot a real time graph in c#?

heyy Thanx nick.. i solved my problem.
Can u give me some example how to plot a real time graph in c#?

Hi dilansankalpa,

Your question should be posed in a new thread, otherwise it would be hard for others to see. However, check out

http://zedgraph.org/wiki/index.php?title=Main_Page

it is a very good tool.

hey thanx...!!! I found a graph plot library from www.codeproject.com

http://www.codeproject.com/KB/miscctrl/GraphPlotting.aspx

then i started my own project. i add the graphlib library to my project.. then I add the object PlotterDisplayEx into my project. but i cant add those start, pause, stop buttons and scroll bars to adjust speed and position. please can u help me in this case???

Did you try posting on CP? I'll take a look at trying to see what your problem is if you post a new thread here so people in the future can take a look at how it was solved (if it does get solved :)

Code Project has a lot of smart people on it too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.