|
Thanks Greeeg.
You're nice.
Sorry for my English. I'm a freshman .
|
|
|
|
|
No problem. Make sure to read my answer again, I had to modify the regex pattern so that the result does not output "True" in some bad cases.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
All right Greeeg. I saw that.
Sorry for my English. I'm a freshman .
|
|
|
|
|
Hello, I am currently writing an application that needs to be able to generate a private and public key, but it must be output in PEM format. It needs this format because other related applications require this format. I can't find any functions in any libraries that do this. What would be the best way to do this? If there is nothing that does this, is there a way I could write another program in (for example: C) that generates the keys given command line options and just hope it succeeds?
Kind Regards,
Mike
|
|
|
|
|
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 />
tmrRecData.Enabled = false;<br />
lblStatus.Text = "Reading Data ... ";<br />
string data = serialPort1.ReadLine();<br />
ExtractData(data);<br />
tmrRecData.Enabled = true;<br />
}<br />
<br />
private void ExtractData(string data)<br />
{<br />
lblStatus.Text = "Parsing Data ... ";<br />
<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 />
lblDateTime.Text = DateTime.Now.ToString("hh:mm tt MM/dd/yyyy");<br />
string tempData = data.Substring(6, data.Length - 6);<br />
tempData = tempData.Replace((char)0x1B + "G", "");<br />
tempData = tempData.Replace((char)0x1B + "H", "").TrimEnd(null);<br />
lvi.SubItems.Clear();<br />
lvi.Text = currBinNum.ToString("00");<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 />
tmrRecData.Enabled = false;<br />
<br />
lblStatus.Text = "Saving Data ...";<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 />
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 />
lblStatus.Text = "Printing Data ...";<br />
printPreviewDialog1.ShowDialog();<br />
lblStatus.Text = "Waiting ...";<br />
}
Chase Davis
|
|
|
|
|
I suspect that the stream of temperature data may not have a NewLine at the end for ReadLine() to pick up. If that's the case you'll have to accumulate the entire stream then parse it. I'd make clever use of the ReceivedBytesThreshold and some supporting classes to do that. Hope this helps...
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Hi,
Which Timer are you using, System.Windows.Forms or System.Timer, and can you post your code for creating it, assigning the delegate, setting the interval etc.
Are your controls actually updating correctly when data is received? I would have thought you would see cross thread errors as the serial port event and the timer event will be raised on threadpool threads, not the form thread. You should be using the control.Invoke method to update your UI correctly.
I'm just about to leave work so I won't be able to check back for many hours.
Alan.
|
|
|
|
|
It is a System.Windows.Forms Timer
I got a cross thread exception when I first ran the program, and just shrugged it off and added the Control.CheckForIllegalCrossThreadCalls = false; line to my program. I don't know anything about threads, but if I understand what you are saying the timer that I created on my form cannot be updated (enabled / disabled) through the SerialPort DataReceived event? How would I use the Invoke methods to update my UI?
Chase Davis
|
|
|
|
|
The technique used to update controls correctly in multithreaded programmes is given here http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx[^] and it will also be in the local help if you are using a version of Visual Studio.
The knowledge required to implementing threading reliably is not small and when you first encounter the subject it it can be quite daunting. The advice from Microsoft is to ensure that controls are only updated from the thread that created them and the reason for this is to prevent corruption of their “state” . The Control.Invoke methods essentially allow any thread to send the instruction, “Update the control with this information”, to the control’s creator thread.
That said, it is not obvious from the code you have posted if control updating has caused your problem and I would urge you to post your timer setup code. After all, if the timer is setup correctly and it is enabled then it should fire.
The Forms.Timer runs on the UI thread so your code within the tick handler looks ok. I was having a bit of a brainstorm in my previous post when I implied that the Forms.Timer would run on a separate thread. Also changing the timer’s enabled state from the serial port event thread should not be a problem.
Alan.
|
|
|
|
|
Hi all,
I'm needing to do some fancy parsing of keyboard input into a text box. Basically, the need here arises because I have three possible devices that will put input into this box, the regular keyboard, a mag stripe reader and a laser scanner.
The keyboard and laser scanner are fine, but some types of input into the mag stripe reader will contain a carriage return in the middle of input which obviously creates a problem.
I was considering using the raw input API to somehow handle the mag stripe input, but I think it would be simpler if I just used the following logic:
1)Catch first CR
2) Wait for some time interval, probably 100->200 ms
3) If we get another keypress, ignore the first one
4) Repeat until we get a condition where after the wait we have no keypress, then submit input
I'm a little unsure, though, how to 'ignore' the first CR, and how to properly wait and then check if we had another keypress event. I'd appreciate any help, either with the code or perhaps making this logic workflow simpler.
Thanks!
|
|
|
|
|
The easiest solution that comes into my mind is to keep track of the time when the last CR input happend in the keypress handler. Something like
DateTime lastCRinput;
double timeDelta = 150;
void OnKeyPress(...)
{
DateTime now = DateTime.Now;
if ((key == '\r') && ((now - lastCRinput).TotalMilliseconds > timeDelta))
{
lastCRinput = now;
}
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
I need to parse the XML resulted after browsing to a url.
I already have a way to do this, but I'm not quite happy with it: I have a form with an AxWebBrowser in it, I navigate the webBrowser to the url, handle webBrowser_DocumentComplete and in there grab the XML and close the form.
Is there a better way of doing this without loading and hiding a form?
thanx
|
|
|
|
|
Do an HttpWebRequest[^] and grab it?
Life, family, faith: Give me a visit.
From my latest post: "A lot of Christians struggle, perhaps at a subconscious level, about the phrase "God of Israel". After all, Israel's God is the God of Judaism, is He not? And the God of Christianity is not the God of Judaism, right?"
Judah Himango
|
|
|
|
|
Thanx!
It's official, I'm losing my mind...
|
|
|
|
|
I'm using the SetWindowsHookEx Win32 method to set a hook on window activation for my process. It's working fine until garbage collection occurs so I'm trying to pin the delegate using GCHandle.Alloc.
This is failing with an error message that the delegate is nonprimitive and nonblitable even though I've changed the method signature to this:
public delegate IntPtr HProc(IntPtr nCode, IntPtr wParam, IntPtr lParam);
How can I change the delegate so that I can use it, or is there a better approach altogether?
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
I've run into a similar situation.
public delegate void ControlEventHandler(ConsoleEvent consoleEvent);
ControlEventHandler handler = new ControlEventHandler(OnControlEvent);
GC.KeepAlive(handler);
Not sure if this will help, but GC.KeepAlive will render the object ineligible for garbage collection.
Scott P
|
|
|
|
|
Thanks for the approach, but it turns out I didn't need it. The sample code I was using had the delegate as a local variable of the hooking class instead of an instance variable. Giving it the proper lifetime fixed the issue.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Is ClickOnce the preferred deployment strategy today for Winforms and WPF applications (rather than Windows Setup projects)?
|
|
|
|
|
I don't know if its a preferred method, but it doesn't hurt to be able to offer the option. Just depends what your customer wants. Let them choose basically...
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi,
I'm trying to get a very simple remotable type example working (from [url]http://msdn.microsoft.com/en-ie/library/xws7132e(en-us).aspx[/url] ).
I've put together the Remotable Type, the Server/Host and the Client exactly as in the tutorial. The Client is on a different machine from the other 2 (although you need to copy the RemotableType.dll to the client and add a reference to it in that project).
In my client, I configure the remote connection (specifying the machine etc. as in the tutorial) and then create my instance of the remotable class with the code below:
[CODE]RemotingConfiguration.Configure("Client.exe.config.txt", false);
RemotableType.RemotableType remoteObject = new RemotableType.RemotableType();[/CODE]
The trouble is, this is simply creating and running the remotableType on the Client machine. Is there something extra I need to do to actually get it to make that connection to the Server machine, have it run the code and return the result to the client as the tutorial says it does.
Thanks.
Conor.
|
|
|
|
|
Hi All,
If I have two classes with same names in two different namespaces. I need to type cast object of one class into another one. How can I do it. Pls. any help is very thankfull.
Thanks,
Aleem Mohammad.
S/W Engineer
Akebono Soft Technologies
aleem_abdul@akebonosoft.com.
|
|
|
|
|
use (namespace1.classname)namespace2.classname
Dave
|
|
|
|
|
indian143 wrote: I need to type cast object of one class into another one.
What? You can't cast a class into a type that it isn't, period. If it is the type then you use as .
Foo myFoo = myBar as Foo;
However if myBar is not a type Foo that will just produce a compiler error.
led mike
|
|
|
|
|
You can only really do this if one class inherits from the other. If there is no relation other than them sharing the same name, then you can't perform the cast. The only thing you could do is create an instance of the second class and copy the values from the first in. Here's an example where both objects have the same properties, but aren't the same class (and the same property names are present in both - it's an artificial example, but serves as an example):
private U Copy<T,U>(T original) where U : new()
{
PropertyInfo[] props = original.GetType().GetProperties();
U returnItem = new U();
foreach (PropertyInfo p in props)
{
returnItem.SetValue(returnItem, p.GetValue(original, null) null);
}
} I've just typed this off the top of my head, so some of the details may need to be finetuned a bit.
|
|
|
|
|
I'm studying for the MCTS and have just started developing my first custom control. The control seems to work perfectly when implemented in design time when dragged from the Toolbox to a test form, but when I try to implement/create the control dynamically in code, the control's overridden OnPaint method is not being accessed and the control is not being drawn when I run the program and try to create a new instance of the control in the Form's Load event.
I think I'm missing something fundamental in the control's constructor, but from what I've read about SetStyle method, using:
this.SetStyle(ControlStyles.UserPaint, true);
should have forced the control to paint itself via OnPaint -- but, it's had no effect. Using an Invalidate() call in the constructor also has no effect. Here's the code for the control as it stands now. The Control itself is essentially a label with a 'progress bar' drawn to a certain proportion of the control's width, then the base text is drawn above the bar.
Any thoughts on what changes are needed to ensure the OnPaint method is invoked when the control is instantiated/added at runtime would be appreciated!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ProgressBarLabel
{
[ToolboxBitmap(typeof(ProgressBar))]
public partial class ProgressBarLabel : Control
{
private float progressBarWidthRatio;
[Category("Appearance"),
Description("A number between 0.0 and 1.0 representing the % width of the ProgressBar in the Label.")]
public float ProgressBarWidthRatio
{
get
{
return this.progressBarWidthRatio;
}
set
{
this.progressBarWidthRatio = value;
if (this.progressBarWidthRatio > 1.0)
{
this.progressBarWidthRatio = 1.0F;
}
else if (this.progressBarWidthRatio < 0)
{
this.progressBarWidthRatio = 0.0F;
}
Refresh();
}
}
private Color progressBarBackColor;
[Category("Appearance"), Description("The BackColor of the ProgressBar within the Label.")]
public Color ProgressBarBackColor
{
get
{
return this.progressBarBackColor;
}
set
{
this.progressBarBackColor = value;
Refresh();
}
}
public ProgressBarLabel()
{
this.progressBarWidthRatio = 0.0F;
this.progressBarBackColor = this.BackColor;
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
public override string Text
{
get
{
return base.Text;
}
set
{
this.Invalidate();
base.Text = value;
}
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics g = pe.Graphics;
Rectangle r = pe.ClipRectangle;
Brush pbBrush = new SolidBrush(progressBarBackColor);
g.FillRectangle(pbBrush, r.X, r.Y, r.Width * progressBarWidthRatio, r.Height);
g.DrawRectangle(Pens.Black, r.X, r.Y, r.Width - 1, r.Height - 1);
g.DrawRectangle(Pens.WhiteSmoke, r.X + 1, r.Y + 1, r.Width - 2, r.Height - 2);
SizeF timeSize = g.MeasureString(base.Text, base.Font);
g.DrawString(base.Text, base.Font, new SolidBrush(base.ForeColor),
(r.Width - timeSize.Width) / 2, (r.Height - timeSize.Height) / 2);
g.Dispose();
}
}
}
|
|
|
|
|