|
So I was trying to convert Binary file to data.
BinaryReader Read_Binary = new BinaryReader(File.Open(@BinaryFile, FileMode.Open));
Uint32_Data = (Read_Binary.ReadUInt32());
But what I want is data in float.
eg. Uint32_Data = 1079320248
in hex = 0x40551EB8
But what I want is floating point. i.e 3.33.
The data bits are proper order. But how can I extract value in floating point.
Online Hex Converter - Bytes, Ints, Floats, Significance, Endians - SCADACore[^]
|
|
|
|
|
Hi,
if you know in advance a float is up, just use BinaryReader.ReadSingle() .
If not, you need to perform a conversion; there are a couple of ways doing this, e.g. using the BitConverter class.
Alternatively you can use a pseudo-union, as in:
[StructLayout(LayoutKind.Explicit)]
public struct Uifl {
[FieldOffset(0)]
public float fl;
[FieldOffset(0)]
public uint ui;
};
|
|
|
|
|
hi all
I am in process of preparation of an app which gives the details of a webservice - Name, ValuePair
Its some thing like this
If we input the url for the webservice. It must give the Name, Value Pair (which is extracted from the Response)
Hope i am clear and help me in this
|
|
|
|
|
Download the info from the WDSL as a string?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Member 2236419 wrote: Hope i am clear and help me in this
How?
We have no idea what you have tried, where you are stuck, or what help you want from us - you haven't asked a question at all!
All you have done is give a very, very brief outline of what you want to end up with - we don't even know where you are starting from, if teh web service exists, or what it provides if it does.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Basically assume that i have 3 webservices
1. service1
2. service2
3. service3
Now my requirement is i need to generalize the consumption of the webservice
So if i add a service reference of the webservice in the current project, and place a request to the webservice, it must give me the properties(Name and ValuePair)
of the response from the webservice.
The main intention of doing this is... in future i am expecting more webservices which will be added into my current application. So i thought of using reflection
to acheive the same but its not getting worked out.
Hope i am clear now
Kindly suggest and help me
|
|
|
|
|
Member 2236419 wrote: So i thought of using reflection to acheive the same
What OG is asking for is what have you tried, where you are getting any errors.
You are only giving him the requirement which sets the context of the problem.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Class1.cs
<pre>namespace ClassLibrary1
{
class Class1 : IGameMenuItemPlugin
{
public bool SupportsMultipleGames => false;
public string Caption => "Save";
public System.Drawing.Image IconImage
{
get
{
return null;
}
}
public bool ShowInLaunchBox => true;
public bool ShowInBigBox => true;
public bool GetIsValidForGame(IGame selectedGame)
{
return true;
}
public bool GetIsValidForGames(IGame[] selectedGames)
{
return false;
}
public void OnSelected(IGame selectedGame)
{
Apath item = new Apath
Num1 = selectedGame.ApplicationPath
var form = new Form1();
form.Show();
}
public class Apath
{
private string num1;
public string Num1
{
get { return num1; }
set { num1 = value; }
}
}
public void OnSelected(IGame[] selectedGames)
{
return;
}
}
}
form1
namespace ClassLibrary1
{
public partial class Form1 : Form
{
Class1.Apath apath1 = new Class1.Apath();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(apath1.Num1);
}
}
}
I am trying to get mesagebox to display
selectedGame.ApplicationPath but I get a blank messagebox.
Appreciate any help please.
|
|
|
|
|
Hi,
I see several issues:
1.
the code shown does not compile; there are several syntax errors in method OnSelected() .
Please show actual code, and if you consider it necessary to shorten the code, keep it correct.
2.
I fail to see the logic in your code structure: both Class1 and Form1 create a new Apath. Are you sure that is what you want? They will be distinct objects.
3.
I fail to see how your OnSelected() method will ever execute. There seems to be nothing that calls it. Therefore num1 remains at its initial value (which is null), and that is what gets shown by your MessageBox, which is kind enough to treat null as an empty string.
Suggestions:
1.
Use descriptive names, not just Form1 and Button1 .
2.
Provide some context information when asking a question here; it helps us understand what it is all about.
3.
If what you want is the path of your .exe file, you should have a look at the Assembly class and try something like
string exePath=Assembly.GetCurrentAssembly().Location;
|
|
|
|
|
In OnSelected you have some syntax errors, but it looks like you intend to create a new Apath, set its Num1, and then use that in Form1. Currently however, Form1 creates a new Apath instead of using the one from Class1.
You could pass the item in the constructor like so.
Class1.cs
public void OnSelected(IGame selectedGame)
{
var item = new Apath
{
Num1 = selectedGame.ApplicationPath
};
var form = new Form1(item);
form.Show();
}
Form1.cs
namespace ClassLibrary1
{
public partial class Form1 : Form
{
Class1.Apath apath1;
public Form1(Class1.Apath item)
{
InitializeComponent();
apath1 = item;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(apath1.Num1);
}
}
}
modified 13-Sep-18 21:01pm.
|
|
|
|
|
guys already i split the value by(,) comma . i have n number of lines with comma(,) in notepad file.
Material Name,Material Type,Length,width,thickness,Area,Initial Gauge Length,Speed,graph type,Breath
Rubber,flat,50mm,20mm,10mm,65mm,22mm,10mm,LOAD VS DISPLACEMENT,30MM
silicon,round,5mm,3mm,2mm,6MM,2MM,1MM,Stress VS Strain,3mm
now i want the separate the data from text file.i have 10 textbox. for ex : if i enter "Rubber" in a textbox then click button.another textbox filled with before comma words in that specified line only (i.e 2nd line)
now how can i get the splitted values in a textbox from seperate line in c# using text file
|
|
|
|
|
Too many questions and no code.
Show some code and ask "one or two" questions at this point; since you are practically asking someone to "answer" with a complete program.
And, only show code "relevant" to the question(s).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The simplest way is to use a CSV processor - A Fast CSV Reader[^] is a good one - and let it read the whole file into say a DataTable.
You can then use Linq or a foreach loop to find the matching text in the first column, and display the rest in your textbox.
It's pretty simple, but this smells of homework, so I'll give you no code!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In my Application, I have a WCF service. I am trying to send a Json Object and get the Json object as Response.
But every time, I am getting error "The data contract type 'TestConsole.localhostrREF4.PrimeDataProperty' cannot be deserialized because the required data members 'isPrimeResultField, isPrimeResultFieldSpecified, isPrimeResultSpecified1Field, isPrimeResultSpecified1FieldSpecified, numberField, numberFieldSpecified, numberSpecifiedInField, numberSpecifiedInFieldSpecified' were not found.
My Web Service name is "ISAJsonWebService"
Here is my code of Web Service:
IJsonWebService.cs
[ServiceContract] public interface IJsonWebService {
[OperationContract]
[WebInvoke(UriTemplate = "/GetData",
Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
PrimeDataPropertyOut GetData(PrimeDataProperty value);
}
[DataContract]
public class PrimeDataProperty
{
[DataMember]
public int number { get; set; }
[DataMember]
public bool NumberSpecifiedIn { get; set; }
[DataMember]
public bool IsPrimeResult { get; set; }
[DataMember]
public bool IsPrimeResultSpecified { get; set; }
}
[DataContract]
public class PrimeDataPropertyOut
{
[DataMember]
public bool IsPrimeResultOut { get; set; }
[DataMember]
public bool IsPrimeResultSpecifiedOut { get; set; }
}
EndPoint Code behind JsonWebService.svc.cs
public class JsonWebService : IJsonWebService
{
public PrimeDataPropertyOut GetData(PrimeDataProperty value)
{
return new PrimeDataPropertyOut
{
IsPrimeResultOut = true,
IsPrimeResultSpecifiedOut = true
};
}
}
Here is my Web Config:
<configuration>
<appsettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true">
<system.web>
<compilation debug="true" targetframework="4.7.1">
<httpruntime targetframework="4.7.1">
<system.servicemodel>
<diagnostics>
<messagelogging logmalformedmessages="true"
="" logmessagesattransportlevel="true">
<services>
<service behaviorconfiguration="serviceBehavior"
="" name="ISAJsonWebService.JsonWebService">
<endpoint address="" behaviorconfiguration="jsonEndpointBehavior"
="" binding="webHttpBinding" name="json" contract="ISAJsonWebService.IJsonWebService">
<identity>
<dns value="localhost">
<endpoint address="mex" binding="mexHttpBinding" name="mex"
="" contract="IMetadataExchange">
<endpoint address="wsHttpBinding" behaviorconfiguration="wsHttpBinding"
="" binding="wsHttpBinding" bindingconfiguration="" name="wsHttpBinding" contract="ISAJsonWebService.IJsonWebService">
<identity>
<dns value="localhost/wsHttpBinding">
<behaviors>
<endpointbehaviors>
<behavior name="jsonEndpointBehavior">
<webhttp>
<behavior name="wsHttpBinding">
<servicebehaviors>
<behavior name="serviceBehavior">
<servicemetadata httpgetenabled="true">
<servicedebug includeexceptiondetailinfaults="true">
<system.webserver>
<modules runallmanagedmodulesforallrequests="true">
<directorybrowse enabled="true">
I am trying to Consume the web service from a Console App.
Here is the code:
static void Main(string[] args)
{
localhostrREF4.JsonWebService jsonWebServiceRef = new
localhostrREF4.JsonWebService();
PrimeDataProperty pdp = new PrimeDataProperty { number = 1,
NumberSpecifiedIn = false, IsPrimeResult = false, IsPrimeResultSpecified
= false };
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer serializer = new
DataContractJsonSerializer(typeof(PrimeDataProperty));
serializer.WriteObject(ms, pdp);
byte[] data =
client.UploadData("http://localhost:65256/JsonWebService.svc/GetData",
"POST", ms.ToArray());
Stream stream = new MemoryStream(data);
var obj = new DataContractJsonSerializer(typeof(PrimeDataProperty));
**var returnPrimeDataProperty = obj.ReadObject(stream) as
PrimeDataProperty;**
}
in the last line (Bold Text) is throwing exception.
Please let me know, what I am missing.
Thanks.
|
|
|
|
|
Start by looking closely at the source app, and find out exactly what class(es) it is including in the JSON data. Then look very closely at those classes, and check that the JSON contains exactly what you expected.
Then look at the destination app, and the matching classes there: if they do not contain exactly the same classes, with exactly the same properties, this is the error you will get.
What the error is saying is: "the source and destination classes are not the same" - the destination has missing or added properties.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
Thanks For your reply.
Parameter names ending with "specified" added in the DataContract class in Reference.cs file after adding the WebService in the main application( WebService Consume).
I found that is making difference.
But how to get rid of that?
Thanks.
|
|
|
|
|
I have been familiarizing myself with this, but keep thinking that ... given the efficiency of .NET's hash-based data structures ... unless I had a huge SortedList<TKey, TValue> list, frequently accessed, with a large percentage of accesses matching the sort-order ... that I might as well use a hash-based solution.
On the "plus side," SortedList offers some nice facilities, like 'IndexOfValue, and it's easy to work-around having duplicate keys by using a custom IComparer<TKey> implementation.
Of course, if you choose to allow duplicate keys: changing the value associated with the key does not resort the list; to force a re-sort you have to remove the Key-Value pair, change the Value, and then, add the modified Key-Value pair back to the list.
Appreciate hearing from you about the strategic use of this data-structure.
thanks, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 5-May-18 14:54pm.
|
|
|
|
|
All my use seems to center around transporting "series data" from various sources into my "charting components"; mostly of the form SortedList<object,object>; i.e. <x,y>.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks, Gerry, I am interested in why you chose a SortedList for this task; I assume 'x,y' refers to a list of discrete 'Point (i.e., not deltas) whose magnitude fits some-axis order.
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
What JSchell said.
Every charting software "warns" about "unsorted" series data (performance).
In this case, "time-series" data.
One looks at the data; one looks at the charts; one looks at reports.
Everything is practically screaming: "sorted the same".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yep, and that's kind of what I implied in my comment:
I assume 'x,y' refers to a list of discrete 'Point (i.e., not deltas) whose magnitude fits some-axis order. But, let me ask you to respond to what I said to JSchell:Quote: think one additional factor in ... perhaps ... making a SortedList a less viable choice in many situations is the ease of sorting, and/or grouping, etc., using Linq.
What do you think ? thanks, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
(And that's what I implied with "series data" and "charting components").
Re: SortedList
It's a "message" to whomever contemplates that "list" outside of its immediate context.
It's more "intuitive" in terms of its purpose.
It's a (sort of) "typed" list.
Your position seems to be you can always "sort" it. It's a questionable strategy when there is little practical use "unsorted".
What about debugging? Why contend with unsorted data even in memory when it makes it more difficult depending on the situation?
Chunked real time data capture? You want to remember to "sort" everytime? Even just to look at it?
You're trying to generalize something which varies in "value" depending on the situation; while value is in the eyes of the beholder and their "requirements".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: You're trying to generalize something which varies in "value" depending on the situation; while value is in the eyes of the beholder and their "requirements". Uh, no, I am seeking information from my peers, and mentors, here, regarding their use of generic SortedList<>.
With your current response, I am finally getting information from you, and I am up-voting this response
thanks, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
BillWoodruff wrote: given the efficiency of .NET's hash-based data structures ... unless I had a huge SortedList<TKey, TValue> list, frequently accessed, with a large percentage of accesses matching the sort-order
Vast majority of time if "efficiency" is an actual versus hypothetical concern especially in terms of access then the design probably needs to be looked at.
I have used sorted collections because I don't want to figure out how to sort them latter. No consideration at all for efficiency either for individual look up or impacts on insertions. Far as I can recall it was usually because the UI needed it sorted although at least one occasion it was simply because I wanted to log it and wanted it in sorted order.
Very few cases where efficiency was a concern I didn't sort it.
|
|
|
|
|
Thanks, JSchell,
I think one additional factor in ... perhaps ... making a SortedList a less viable choice in many situations is the ease of sorting, and/or grouping, etc., using Linq.
What do you think ?
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|