|
Do you have the vaguest idea what this code does ? Have you stepped through it to see where it gets stuck ? Are the values being passed in correct for your database, or did you just copy random code ? I am guessing you don't have a Coupon Management.mdf, or you have some other issue that's causing the database connection to time out, hence the wait.
Either way, programming and copying random code off the web, THEN asking us to make it work for you ( without even giving us the info we need to try to work out why it's not running ), are two different things. If you're being paid for the latter, you should tell your client you don't know what you're doing. If you're trying to learn, you shouldn't start with random code snippets, you should start with a book.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have a class that takes a constrained generic type and I need to know whether that type will be boxed when I call the Equals method.
class FUBAR<T> where T : struct
{
bool DoSomething(T a, T b)
{
return a.Equals(b);
}
}
|
|
|
|
|
Use ildasm to check.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Why can't you just use the == operator ? How do they differ from each other ? Is that not possible because of the generic type ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Its not possible because structs do not implement the == operator implicitly.
|
|
|
|
|
Oh, of course. I was thinking of IComparable, but that has a CompareTo method, not ==. Generics in C# are woefully underpowered compared to C++. I don't think they are good for much more than containers of type T.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Boxing will happen for both byte and enum . This is because you have constrained only on struct and not all structs have got a strongly typed Equals() method. So a compiler will be forced to call the Equals(object obj) method defined in the System.Object which will lead into boxing.
To avoid boxing here, you can constraint on IEquatable<T> . But this will not allow you to specify a enum as enums don't have IEquatable implemented.
CaptainSeeSharp wrote: OR WILL THE OVERLOAD THAT BYTEDEFINES BE CALLED?
Call will go to byte's Equals(object obj) method as Object.Equals() is virtual and System.Byte has overridden it.
Best wishes,
Navaneeth
|
|
|
|
|
here i have code that i use with ZedGrapf:
for (int i = 0; i < 30; i++)
{
if (cene_novo[i] != "")
{
x = (double)new XDate(leto, mesec+i, i+14); ??
y1 = Convert.ToDouble(cene_novo[i]);
list1.Add(x, y1);
}
}
How to change month that starts from October 2008 for every i+2.. and end with october 2009?
|
|
|
|
|
Zedgraph have forums. They are the best place to ask questions about Zedgraph, because everyone who reads them, uses it.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I have a problem. BIG one.
I have a LED connected to pin 3 and 5 at serial port (rs232).
Here is the code I make, who blink that led at an interval from a timer.
private SerialPort o_port = new SerialPort("COM3", 9600, Parity.Odd, 8, StopBits.One);
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
o_port.WriteLine("transmit data");
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
timer1.Interval = (int) numericUpDown1.Value;
labelInterval.Text = timer1.Interval.ToString();
}
What I want, is a modality to manipulate the ON state for the LED. In other words the sending data to pin 3.
I must link the "transmit data" to a timer event, and to keep it transmit for the duration of that timer event.
How to do that? hmmm.
Is there a special property who can be set to transmit a loop of data until some time is passed? Like flooding?
Thanks.
~Teodor~
modified on Sunday, November 1, 2009 6:41 PM
|
|
|
|
|
You could write a timer, then write a loop that sends the data over and over, and turn it off when the timer fires, if you send the data on another thread. That's assuming that the data gets sent once, that it's not a switch you turn on or off. That's how it worked when I worked with the serial port, you'd turn the pin on, set a timer, then turn it off again.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
well, when I integrate a while loop, my pc crash.
I really dont know how to do it...I dont have any clue. Please write me a code to have a inspiration on how to do it. Im a bit new to this .
thanks.
|
|
|
|
|
merlinq12 wrote: well, when I integrate a while loop, my pc crash.
How does it crash ? What happens ? What's the code ?
merlinq12 wrote: Please write me a code to have a inspiration on how to do it. Im a bit new to this Smile.
It's years since I did it, but have you tried just setting it once ? Does that turn the LED on, or make it flash on and off ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
{
int number = 1;
while (number == 1)
{
o_port.WriteLine("xxx");
}
}
The original code make the led flash/ ON and OFF.
I dont know how to turn the pin ON !!!!
|
|
|
|
|
I'd think you'd want to set a timer with a small interval, not run your processor to 100%.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
You have connected the LED between transmit data (TD) and ground (SG). Is is your intention to show when data is being transmitted or do you just want to turn an LED on and off?
If it's the latter then it would be better to connect the LED to one of the control lines, e.g. data terminal ready (DTR) or request to send (RTS), and ground. These lines can be toggled or or off via the SerialPort class.
The timer tick code would be e.g.
port.DtrEnable = !port.DtrEnable;
Alan.
|
|
|
|
|
Hi,
you're taking a bad approach here. The data lines (TD and RD) carry a serial data stream, which consists of start bits, data bits, parity bit, and stop bits; and by definition are not constant.
What you want can be achieved by using one of the control lines (that would be DTR or RTS, and it requires a hardware change to your current LED connection).
You can use SerialPort class, open the port, keep Handshake at None, then set DtrEnable or RtsEnable to the desired value. No need to read or write any data though.
BTW: don't forget to include a series resistor, 1K is a good first estimate.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
ohooohooo... Its Christmas time
Thank you very much for this very good advice, guys. Oau.
I use a usb to serial converter, and a bright LED , so I don't mind about the U/Led.
I wonder ... hmmm..I can run a stepper motor with this? Actually at this is serve the experiment with the led. Of course I will use a demultiplexor, a uln2004, and some bunch of wires.
If you know a better way (cleaner way) , I am all ears.
I have a pic 18f4550 but I dont have a scheme to make and then program it. I also have an 16f84 with what I do some nice stuff some time ago... with //port.
I also want to know how to make a timer run 1.25ms , then 1.50ms , then 1.75ms to be able to move a servo?
This would be great!!!!
|
|
|
|
|
merlinq12 wrote: I don't mind about the U/Led.
I don't know what you mean here, if you want to forgo the resistor chances are you will ruin your serial port, which will cost you more than thousands of resistors.
merlinq12 wrote: .I can run a stepper motor with this?
with the proper H bridge in place you can control motor steps, yes. However:
- there is bound to be some unpredictable delay between setting a control line in software, and getting the result at the end of the USB cable (a motherboard serial port is much better in this, it does not need a USB packet to transmit the command over a multi-device bus);
- a Windows PC would be unreliable in generating a smooth stepper motor sequence, as Windows has lots of overhead and isn't real-time at all.
The only good way to control moving equipment at the step level is by using a dedicated micro-controller, such as a PIC.
merlinq12 wrote: how to make a timer run 1.25ms , then 1.50ms , then 1.75ms
There is no way to do that reliably, unless you:
- replace the USB-to-RS232C cable by a motherboard port;
- and write a device driver (which can really run its code at a priority above all applications),
FWIW: moving parts that may harm a human being should not be controlled directly by a PC; always use a dedicated micro-controller, some micro-switches to detect out-of-order situations, and appropriate code.
PS: stop abusing the C# forum for something that is purely hardware oriented!
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc Pattyn thanks for your prompt response ... very nice and clean explanations (not very detailed but enough & strait forward). Thanks man.
And I Dont abuse anything, I was beginning the discussion from SerialPort class, and one thing to another I was jumping to other interesting stuff.
I see that I am away a bit from my original post, so I will no longer continue . I understand.
hmmm...nice talk with you...I can sleep tonight right.
thanks again and have a nice day.
~Teodor~
|
|
|
|
|
though ... I must put for others the !Finished! customized code :
using System.IO.Ports;
private SerialPort port = new SerialPort("COM3", 9600, Parity.Odd, 8, StopBits.One);
public Form1()
{
InitializeComponent(); port.Open();
}
private void buttonSS_Click(object sender, EventArgs e)
{
if (buttonSS.BackColor==Color.Transparent)
{
buttonSS.BackColor = Color.GreenYellow; port.DtrEnable = true;
timer1.Start();
}
else
{
buttonSS.BackColor = Color.Transparent;port.DtrEnable = false;
timer1.Stop(); label1ShowPort.Text = "Closed";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
port.DtrEnable = !port.DtrEnable;
if (port.DtrEnable)
{
timer1.Interval = (int)numericUpDown1.Value;
label1ShowPort.Text = "sending...";
label1ShowPort.BackColor = Color.OrangeRed;
}
else
{
timer1.Interval = (int)numericUpDown2.Value;
label1ShowPort.BackColor = Color.DarkRed;
label1ShowPort.Text = "";
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
timer1.Interval = (int)numericUpDown1.Value;
}
|
|
|
|
|
Hello, I am using borderless form as main form. It has a menu bar associted with it.
The problem is that main for window is not focused by default.
Menus gets highlighted when i move mouse over it but they do not expand as i click on it. I need to click one more time to expand the menu.
What should i do so that form is activated as soon as it comes up.
Thanks in advance.
|
|
|
|
|
Call the Focus() method in your form loaded event.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I'm trying to think on best way to implant something, and i'm uncertain as to what approach should i take.
Background:
1. i have PCI card (digital I/O card) that can acquire up to 96 inputs (each input reads as '1' or '0').
2. I'm developing panel for that card, that will display for user 96 LEDs (each with name next to it) - led lit = 1, led not lit = 0.
3. panel update at runtime without need to press anything.
The first approach that comes to my mind is:
1. 96 LEDs are generated on form at runtime (each with line input name).
2. run via loop: run async function using BeginInvoke that read input x value, then invoke main thread to update LED to on/off (based on value we've just read).
Possible problems:
overhead / GUI update speed.
I was thinking if i could somehow make certain led "subscribe" to a bit change on some array that is updated with changes, and that could somehow auto-fire the event & control would just "toggle" itslef to 1/0 (without me needing to address him).
Now i guess i could use singleton to refrence inside the custom control (led + label), but is there any better alternative / approach I should use ?? (aiming for max performance)
|
|
|
|
|
There's no way I can see to 'subscribe' to a mythical event, unless the drivers for your card generate one. Polling could be your best bet. I've written input controllers for custom controllers that use the parallel port and I was able to poll them on a timer without hurting my UI performance.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|