|
Kiotaya wrote: (Byte)(Encoding.UTF7.GetBytes(RequestMessage.Substring(i, 1))[0]
This does not seem right: you choose UTF7 encoding, however for each string character you only use the first byte GetBytes returns.
You should have two distinct steps:
- represent your string as a byte array in the encoding of your choice;
- calculate LRC on that byte array.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Thank you for your response Luc. However it looks like what you are telling me is what I did in the second example I show. Please correct me if I am wrong in this assumtion. Here is the second example.
RequestMessage contains Message+ETX only
public static char theReturnLRC(string RequestMessage)
{
int lrcAnswer = 0;
byte[] byArray = Encoding.UTF7.GetBytes(RequestMessage);
foreach (byte curByte in byArray)
{
lrcAnswer ^= curByte;
}
return (char)lrcAnswer;
}
char charLrc = ReturnLRC(Trans);
string lrcString = charLrc.ToString();
byte[] LRC = unicode.GetBytes(lrcString );
fullMessage[addLRCHere] = LRC[0];
|
|
|
|
|
OK, two comments:
1.
Kiotaya wrote: string lrcString = charLrc.ToString();
byte[] LRC = unicode.GetBytes(lrcString );
fullMessage[addLRCHere] = LRC[0];
what is all this stuff? you perform calculations on bytes, turn the result in a char, then a string, then a byte array, and then take the first byte. Why can't theReturnLRC() just return the byte result for immediate use?
2.
Your LRC is starting from zero, and XORing the bytes. There are hundreds of "standard" checksums and the like (using XOR or ADD; using left shifts, with recycling some carry, etc). Are you sure this is the one you need? Can you confirm with a few simple examples that are known to be good?
This[^] says "...may be computed in software by the following algorithm...". While this[^] uses a different definition.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I forgot one remark:
if (I don't know, you haven't told us enough to be sure) your communication is basically binary possibly with an occasional letter or word embedded in it, then you should not be using any strings at all, instead you then should be using byte[] exclusively.
Do you have the full specification?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I am going to be running some more tests today. I will give you more details this afternoon. Thank you very much for your help and time.
|
|
|
|
|
Sorry I didn't reply to this much sooner but the help you game me help me clear up this problem.
Thanks Luc Pattyn and everyone else.
|
|
|
|
|
Hello would you be able to post the solution for this?
I have a scenario where its been mentioned that my message will be sent in the following format
STX Data ETX BCC
And that BCC = LRC - XOR over all characters excluding STX but including ETX.
I am kind of trying to figure out how this works?
Here is the LRCCalculation method I have implemented.
private char CalculateLongitudinalRedundancyCheck(string source)
{
int result = 0;
for (int i = 0; i < source.Length; i++)
{
result = result ^ (Byte)(Encoding.ASCII.GetBytes(source.Substring(i, 1))[0]);
}
return (Char)result;
}
I get the LRC from this and then what...!!
For ex: say my data is something like "345565645023495767714.12.1988021114:33 15.8001".
|
|
|
|
|
I land to the same issue.
Guys how did you resolved it?
|
|
|
|
|
I've tried writing an application that is using WIA in Windows 7 and i get the classic
Exception from HRESULT: Ox80210015 which means that my cameras don't support WIA. But i've moved run the exe on my eeePC and it works. So my question is does anyone know if there are any problems with Windows 7 and WIA ?
|
|
|
|
|
I have the same problem. Works fine on XP SP3 but
no luck on Win 7!
Did you get anywhere with this?
|
|
|
|
|
Unfortunelty no, but i'm not quite sure that it's Windows 7, because i connected my Nokia Cell Phone via bluetooth by mistake and it worked as in i stop getting the error, beacause WIA reconised my phone cam. So it think that it might not be Windows 7 but the webcams that i was using (the funny this is that one of the is from Microsoft).
Maybe the drivers for the camera might be outdated.
But to be honest i not really sure what it the problem. If you find out anything please let me know
|
|
|
|
|
Hi
I have the code to make the backup of the MySql database like this..
try
{
DateTime backupTime = DateTime.Now;
int year = backupTime.Year;
int month = backupTime.Month;
int day = backupTime.Day;
int hour = backupTime.Hour;
int minute = backupTime.Minute;
int second = backupTime.Second;
int ms = backupTime.Millisecond;
String tmestr = backupTime.ToString();
tmestr = "C:\\" + year + "-" + month + "-" + day + "-" + hour + "-" + minute + ".sql";
StreamWriter file = new StreamWriter(tmestr);
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} > {4};", "root", "password", "localhost", "dbfile", "backup.sql");
proc.FileName = "mysqldump";
proc.RedirectStandardInput = false;
proc.RedirectStandardOutput = true;
proc.Arguments = cmd;//"-u root -p smartdb > testdb.sql";
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = p.StandardOutput.ReadToEnd();
file.WriteLine(res);
p.WaitForExit();
file.Close();
}
catch (IOException ex)
{
MessageBox.Show("Disk full or other IO error , unable to backup!");
}
}
while executing the program it is showing an error as shown
"The system cannot find the file specified" with caption "Win32Exception was unhandled "...
can anyone help todo this.....
|
|
|
|
|
same question as yesterday.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi
I have windowsApplication program and i have sql 2005 database;
my database doesnt have password;
what is my connectionstring?
Is it correct? "Data Source=.;Initial Catalog=" + System.Windows.Forms.Application.StartupPath
+ "\\Data\\kazemi.mdb;" +
"Integrated Security=true;";
|
|
|
|
|
Initial Catalog = DBName(just your database name is ok, the path is not necessary),and even if your database doesnt have password,i think you should add user id here(uid = logid)
|
|
|
|
|
I Found a lot of articles explained how to store and retrieve a image into /from DB.They are helpful.But I got a problem when i used the same way to deal with a MPG picture.
First,I upload a mpg picture ,convert it into byte[],and store it into my DB,until now ,it's working well.
Then,I just need to convert the byte[] back to a MPG picture,as follows:
byte[] b = (byte[])cmd.ExecuteScalar();
if(b.Length >0)
{
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(b, 0, b.Length);
Bitmap bmp = new Bitmap(stream)//Exception is threw here
//using Image img = Image.FromStream(stream )is the same;
}
I have found out mpg was not included in ImageFormat.So,what type is mpg,and how can get it from byte[]?
modified on Sunday, November 8, 2009 12:58 AM
|
|
|
|
|
|
Thank you very much ,and ,the link is helpful.
|
|
|
|
|
In CR XI it is possible to adjust the x position conditionally. But is it also possible to adjust the y position conditionally?
For my report i need to adjust the position of a field based on it's value.
I have needed to conditionally adjust the x and y position of fields. Is this possible? If Yes How? Please reply me.
|
|
|
|
|
I tried to test a simple BHO but it doesn't seem to work very well.
I compiled the .dll and registered using regasm, the BHO appears in the IE Addons (or complements, i have it in spanish) page, and it says "Enabled" but when visiting any site I am not getting the message box I should get (it's a simple message for testing if the bho works), could someone take a look at it?
I uploaded my visual project here.
http://sites.google.com/site/oscodes/ClassLibraryTest.rar?attredirects=0&d=1[^]
It doesn't have much code just the necessary for a simple test, I can't find why it's not working.
Any help will be appreciated.
Regards.
|
|
|
|
|
This may be a stupid question for some of you, but I really am unsure how to start learning the information I want to learn.
I really want to know how to access webcams and other USB devices without the use of frameworks in C#. For example, you have aforge that makes it easy to access your webcam, and you have directshow that does that same. But how do those frameworks gain the ability to access these devices? I know this is getting into COM development most likely, but I would like any direction someone could give as to how I can start learning how to do this in C#.
Thanks!
|
|
|
|
|
It is physically impossible to access a camera without DirectX or WIA. Why ? Because web cams did not exist when Windows was created, these are things that have been added to Windows to add the ability to access these peripherals.
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.
|
|
|
|
|
Ohh.. so even major applications like aim, skype, communicator even use DirectX or another library to help access webcams? I've been reading the books I have purchased but none of them really got into Dllimports or any unmanaged coding with C#. I'm just tryin to learn as much as I can. I'm in school but they seem to not teach that advanced as I've already taken all of the classes lol.
|
|
|
|
|
Jacob Dixon wrote: Ohh.. so even major applications like aim, skype, communicator even use DirectX or another library to help access webcams?
Absolutely.
Jacob Dixon wrote: I've been reading the books I have purchased but none of them really got into Dllimports or any unmanaged coding with C#.
www.pinvoke.net[^] is a great resource for dll stuff. Also, there's a couple of full libraries that import all of DirectX into C# about, I've used those before, and they work well.
Jacob Dixon wrote: I'm in school but they seem to not teach that advanced as I've already taken all of the classes lol.
*grin* well, perhaps that means you're the one who is likely to actually become a programmer. It's generally good to pull things apart and work out how they work, not just use code people give you or that you find, but you won't gain much from trying to go more low level than just finding an article on CP on C# and webcams, and using whatever method they use to get access to Direct X, I believe the DirectX library I was talking about gets used a lot, and that it also has a CP article.
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.
|
|
|
|
|
Thanks!
I will check out the pinvoke.net!
Well I can tell you everything I have learned is from books and just trying to get it to work. I know I have posted a lot in the past here on CP and you guys have helped me out with my problems. I love to code. Its not part of my job right now but I do as much of it as I can at work and home to help out. My fear is not being able to find a job as a programmer since I personally feel my experience is not good enough even though I will have "paper" that says I can.
One day I am hoping to be able to assist in writing applications that are widely used.
I have checked out some of the DirectX articles and found that the ones I did try had issues with accessing some webcams (like iSight on iMac in windows mode). I had good luck with AForge in that area. I was just hoping to learn more how the library worked in doing what it did.
Anyways thanks again!
See you around!
|
|
|
|