Click here to Skip to main content
15,902,787 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can we create Image type from base64 string ? Pin
Colin Angus Mackay18-Jun-08 11:02
Colin Angus Mackay18-Jun-08 11:02 
GeneralRe: How can we create Image type from base64 string ? Pin
Mohammad Dayyan18-Jun-08 11:32
Mohammad Dayyan18-Jun-08 11:32 
GeneralRe: How can we create Image type from base64 string ? Pin
User 665818-Jun-08 11:41
User 665818-Jun-08 11:41 
GeneralRe: How can we create Image type from base64 string ? Pin
Mohammad Dayyan18-Jun-08 11:46
Mohammad Dayyan18-Jun-08 11:46 
GeneralRe: How can we create Image type from base64 string ? Pin
User 665818-Jun-08 11:48
User 665818-Jun-08 11:48 
GeneralRe: How can we create Image type from base64 string ? Pin
Mohammad Dayyan18-Jun-08 11:56
Mohammad Dayyan18-Jun-08 11:56 
QuestionOpenSSL key generation in PEM format Pin
Mike Bentzen18-Jun-08 10:44
Mike Bentzen18-Jun-08 10:44 
QuestionSerial Port Help Pin
Chase Davis18-Jun-08 9:30
Chase Davis18-Jun-08 9:30 
I have a temperature scanner that reads the temperature from certain field devices. Every morning at 7:00 a.m. the scanner sends ASCII data over the serial port (originally intended to go straight to a printer). The printer does not have a serial connection, so I am monitoring the data and using the PrintDocument class to print the data. The data contains 21 temperatures for at least 11 groups. I have no problem reading the data using the SerialPort class and the ReadLine function. However, the only way to know when the last grouping is sent is by using a timer (I can't just look for group #11's data and say that is the end). For some reason, my timer will not time out after I read serial data. Here is my code. Any help would be appreciated.

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)<br />
{ <br />
     // disable the timer<br />
     tmrRecData.Enabled = false;<br />
     lblStatus.Text = "Reading Data ... ";<br />
     string data = serialPort1.ReadLine();<br />
     ExtractData(data);<br />
     // enable the timer<br />
     tmrRecData.Enabled = true;<br />
}<br />
<br />
private void ExtractData(string data)<br />
{<br />
    lblStatus.Text = "Parsing Data ... ";<br />
<br />
    // the first line starts with Bin: (get the bin number)<br />
    if (data.StartsWith("Bin:"))<br />
        currBinNum = Convert.ToInt32(data.Substring(4, 6).Trim());<br />
    else if (data.Length > 10)<br />
    {<br />
        int lvIndex = -1;<br />
        ListViewItem lvi = new ListViewItem();<br />
        foreach (ListViewItem item in lvLastRead.Items)<br />
        {<br />
            if (item.Text == currBinNum.ToString("00"))<br />
            {<br />
                lvIndex = item.Index;<br />
                lvi = item;<br />
                break;<br />
            }<br />
        }<br />
        if (lvIndex == -1)<br />
        {<br />
            lvi = lvLastRead.Items.Add(new ListViewItem(currBinNum.ToString("00")));<br />
            lvIndex = lvi.Index;<br />
        }<br />
        // the first five characters represent the date (ignore them)<br />
        // set the label to the last read time and date<br />
        lblDateTime.Text = DateTime.Now.ToString("hh:mm tt MM/dd/yyyy");<br />
        // remove the date characters<br />
        string tempData = data.Substring(6, data.Length - 6);<br />
        // remove escape sequence with G character<br />
        tempData = tempData.Replace((char)0x1B + "G", "");<br />
        // remove escape sequence with H character<br />
        tempData = tempData.Replace((char)0x1B + "H", "").TrimEnd(null);<br />
        lvi.SubItems.Clear();<br />
        lvi.Text = currBinNum.ToString("00");<br />
        // every 4th character is the start of a 3 digit number for the temperature<br />
        for (int i = 0; i + 2 <= tempData.Length; i += 4)<br />
        {<br />
            string temp = tempData.Substring(i, 3).Trim();<br />
            lvi.SubItems.Add(temp);<br />
        }<br />
        lvLastRead.Items[lvIndex] = lvi;<br />
    }<br />
    lblStatus.Text = "Waiting ...";<br />
}<br />
<br />
private void tmrRecData_Tick(object sender, EventArgs e)<br />
{<br />
  //disable the timer	<br />
  tmrRecData.Enabled = false;<br />
<br />
  lblStatus.Text = "Saving Data ...";<br />
  // if the timer times out, then save the data to a csv<br />
  DirectoryInfo di = new DirectoryInfo(Application.StartupPath);<br />
  di.CreateSubdirectory("Monthly Temps " + DateTime.Now.ToString("yyyy-MM"));<br />
<br />
  TextWriter tw = new StreamWriter(Application.StartupPath + @"\Monthly Temps " + DateTime.Now.ToString("yyyy-MM") + @"\Daily Temps " + DateTime.Now.ToString("yyyy-MM-dd") + ".csv");<br />
  // write the header<br />
  tw.WriteLine("Bin,Temp. #1,Temp. #2,Temp. #3,Temp. #4,Temp. #5,Temp. #6,Temp. #7,Temp. #8,Temp. #9,Temp. #10,Temp. #11,Temp. #12,Temp. #13,Temp. #14,Temp. #15,Temp. #16,Temp. #17,Temp. #18,Temp. #19,Temp. #20,Temp. #21");<br />
  foreach (ListViewItem lvi in lvLastRead.Items)<br />
  {<br />
      string strLine = lvi.Text;<br />
      for (int i=1; i<lvi.subitems.count;>      {<br />
          strLine += "," + lvi.SubItems[i].Text;<br />
      }<br />
      tw.WriteLine(strLine);<br />
  }<br />
  tw.Close();<br />
<br />
  // print the file<br />
  lblStatus.Text = "Printing Data ...";<br />
  printPreviewDialog1.ShowDialog();<br />
  lblStatus.Text = "Waiting ...";<br />
  //printDoc.Print();<br />
}


Chase Davis

AnswerRe: Serial Port Help Pin
carbon_golem18-Jun-08 10:01
carbon_golem18-Jun-08 10:01 
AnswerRe: Serial Port Help Pin
Alan N18-Jun-08 10:09
Alan N18-Jun-08 10:09 
GeneralRe: Serial Port Help Pin
Chase Davis18-Jun-08 10:20
Chase Davis18-Jun-08 10:20 
GeneralRe: Serial Port Help Pin
Alan N18-Jun-08 13:10
Alan N18-Jun-08 13:10 
QuestionHow to check if keyboard input occurs within a certain time limit? Pin
Michael Zmuda18-Jun-08 9:13
Michael Zmuda18-Jun-08 9:13 
AnswerRe: How to check if keyboard input occurs within a certain time limit? Pin
User 665818-Jun-08 9:21
User 665818-Jun-08 9:21 
QuestionAxWebBrowser question Pin
kozu18-Jun-08 8:51
kozu18-Jun-08 8:51 
AnswerRe: AxWebBrowser question Pin
Judah Gabriel Himango18-Jun-08 11:31
sponsorJudah Gabriel Himango18-Jun-08 11:31 
GeneralRe: AxWebBrowser question Pin
kozu18-Jun-08 11:59
kozu18-Jun-08 11:59 
QuestionGCHandle.Alloc and delegate Pin
Andy Brummer18-Jun-08 7:13
sitebuilderAndy Brummer18-Jun-08 7:13 
AnswerRe: GCHandle.Alloc and delegate Pin
carbon_golem18-Jun-08 9:12
carbon_golem18-Jun-08 9:12 
GeneralRe: GCHandle.Alloc and delegate Pin
Andy Brummer18-Jun-08 11:00
sitebuilderAndy Brummer18-Jun-08 11:00 
QuestionClickOnce Pin
Member 391904918-Jun-08 7:07
Member 391904918-Jun-08 7:07 
AnswerRe: ClickOnce Pin
Gareth H18-Jun-08 8:15
Gareth H18-Jun-08 8:15 
Question.NET Remotable Types Pin
conor2018-Jun-08 5:39
conor2018-Jun-08 5:39 
QuestionType casting Pin
indian14318-Jun-08 5:04
indian14318-Jun-08 5:04 
AnswerRe: Type casting Pin
DaveyM6918-Jun-08 5:08
professionalDaveyM6918-Jun-08 5:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.