|
Hi all,
i need to send a data message to a device every data message must have its header.
byte[] messageheader;
messageheader= new byte[10];
messageheader[0] = 0x16;
messageheader[1] = 0x01;
messageheader= BitConverter.GetBytes(01);
messagehd[3] = 02;
messageheader[4] = 00;
messageheader[5] = (byte)(message.Length);
serialPort1.Write(messageheader, 0, messageheader.Length);
now the BitConverter delete every thing, i think this is very simple, but I'm struggling with it
thanks in advance.
modified on Wednesday, January 7, 2009 3:31 AM
|
|
|
|
|
A4ad wrote: messageheader= BitConverter.GetBytes(01); // this must be divided into two bytes within the array
Since BitConverter.GetBytes() returns an array, your messageheader gets reassigned, thus losing the reference created 3 lines above. What you need to do is:
byte[] messageheader = new byte[10];
messageheader[0] = 0x16;
messageheader[1] = 0x01;
Array.Copy(BitConverter.GetBytes(01), 0, messageheader, 2, 2);
messagehd[4] = 02;
messageheader[5] = 00;
messageheader[6] = (byte)(message.Length);
serialPort1.Write(messagehd, 0, messagehd.Length);
|
|
|
|
|
thank u for your answer, it helps me a lot...
but is it an issue if id do the array copy, for the whole array. i don't think it will effect the performances of my application, but it looks to me that is not the write way to do this for the array.
|
|
|
|
|
The performance difference between copying 2 bytes and 4 bytes is insignificant, but you should take the habit of not doing more than necessary.
|
|
|
|
|
Please for good people - only - how to change computer name by c# , i found many codes but all is not working well.
thanks & regards
|
|
|
|
|
|
Hi,
SetComputerNameEx[^] should do it, however you must restart the system to make it work!
|
|
|
|
|
Dear All,
I have created a setup project using vs 2005 and i want to install another .exe file after finishing my c# application setup.I am getting the .exe file as embeded resource to my project.
now using Installer when i use to run the .exe file after installation, it gives me an error file not found. I know the Error is that it can not locate or find the .exe file which i am installing after c# application.
I am asking how to get the installation path (folder which i am installing the application)?
I use Application.startup, but it did not help.
Remember that the .exe file which i am installing is inside that installation folder.
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Abdul Rahman Hamidy wrote: I am getting the .exe file as embeded resource to my project.
Which project?? Is it the C# app, or it's installer project??
If you've got a seperate .EXE, unpack it and make it a part of your app's installer project. There's no need to keep it as a resource in your app.
|
|
|
|
|
well i added the .exe file into my setup project (the one which i created through setup and deployment)
the .exe is now added to computer Application Folder like (c:\programe files\company Name\Application) through installing setup project.
How can i get this path from installer class to execute this .exe when c# application setup finished?
Abdul Rahaman Hamidy
Senior Student Student in Computer Science
Kabul, Afghanistan
Software Developer
|
|
|
|
|
Well, that changes the question entirely. AFAIK, there's no support for this in the Visual Studio installer project. The reason being, the last time I tried this (a LONG time ago), the installer waited for the application to close on first launch. This caused some rather serious "issues" because of the nature of the environment.
AFAIK, you'd have to modify the installation using an external utility, like Orca or InnoSetup, to make this kind of change. See this[^] post.
|
|
|
|
|
Hi,
I am facing with a performance issue in one of my windowsapplication.
I need to create a dialog window for excluding subfolders and files in a particular folder (passed as input).
The Exclude dialog must allow the user to select folders and files which he wants to exclude from counting.
Currently I am using a tree view and list view (both with checkboxes) for this purpose.
<br />
Implementation:<br />
1. I bind the tree view with all subfolders on the load time.<br />
2. The list view shows the files and folders of each selected node in the tree.<br />
3. When a node or list item checked or unchecked, all its sub-items has to get checked or unchecked.<br />
<br />
Issue faced:<br />
1. In case of a large folder (with large no. of Subfolders and files), it takes long time for loading the tree (to bind all these sub-folders and files to tree)<br />
2. If I go for an implementation of binding only two levels to the tree node each time (on load and on node click), issue occurs when I uncheck a node or list item. Only the sub items up to 2 level gets unchecked.<br />
3. Check- Uncheck for large subfolders too takes long time.<br />
<br />
Can anyone help me out with a solution for this? Even a design change or change in the current implementation can be suggested.
Thanks in Advance
Praji
|
|
|
|
|
KP_Prajilal wrote: In case of a large folder (with large no. of Subfolders and files), it takes long time for loading the tree (to bind all these sub-folders and files to tree)
You could fill the node when it's opened. Just fill the root and perhaps some child levels in the beginning
KP_Prajilal wrote: If I go for an implementation of binding only two levels to the tree node each time (on load and on node click), issue occurs when I uncheck a node or list item. Only the sub items up to 2 level gets unchecked
You can either fill the child nodes for the selected node upon selecting but you can also change the logic so that if the child nodes aren't filled, the outer node selection automatically implies to all subfolders even if they are not in the tree. So when working on user's choices (what ever you do with them) you don't expect to find every folder in the tree.
|
|
|
|
|
I want to bind all the sub folders and file of a root folder when selecting it.
Could u please give me a sample code?
|
|
|
|
|
The idea was that you don't take all the folders to the tree, only the nodes are selected. You can use BeforeExpand[^] event and in that event you fill the folders right under that node (if not already filled).
When you perform the operation (whatever it is) you check if the node is present and based on the selection you do the operation. You can use recursion in the operation just check if node is selected and if it is, recurse child nodes if there are any. if there aren't recurse, the folders under that folder and do the operation if the node was selected.
|
|
|
|
|
I tried it and got better performance while binding the folders. But when Check/Uncheck a root folder performance is too low(for Check/Uncheck the sub folders). How can i solve this?
Thanks in Advance
Praji
|
|
|
|
|
DJ245 wrote: But when Check/Uncheck a root folder performance is too low(for Check/Uncheck the sub folders). How can i solve this?
Without seeing the code you've made, it's quite impossible to say why it's slow. When the root node is checked, do you for example recursively traverse all of the subnodes and check them also? That would explain why it's slow. Also if that's the case, it depends how you have done it. Can you post the code that is used when checking a node?
|
|
|
|
|
Code used :
#region CheckUncheckChildNodes
private void CheckUncheckChildNodes(TreeNode node)
{
childCheck = true;
if (node.Checked == true)
{
bool isExists = false;
for (int index = 0; index < removedFileList.Count; index++)
{
string name = removedFileList[index].ToString().Replace("\\\\", "\\");
if (name == node.FullPath)
{
isExists = true;
break;
}
}
if (isExists)
removedFileList.Remove(node.FullPath);
CheckUncheckFilteredFiles(node, node.Checked);
foreach (TreeNode childNode in node.Nodes)
{
childNode.Checked = true;
CheckUncheckChildNodes(childNode);
}
}
else
{
bool isExists = false;
for (int index = 0; index < removedFileList.Count; index++)
{
string name = removedFileList[index].ToString().Replace("\\\\", "\\");
if (name == node.FullPath)
{
isExists = true;
break;
}
}
if (!isExists)
removedFileList.Add(node.FullPath);
CheckUncheckFilteredFiles(node, node.Checked);
foreach (TreeNode childNode in node.Nodes)
{
childNode.Checked = false;
CheckUncheckChildNodes(childNode);
}
}
}
#endregion
#region CheckUncheckFilteredFiles
private void CheckUncheckFilteredFiles(TreeNode tnSubNode, bool checkedState)
{
trvSource.ImageList = sysIcons.SmallIconsImageList;
bool isDirectory = false;
DirectoryInfo diRoot;
diRoot = new DirectoryInfo(tnSubNode.FullPath);
string allFiles = string.Empty;
FileInfo info = new FileInfo(tnSubNode.FullPath);
string ext = info.Extension;
if (tnSubNode.FullPath != string.Empty)
{
if (File.Exists(tnSubNode.FullPath) || Directory.Exists(tnSubNode.FullPath))
{
FileAttributes attrb = File.GetAttributes(tnSubNode.FullPath);
if ((attrb & FileAttributes.Directory) == FileAttributes.Directory)
{
isDirectory = true;
}
else
{
isDirectory = false;
}
}
}
if (isDirectory)
{
DirectoryInfo[] dirs = diRoot.GetDirectories();
FileInfo[] fils = diRoot.GetFiles();
ArrayList directoryFiles = new ArrayList();
ArrayList excludedDestFiles = new ArrayList();
for (int index = 0; index < fils.Length; index++)
{
directoryFiles.Add(tnSubNode.FullPath.ToString() + @"\" + fils[index].ToString());
}
ArrayList allFilesInDirectory = directoryFiles;
excludedDestFiles = GetExcludedFiles(ref allFilesInDirectory);
foreach (FileInfo fil in fils)
{
TreeNode subNode = new TreeNode(fil.Name);
subNode.ImageIndex = sysIcons.GetIconIndex(fil.FullName);
subNode.SelectedImageIndex = sysIcons.GetIconIndex(fil.FullName);
if (isParserSelected)
{
for (int fileIndex = 0; fileIndex < allFilesInDirectory.Count; fileIndex++)
{
allFiles = allFilesInDirectory[fileIndex].ToString().Replace("\\\\", "\\");
if (allFiles == fil.FullName)
{
if (!treeClick)
{
bool isExist = false;
for (int index = 0; index < removedFileList.Count; index++)
{
if (removedFileList[index].ToString() == fil.FullName)
{
isExist = true;
break;
}
}
if (!isExist)
{
if (!checkedState)
removedFileList.Add(fil.FullName);
}
else
{
if (checkedState)
removedFileList.Remove(fil.FullName);
}
}
}
}
}
}
}
}
#endregion
|
|
|
|
|
Lets start with the CheckUncheckChildNodes method.
You have an array removedFileList . Instead of using an array and always looping through it, use for example HashTable. Something like this when you add new files to the list (or whatever code you use when you add to the array):
private System.Collections.HashTable removedFileList = new System.Collections.HashTable();
...
removedFileList.Add(node.FullPath, "");
Now when you have the CheckUncheckChildNodes method, you could modify your code to this:
...
if (removedFileList.ContainsKey(node.FullPath))
removedFileList.Remove(node.FullPath);
CheckUncheckFilteredFiles(node, node.Checked);
...
The same applies to the else section if the selected node is not checked.
That would speed up the execution and use less code. The same idea can be used in CheckUncheckFilteredFiles
|
|
|
|
|
Changed my code . But no improvement. Performance is same as previous.
|
|
|
|
|
One question is that do you still have all the files and directories initially in the tree view. I'm asking this because both listview and treeview can handle few thousand rows. After that the performance degrades radically.
The next step is that is the CheckUncheckChildNodes method slow or the CheckUncheckFilteredFiles method? I would guess that it's CheckUncheckFilteredFiles. You can try this by commenting out the call to CheckUncheckFilteredFiles from CheckUncheckFilteredFiles.
I figured out that you're listing both files and folders in the same treeview but you exclude some files based on their extension or is it vice versa, if the user has selected a parser, do you show only files with certain extension? If you show only certain extensions, use serchpattern on GetFiles
Then you also show an icon based on the file. However did I understand correctly that you have a separate icon for every file??
subNode.ImageIndex = sysIcons.GetIconIndex(fil.FullName)
Also I don't seem to find that you are clearing subnodes anywhere so if the directory is read twice, won't you have duplicate rows on the tree?
One way to enhance the performance is to use a tree for folders only and a list view for files, same as Windows Explorer. By separating them you wouldn't have so many items in the tree.
Also, what's the whole idea. You have a form where you have a combobox? for parser selection. After selecting the parser, user can select what files are parsed? All the files that are selected are parsed and if a node is parsed then every file in that node and it's subnodes are parsed? Was that even close?
|
|
|
|
|
I used this to count the LOC of a whole project. For example my project folder contains around 250 folders and 25000 files. A tree view is used to list out the folders with check boxes and a list view to display all the files under selected folder.
Both the two functions are slow. Main form contains a combo box for parser selection and another combo box for selecting folder.
|
|
|
|
|
Byte c_sum;
c_sum = 0;
I got this error when assign c_sum =0. Really can not understand why?
|
|
|
|
|
The second line is a statement, not a declaration. Statements has to be inside a method.
Perhaps you meant to use an initializer in the declaration:
byte c_sum = 0;
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
No, it did not work. My code suddenly have so many funny errors like that ?
|
|
|
|