|
It's less hacky than opening the password entry form in the form constructor / load event - and if the wrong password is entered the main app doesn't really start at all.
If (as it appears to me from his question) he has the rest of the app in place, it's a less intrusive solution as well.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I don't find an ApplicationContext hard to implement or intrusive.. but if you say this method can't backfire I'll take your word for it
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thx, OriginalGriff, that gave me the idea to be able to get it to work. I added the code for the password to the Main() in program.cs and it worked exactly how I wanted it to. You don't get it right and it lets you know and closes. If you do, it lets you in. Thx!
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I think that is a bad design! The user has to restart the app if he gets the password wrong. I always allow 3 tries before closing the application, caters for the dyslexic idiots we have as users!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello.
You may Use this.close() method for this.
It will close your window form.
Thanks.
|
|
|
|
|
Hello all,
as an old fashioned c-programmer I'm new to c# and this results in not understanding how to distribute data read from RS232c port (ASCii) to local file and via http (get) to my HTTP-Server on the other edge of our science world ...
I fond some examples how to read data from RS232 which works fine - I found an example how to write to disk ( aka file), but how do I combine this in one Process (foreground or background is irrelevant)? How do I split the data to file and ftp that come from serial port?
Many thanks for your help
Werner
|
|
|
|
|
Depends on exactly what you are trying to do: both operations individually are pretty simple! It's when you try to combine them that it gets more complex - and there are thousands of possible things you could be trying to do.
If you are looking at storing everything you receive to a disk as it comes in, then that;s reasonably trivial: handle the SerialPort.DataReceived[^] event and write it to a permanently open class level stream as byte data. As long as you call Stream.Flush[^] periodically (so that if your app crashes you don't loose the data) you should be fine.
Quite where FTP comes into the task, I'm not sure...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you OriginalGriff,
I found this sniplet which takes the data and displays it in an GUI-Text-Window ...
My Idea was to follow the description in the comment "Send data to whom ever interested", but I can not catch the provided data in an different procedure/function anymore
<pre lang="c#">void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int dataLength = _serialPort.BytesToRead;
byte[] data = new byte[dataLength];
int nbrDataRead = _serialPort.Read(data, 0, dataLength);
if (nbrDataRead == 0)
return;
// Send data to whom ever interested
if (NewSerialDataRecieved != null)
NewSerialDataRecieved(this, new SerialDataEventArgs(data));
}
</pre>
Where and how do I connect to "data" again?
I tried new functions and I tried from within the existing function ,... but I cannot find the data
Thank you
Werner
|
|
|
|
|
What do you mean "I can not catch the provided data in an different procedure/function anymore"?
I assume this is part of a class / control and NewSerialDataRecieved is an event of yours? What is handling the event? How have you linked the class to the handler method?
Does the handler have a try...catch block that swallows exceptions? If so, is it accessing any UI controls within the block?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
#region Fields
public event EventHandler<SerialDataEventArgs> NewSerialDataRecieved;
#endregion
Does this answer your question? sorry, I'm still confused about the very different coding compared to C
If it helps: I've found most of the code in "SerialPortListener" (an older) project on codeproject.com and I hoped to be able to learn from it ... but it seems it not easy doing self-studies
|
|
|
|
|
OK - lets try from a different angle...
What "hooked up" to that event - which method (or function in C parlance)?
Somewhere, there will be a line similar to:
classInstance.NewSerialDataRecieved += ... This could be in your code, or it could have been added automatically to the xxx.designer.cs file when you added the handler via the form designer / properties pane...Events
Show the method and I'll pick out the relevant bits!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OK - you can just post the code here, it's easier to read!
If you breakpoint the _spManager_NewSerialDataRecieved method, does it hit it all?
And does your SerialPortManager class open the port at any time?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yes , the incoming data are displayed completely in the GUI-Textwindow as soon as they arrive.
So I thought it must be easy to hook on
// Send data to whom ever interested
if (NewSerialDataRecieved != null)
NewSerialDataRecieved(this, new SerialDataEventArgs(data));
on this, but I don't see where I find the data ...
// tbData
//
this.tbData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbData.Location = new System.Drawing.Point(12, 260);
this.tbData.Multiline = true;
this.tbData.Name = "tbData";
this.tbData.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.tbData.Size = new System.Drawing.Size(431, 199);
this.tbData.TabIndex = 13;
//
I think the above is the part where the data are written to screen ,,,,
This might be the function where the data-array is filled with bytes ...
/// <summary>
/// EventArgs used to send bytes recieved on serial port
/// </summary>
public class SerialDataEventArgs : EventArgs
{
public SerialDataEventArgs(byte[] dataInByteArray)
{
Data = dataInByteArray;
}
/// <summary>
/// Byte array containing data from serial port
/// </summary>
public byte[] Data;
}
I'm loosing the ground under my feet ...
|
|
|
|
|
Um...tbData is a TextBox?
So it has a Text property?
And this bit of code:
string str = Encoding.ASCII.GetString(e.Data);
tbData.AppendText(str);
Should append the new data to the existing text in the textbox (and it's in an Invoke, so cross threading isn't a problem - well done!)
So put a breakpoint on the line:
int maxTextLength = 1000;
And step through to look at what is happening - you should see the raw data in e.Data as soon as it hits the breakpoint.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you so far - I'll be off 'til thursday for an business trip.
I think I will need your help and patience again.
Bye
Werner
|
|
|
|
|
I'm not planning on going anywhere!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
public static List<DefCurrency> AllCurrency
{
get
{
using (var db = new RPDBEntities())
{
return db.DefCurrencies.Select(b => new DAL.DTO.DefCurrencyDTO()
{
CreatedBy = b.CreatedBy,
CreatedDate = b.CreatedDate,
CurrencyCode = b.CurrencyCode,
CurrencyName = b.CurrencyName,
CurrencySign = b.CurrencySign,
DecimalPlaces = b.DecimalPlaces
}).ToList();
}
}
my controller class code is:
public List<DefCurrency> GetAllCurrency()
{
List<DefCurrency> myCurrencies = DefCurrency.AllCurrency;
return myCurrencies;
}
i am getting entities from DefCurrencyDTO class but conflict is between list i made in DefCurrency class
Nouman Arshad
modified 19-May-15 9:11am.
|
|
|
|
|
Well, one problem I see is that you're supposed to be returning a ``List<DefCurrency>`` but that's not what your code is doing. You're returning a ``List<DefCurrentDTO>``.
|
|
|
|
|
When looking at your code it's not clear whether there are two or three different types involved:
Are the elements of db.DefCurrencies of type DefCurrency, DefCurrencyDTO or some third type?
If they are of type DefCurrency, it would be trivial: You could just replace it by return db.DefCurrencies.ToList()
If they are of type DefCurrencyDTO or some third type you shouldn't do a "select new DefCurrencyDTO" but "select new DefCurrency".
(Having to deal with three different types in one method would be somewhat strange.)
For mapping types you could use something like Automapper[^] to make your life a bit easier and your code better maintainable.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 19-May-15 9:14am.
|
|
|
|
|
|
Please take another look at my previous message, I just edited it.
For information on how to use Automapper please refer to its homepage which you find with the Google search I provided you - there's a "getting started guide" linked. And the Google search also shows you a Codeproject-article on using Automapper.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I'm trying to get the list of com port name and the device's name connected to it. (eg: I want to automatically find the COM port for a specific USB device of Fastrack modem M1206B series). In the case where it finds multiple possible ports and i want only finds the port depending on what other usb devices are connected. I tried the following where I get only the list of com ports.
[CODE]
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
cboCOM.Items.Add(port);
}
[/CODE]
But I need get COMPort only finds the port depending on what other usb devices are connected.
|
|
|
|
|
Not having done anything with USB devices, would this document help? A USB Library to Detect USB Devices[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|