|
Oh I am sorry.
The exception is raised when I try to write the struct in memory mapped file i.e. this line - SharedData.Writer = MemWriterObj;
I have marshalled mystring hoping that it would solve the problem but it doesn't.
Any idea how I can make it work?
|
|
|
|
|
|
Thank you.
But I have already checked this, it shows how to write struct having int(which I am able to do successfully), I want to write a struct having string.
|
|
|
|
|
Well, as explained, you can't; you can only write value types in a struct. If you want to write a string then you need to use one of the alternate methods, as shown in the article.
|
|
|
|
|
Basically what the error is saying is "you can't do that at all".
A struct is a value type - it contains all it's information directly within the struct itself, and teh size is always fixed at compile time. "Basic types" such as int, float, and double are also value types.
A string is a reference type - the variable you declare is not the string itself but a reference to the memory that actually contains the string data - the reference itself is a fixed size, but teh data it refers to is not.
The error message is saying "you can only give me fixed size data" - a value type, not a reference type - and that it cannot contain any references.
So the struct you pass through can only contain basic types, and structs containing basic types - no reference types, which means no strings, no arrays, no Lists, nothing complex at all.
I suspect you are going to have to find a better solution to your problem, and drop the idea of memory mapped files altogether. What exactly are you trying to do that you think you need these?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
@OrigianlGriff...That is the reason I used MarshalAs(UnmanagedType.ByValTStr,SizeConst=16)] public string mystring;
Which gives my string a fixed size(16) if I am not wrong.
I am trying to create an application which writes to a memory mapped file("test"). There will be another application which reads from the same memory mapped file and performs the specified operation.
|
|
|
|
|
Doesn't matter: it's still a reference type, and you can't use it!
Are you just trying to use the file to communicate between the two apps?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ok.
Is there no other way to do it?
|
|
|
|
|
For writing data to an MMF that is more complex than a struct containing only value type members you would have to serialize that data into a byte array and then write that byte array to the MMF using MemoryMappedViewAccessor.WriteArray<T>[^]. In order to be able to read it back, you should also write the length of the byte-array to the MMF, probably directly before the start of the byte-array.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I need a runtime is similar to the Visual Studio forms designer examples, I hope it's not a Windows form, but Windows Presentation Foundation, it has a few features I need:
1. to design window
2. in the design window, add widge
I am very grateful to you if you help me
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Environment: - Windows XP/Windows7 32bit, 64 bit/Windows 2008 Server 64 bit/Windows 2012 Server 64 bit
.
Application Details: -
Application.exe [Visual Studio C# created]
Extract.exe [Visual Studio C# created]
.Net Frame Work: - 3.5 .Net Frame Work
.
Product Description: - We have a product Application.exe, which launch another process Extract.exe in command line for extracting image documents, after extraction; we store data into text file and read from Application.exe and store into data base.
Note: - Application.exe start from services.msc.
.
We run multiple instance of Application.exe after renaming it as Application-FirstInstance.exe, Application-SecondInstance.exe; each application exe launches Extract.exe. We create service for each Application-{Instance}.exe. Application works fine in multiple instances environment, but during run of each service; there are many Extract.exe and Application-{Instance}.exe visible in task manager.
.
Requirement Description: -
We want to kill related Extract.exe on stopping Application-{Instance}.exe from services, and it would be instant operation.
But we have to make sure that related Extract.exe is deleting, while stopping Application-{Instance}.exe from services. What will be right way to identifying particular Application-{Instance}.exe and related Extract.ext and killing operation?
.
Kindly assist us to find the resolution. Please let us know, if more information is required.
We will be really thankful.
|
|
|
|
|
The best solution is that when an instance of Application.exe is killed, it should close its instance of Extract.exe - since it is the only program that knows for sure which one it is.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi Sir,
That is right, but how will we know the reference of particular exe.
|
|
|
|
|
Presumably you start it using Process.Start? Which means you have the Process object, and all it's info...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi Sir,
We start it in same way, I will check from Process object for required value in application, and will let you know, that we have captured required info or not.
Thanks & Regards
|
|
|
|
|
Hi,
I need know how can reading byte using serialport I mean if any device send data in bytes by serialport I need code can be reading byte and display this data in textbox
for examble if micro controller send x=255 this data will send in ascii code how can read this value in C#
Regards
|
|
|
|
|
|
Use SerialPort.Read[^] to get the bytes, and then Bitconverter.ToString to output them to a textbox:
myTextBox.Text += BitConverter.ToString(arrayOfBytesFromSerailPort);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi ,
Thank you for support
I have equation I send data I text for example my_data="ST23.5255"
Iam using
serialport.ReadTo("ST") to Read ST from array text then now I have two value
1- 23.5 this is anolage value from temperature senser
2- 255 this value from anther senser
now my equation how can separated this value from array my_data and display this value in gauge or led array
I mean can be use method in C# convert string to float value and selected index from array because I have two value
Regards
|
|
|
|
|
Read the following three bytes - you will probably have to wait until they are available.
Then use float.Parse or float.TryParse (or their double equivalents) to convert the value.
Then do the same for the next three bytes.
What part of this is difficult?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
The difficult is how can separated the data from string because this array have multi data
for example
string w;
w = Port.ReadTo("ST");
and assume the data send "ST12.5127"
this data 12.5127 will store a text in W now I need convert 12.5 from text to float and convert 127 to float how can separated data from W
Sir can be written the code
Regards
|
|
|
|
|
SerialPort.Read[^] lets you specify how many characters (or bytes) to read...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
hasan hadi wrote: this data 12.5127 will store a text in W now I need convert 12.5 from text to
float and convert 127 to float
Convert.ToFloat("12.51"); You're not going to like this, but converting from one simple type to another simple type should not be an issue.
I suggest you buy a book and go through a lot of tutorials before attempting anything more complex.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Sir what Book mean ?
Regards
|
|
|
|