|
Hi,
I work with RS232 printers and sometimes they have just a few changes in the serialport configuration, like one has Parity=Even and other has Parity=None, or sometimes in the baudrate.
My questions are:
1) Does SerialPort has any builtin function that could read this configuration, without me changing it manually (I can change the port name manually of course)
2) If not, does anyone have ever implemented such feature? What would be a nice (and safe) approach for that?
Thanks,
Dirso
|
|
|
|
|
AFAIK rs232 is too legacy an interface to advertise its connection settings. Unless there's another app involved that sends the config changes to the printer and keeps a record i believe you're SOL.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
|
First explain what do you want to archive clearly
and the second thing refrain from using words like "it's urgent!!!"
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hesham Yassin wrote: it's urgent!!!
That's just plain rude. Your urgency is not anyone else's problem.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
|
Don't expect anyone to help you on this site with an attitude like that.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I have a frmMain which has a StatusStrip on it. Inside my class I have a function which checks for internet connection and when the system is not online, I would like for it to update one of the labels on the StatusStrip. I have tried to do some searching and have tried some examples but can not seem to get it to work.
I created the below function in frmMain.cs
public void Set_StatusStrip(string status)
{
toolStripStatusInternetConnection.Text = "";
}
In inc_functions.cs I have the following function
public void InternetConnectionAvailable()
{
frmMain.Set_StatusStrip("Application Online");
}
The error I get is "An object reference is required for the non-static field, method, or property." Can anyone see what I am doing wrong?
|
|
|
|
|
In the "IntererConnectionAvailable" method, you need to be calling Set_StatusStrip on an instance of the form, not on the form class
Object test = new Object();
Object.TestMethod1() <-- Static Method
test.TestMethod2() <-- Instance method
You are calling it as if it was a static method, but it's not, it's an instance method.
Good luck.
(This is a bad design by the way. You shouldn't be using a helper object to set a UI property on the form. Consider reading up about MVC, MVP or other GUI patterns)
Simon
|
|
|
|
|
I have read that it is bad practice, but I have been searching and reading all morning and I can not seem to find anything that is helping me do this the correct way. Can anyone help out with this?
|
|
|
|
|
You could do something like
public void InternetConnectionAvailable(frmMain f)
{
f.Set_StatusStrip("Application Online");
}
And when you call InternetConnectionAvailable , you pass an instance of your frmMain.
|
|
|
|
|
He's trying to avoid bad/not-recommended practices and this is one of those - why on earth would his Connection class or this particular method in it need to know about the form? It's nothing to do with the connection. Events/delegates are the way to handle this scenario.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
This is a perfect situation for using your own custom event. Something like this:
Create a delegate and event
public delegate void ConnectionChangedEventHandler(object sender, ConnectionEventArgs e);
public event ConnectionChangedEventHandler ConnectionChanged;
and a ConnectionEventArgs class
public class ConnectionEventArgs
{
public ConnectionEventArgs(bool isConnected)
{
m_IsConnected = isConnected;
}
private bool m_IsConnected;
public bool IsConnected
{
get { return m_IsConnected; }
}
}
then make the InternetConnection call a method
private void InternetConnectionAvailable()
{
OnConnectionChanged(new ConnectionEventArgs(true));
}
protected virtual void OnConnectionChanged(ConnectionEventArgs e)
{
if (ConnectionChanged != null)
ConnectionChanged(this, e);
}
Now you can subscribe to the ConnectionChanged event and update the StatusStrip
MyClassInstance.ConnectionChanged += new MyClass.ConnectionChangedEventHandler(MyClassInstance_ConnectionChanged);
void MyClassInstance_ConnectionChanged(object sender, ConnectionEventArgs e)
{
}
[edit] This is (obviously) also reusable for when it's not available too
private void InternetConnectionUnavailable()
{
OnConnectionChanged(new ConnectionEventArgs(false));
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Thursday, October 16, 2008 1:07 PM
|
|
|
|
|
Hi,
Does someone know if it is possible to know if characters that was received, was received from the Keyboard or from the Barcode scanner?
Thanks
|
|
|
|
|
If your scanner is like ours, then no.
I would suggest you try asking the manufacturers of the scanner.
|
|
|
|
|
I am in need of the same thing. We use symbol scanners and I know that I read somewhere that most manufactures have a dll file to integrate with your applications. This hasnt been something I have looked into yet but will be very shortly. Can you let me know if you find out something, or maybe we can help each other complete this?
|
|
|
|
|
Brad,
Did you see the comment from Dave Kreskowiak, i think this will work. Your scnner should come with a form containing different bar codes. These are used to configure the scanner.
Cheers
|
|
|
|
|
Yes I saw that, and I think that is what I am going to do. I wish I did not have to do this as I like the barcode application to send just the barcode so it can work with other things I have but appears to be the only choice.
I use the POS-X Xi3000 ( http://www.posguys.com/barcode-scanner_3/POS-X-Xi3000_716/XI3000U_9177/[^] ) which is a great scanner, but I wish they had the ability to capture the scanner just like Symbol does.
|
|
|
|
|
You could try to measure the time delay between one char and another.. Barcode readers can be configurated to send the chars one after the another very quickly, humans can't
|
|
|
|
|
If it's a keyboard wedge scanner, then no, there's no way to tell.
Though, most scanners will let you setup a preamble/postamble sequence that the scanner pre-/post-pends to the data it "types", like adding "@@" to the string. So, if you scan a barcode of "123456789", the scanner actually sends "@@123456789". How I've done it in the past is to set my form's KeyPreview to True, and in the KeyDown event of the form, I look for the "@" character (in this example). If I keep getting the preamble sequence, then I know the next numbers I get are for the barcode and I redirect that data appropriately.
|
|
|
|
|
I am trying to figure out the best way to integrate this so that it can be customizable. My barcodes are always 12 characters long but you never know what might change in the future. So my thought is to look for two @@ which means were starting the barcode and then two @@ means the barcode has ended. I have activated the forms keypreview so I can now watch the keys on KeyPress. The problem I am having is trying to figure out the best way to make this dynamic and customizable by a config file incase the user wants to use three #'s instead of @.
private static string ConfigBarcodePreSuffix = "@";
private static int ConfigBarcodePreSuffixTimes = 2;
private static string Scanned_BarcodeText = "";
private static bool Scanned_BarcodeBeingScanned = false;
private static int Scanned_PreSuffixFoundTimes = 0;
private void frmEventTicketVerify_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.Equals(ConfigBarcodePreSuffix))
{
if (!Scanned_BarcodeBeingScanned)
{
if (Scanned_PreSuffixFoundTimes == ConfigBarcodePreSuffixTimes)
{
Scanned_BarcodeBeingScanned = true;
}
}
else
{
if (Scanned_PreSuffixFoundTimes == ConfigBarcodePreSuffixTimes)
{
Scanned_BarcodeBeingScanned = false;
}
}
Scanned_PreSuffixFoundTimes++;
}
else
{
Scanned_PreSuffixFoundTimes = 0;
}
if (Scanned_BarcodeBeingScanned)
{
Scanned_BarcodeText += e.KeyChar.ToString();
}
else if (!Scanned_BarcodeText.Trim().Equals(""))
{
MessageBox.Show(Scanned_BarcodeText);
}
}
I am just starting to test this code, and I am not the best at C# so if you see any improvements or bugs I would be greatful.
|
|
|
|
|
Well, I didn't do much beyond glancing at the code, but I can tell you you're going about this wrong. The prefix can be any combination of characters (usually - depends on the barcode scanner) and doesn't have to be the same character repeating. On top of that, it's not a good idea to use the same combination of chracters for the pre and postambles. You won't be able to tell the difference between the start and stop combinations.
|
|
|
|
|
Hi,
I'm new to c# and was wondering if there is a quicker way of doing to following code without using the try and catch method as it is slow.
int result;
try
{
int str1_num = int.Parse(str1.Replace(",", ""));
int str2_num = int.Parse(str2.Replace(",", ""));
if (lvi1.ListView.Sorting == SortOrder.Descending)
{
if (str1_num < str2_num)
result = 1;
else
result = 0;
}
else
{
if (str1_num > str2_num)
result = 1;
else
result = 0;
}
}
catch
{
if (lvi1.ListView.Sorting == SortOrder.Descending)
result = String.Compare(str1, str2);
else
result = String.Compare(str2, str1);
}
Cheers
Fly
hmmm pie
|
|
|
|
|
Hi,
have a look at
int.TryParse().
This will avoid using try-catch.
Regards
Sebastian
|
|
|
|
|
As mentioned in the other post, use the TryParse method.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|