|
Hi Jason
Thank you for your input, appreciated!
Unfortunately, I did not write the firmware for the device. It uses feature reports as a 'bidirectional' report instead of input/output reports.
I have already implemented a polling solution, with best guess of how long to wait for, and what the polling frequency should be.
It works, but burns a lot of clock cycles in an already loaded system.
Thanks again and good luck with the fireworks - be careful 
|
|
|
|
|
Ugh! Why do some vendors insist on doing things their own way instead of the way everyone else in the world does it!
Good luck. Polling is always a fine art of balancing responsiveness against overhead.
Thanks for the good wishes. We are buried in snow here in the Midwest US and I am VERY ready for fireworks season to return!
|
|
|
|
|
What about polling in a different thread and adding a custom event when data are available? With the current multi-core computers, that should help to remove load from the main (UI) thread of the application. Beware of Control.Invoke/BeginInvoke when you then update the UI on data received from the device.
|
|
|
|
|
Hi all,
I'm trying to build a SOAP message from scratch in C# for a webservice-consuming application. The WSDL provided for the service specifies using as a paramter to a particular method a class generated by the WSDL that includes roughly 70 different properties. When such a class is returned as the result of a method on this webservice, the proxy has no trouble moving the data from the SOAP message into this class, regardless of whether all 70 properties are present or not. Those missing fields are represented in the incoming message as self-closing tags. However, when the proxy generates a SOAP message *to* the webservice using this class, generating self-closing tags for empty fields, the webservice rejects the call. It's only when it's presented with non-empty tags--and at that, not all of the properties, if they contain a value, will be accepted--will it accept the message.
About 6 months ago I figured out how to create the message from scratch in C#, using the HttpWebRequest/Response classes (I think so, anyway), but since then I've lost those code files and can't figure out how I did it. Does anybody have an example of how to do it? Or, even better, any suggestions about what I can do to force the proxy to ignore empty properties when creating the SOAP message?
|
|
|
|
|
If all else fails you could of course just hand craft everything.
So rather than trying to use the C# soap classes just use http or even TCP and just create exactly the SOAP that you need.
|
|
|
|
|
That's what I'm working on right now, actually. I suppose the most specific my question could be is this:
Given a class with various members, how can I turn that into a SOAP message? For instance, if my class is wsRecord, and wsRecord has a String field called ID, a String field called Title, a DateTime field called RecordDate, and a String field called Comments, how do I put that into the message? None of the examples I've found online include any messages, only empty requests that return a response.
|
|
|
|
|
Easiest way I have found to do this.
- Create something that you know works to the target system using the existing API libraries
- Get it to work so it sends and receives.
- Set up a packet capture tool
- Run the message and capture the packets.
- Use the packets to create your HTTP message.
|
|
|
|
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
long Totbyte = 0;
DirectoryInfo da = new DirectoryInfo("C:\\Folder");
FileInfo[] Arr = da.GetFiles();
foreach (FileInfo ap in Arr)
Totbyte = ap.Length;
Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
string temPath = Path.GetTempFileName();
string temPath2 = Path.GetTempFileName();
if (File.Exists(temPath))
{
byte[Totbyte] data = File.ReadAllBytes(temPath);
File.WriteAllBytes(temPath2, data);
}
}
}
}
|
|
|
|
|
computerpublic wrote:
Well, it runs, but it might not be doing what you think it's doing. You're displaying the length of the last file in the directory, but your loop and variable name suggest you want to display the total length of all files in the directory. That's quite a simple change:
foreach (FileInfo ap in Arr)
Totbyte += ap.Length;
Note the "+=" instead of just "=".
computerpublic wrote:
Firstly, what would the length of the files in C:\Folder have to do with the length of a temporary file?
Secondly, the ReadAllBytes method will return an array of the correct size to contain all of the bytes in the file you're reading. You don't need to specify the size of the array.
byte[] data = File.ReadAllBytes(tempPath);
Thirdly, since you're just copying one file to another, why not simple use the File.Copy method?
if (File.Exists(temPath))
{
File.Copy(temPath, temPath2, true);
}
Finally, look at the documentation of GetTempFileName :
Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
That means that temPath will always exist, and will be an empty file. Copying it over another empty file will have no effect.
Perhaps if you explain what you're trying to do, we might be able to point you in the right direction.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I already have the file on my computer. I do not want to read the file to my computer. I want to read the file into an array. I did not know that the array would automatically be the right size. I do not know which of the identifiers is the array. How do I go about accessing the array.
|
|
|
|
|
It's still not clear what you're trying to achieve.
If you want to read the content of a binary file:
byte[] data = File.ReadAllBytes("C:\Folder\TheFileToRead.ext");
for (int index = 0; index < data.Length; index++)
{
byte theByteAtThisIndex = data[index];
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Your explanation is great. I know I am using a byte array (I don't think a bit array exist), but how do i go about accessing the bits of each byte in the array?
|
|
|
|
|
|
You can use the BitArray class to treat the array of bytes as an array of bits.
byte[] data = File.ReadAllBytes("C:\Folder\TheFileToRead.ext");
BitArray dataAsBits = new BitArray(data);
See BitArray Class[^]
Note the order of the bits in the bytes!!
|
|
|
|
|
Upvoted ! At the time I wrote my response to this thread, Richard's reply was not available here, which is becoming all too typical: there is often a gap of hours before content on QA and Forums shows up, and, yet, other parts of CodeProject seem to be updated instantly.
Had I seen Richard's response, I would not have posted.
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
I can't understand what you are trying to do here:
1. you get a Directory, and then you iterate over all its files setting a variable to the current file length: which means the value of 'Totbyte is always going to be equal to the length of the last file read.
Did you mean to make a total of the length of all files ? in which case you should have: Totbyte += ap.Length; ?
2. then you create two temporary files, and check if one of them exists, and read its bytes into a byte[], which makes no sense, since the temp file will have no content.
Isn't it the case that the file (files ?) you want to read have something to do with the first part of your code, where you create an array of files from a Directory path ?
“But I don't want to go among mad people,” Alice remarked.
“Oh, you can't help that,” said the Cat: “we're all mad here. I'm mad. You're mad.”
“How do you know I'm mad?” said Alice.
“You must be," said the Cat, or you wouldn't have come here.” Lewis Carroll
|
|
|
|
|
Ideally what I am trying to do is copy of a file off my desktop in an Array of Bits (not Bytes). Can you please explain how this can be done?
|
|
|
|
|
Richard Deeming already gave you the answer to this.
You could use the BitArray class[^] to give you access to the bits in each byte, but it's not exactly what I would call "efficient".
You would still have to read the file into a byte array and then pass the byte array to the BitArray constructor.
|
|
|
|
|
I really should have read all of the comments before posting my (redundant) suggestion of BitArray.... 
|
|
|
|
|
Dear All,
I am using Visual Studio 2010 ultimate, C# language and MySql as backend database.
I've a Voucher Form, which is Master Detail. After user enters voucher data, he save the data in database by clicking save button. Now I need to add a post button, which when click perform a update to Voucher record and mark it as POSTED. This is not an issue as it simply required an Sql update statement.
What I need is a way, that after POSTED is marked, no one can edit the record, even when it is search by any user. What is the best way to do it? Are programmers do it by setting readonly property of controls true/false? Or there are other options available?
Any ideas/suggestions/samples much appreciated.
Best regards
Ahmed
|
|
|
|
|
ahmed_one wrote: What I need is a way, that after POSTED is marked, no one can edit the record, even when it is search by any user.
Can this be clarified a little please? There are a few different potential problems here. First off, what do you mean by "no one can edit the record"? The database admin is going to be able to edit the record, one way or another. If you mean users should not be able to edit the record, then you are in control of what they do in the application, so you must have enabled the ability to updated? I don't know why searching alters the record (as your comment seems to suggest) - this sounds like something is very wonky to me, or you don't mean database record. It might be better to expand on your question.
ahmed_one wrote: Are programmers do it by setting readonly property of controls true/false? Or there are other options available?
Yes, it is possible and normal to do this (normally a check-box). The other options depend on what you need so no-one can answer that for you, you might want to consult the people you are writing the software for.
|
|
|
|
|
Keith Barrow wrote: ahmed_one wrote: What I need is a way, that after POSTED is marked, no one can edit the record, even when it is search by any user.
Can this be clarified a little please? There are a few different potential problems here. First off, what do you mean by "no one can edit the record"? The database admin is going to be able to edit the record, one way or another. If you mean users should not be able to edit the record, then you are in control of what they do in the application, so you must have enabled the ability to updated? I don't know why searching alters the record (as your comment seems to suggest) - this sounds like something is very wonky to me, or you don't mean database record. It might be better to expand on your question.
By "No one can edit the record" I mean users. Database admin surely can alter the data. That's not a problem. At present, searching is not altering the record, my requirement is: when POSTED is marked users are restricted to Add/Edit/Delete/Update that POSTED record. This means when user use find function to display record (which is POSTED now) in Winforms, it should be locked for ADD/EDIT/DELETE/UPDATE.
|
|
|
|
|
It's been a long time since I've done any winforms, but in principal I'd:
- Extract the UI that allows viewing/adding/updating the record as a control.
- Set the control from above's enabled state to false - this will disable the control
- Show/hide buttons in the control as appropriate
Another option is to create two controls - one for add/edit the other for view only and display the relevant one. Depending on what you are doing, you can usually improve the user experience, though at the cost of extra work, so you need to balance these off with eachother.
|
|
|
|
|
Thanks for your reply,
Are there any option available via Sql, when user find the record, the find function should call a function which fetch data from MySql Db in read-only mode.
|
|
|
|
|
ahmed_one wrote: Are there any option available via Sql, when user find the record, the find function should call a function which fetch data from MySql Db in read-only mode. If you only "SELECT" data it will always be readonly. Simply don't update the data.
No, MySQL has no magic functions.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|