|
In order to control a PLC with a "complex data structure" the PLC class expects a structure that is unmanaged.
This structure runs fine:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class PinStructureQuality
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public int[] iPinValues = new int[24];
public PinStructureQuality()
{
iPinValues = new int[24];
}
}
The problem I have is that I don't know at the time this Class is constructed whether I have 10, 24 or any other number of pins. I would like to read this from a settings file or an XML file containing a parameter telling what the size the array is.
The line
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
causes the problem, since the value 24 must be known in front.
Does anybody have an idea on how to solve this?
|
|
|
|
|
What's the C declaration? I suspect you want to marshal as a pointer not as a fixed size array within the structure.
|
|
|
|
|
the structure is directly used in the API provided with the PLC. This is the declaration of the wrapper:
public void WriteAny(int variableHandle, object value);
and my call to it is:
public void SetAllLow()
{
for (int i = 0; i < iNrIO; i++)
_PinStructureQuality.iPinValues[i] = (int)(65535);
try
{
if (e._ErrorCode == 0)
adsClient.WriteAny(hcomplexStruct, _PinStructureQuality);
}
catch
{
e._ErrorCode = 1;
e._ErrorMessage = "Could not write pinning data to PLC";
ErrorEvent(this, e);
e._ErrorCode = 0;
e._ErrorMessage = "";
}
}
The reason I want to use this WriteAny call is that it allows me to sent also strings and other types in the same structure.
|
|
|
|
|
Member 7889751 wrote: I don't know at the time this Class is constructed whether I have 10, 24 or any
other number of pins. I would like to read this from a settings file or an XML
file containing a parameter telling what the size the array is.
Why does the second preclude the first?
|
|
|
|
|
The easiest way to deal with variable length arrays with P/Invoke is to create your array as a normal .NET array where variable length is no issue.
When you need to pass it you can use GCHandle[^] to pin the data and pass the GCHandle's pointer. Make sure you free the GHHandle after you are done with it! This assumes the native code can somehow work out the length of the data being passed - if it attempts to read outside of the allocated memory, strange things will happen
|
|
|
|
|
Hi Experts
can u please guide me how to download a file which is in Network location( \\10.101.....)where we pass credentials OF particular server and downloading a file from that server to local Machine in asp.net
Regards
venu
|
|
|
|
|
On the local network? You can just use File.Open etc (any of the normal ways to read a file from System.IO), if you have permissions to read it. Remember that ASP.net runs as its own user, though, so setting up the network permissions might be tricky.
|
|
|
|
|
ya i dont have permissions to read it but i have a user name and password who has the permission to read so i have to pass this parameters in the code and to read the file
|
|
|
|
|
Getting network resources under a different user name is (on Windows anyway) pretty tricky. You'd probably do better asking your network admin for read permissions on that file.
|
|
|
|
|
I am working in a c# code generator project. This first version was mostly hacked out in a couple of weeks.
, Now I am having qualms , regarding if I should publish it or simply keep it for myself ( I mean , not out of selfishness , but due to the fact that a comercial product needs a lot more work than an only-for-your-eyes tool, plus I get the impression that code generators are not very popular these days ).
Currently the tool generates the following :
Stored procedures for the tables (SQL Server only)
Business objects
Data Access Layer
A basic navigation menu
A list view for the objects.
Any feedback will be greatly appreciated.
|
|
|
|
|
Most developers worth paying build their own code generator as part of their "framework". Most of us also run up against this same question, should I publish? I predict that almost no one will actually pay money for it if/when you do publish (remember we all built our own).
There is one benefit you will gain from it if you do go on to publish it. You will learn the difference between corporate and commercial grade software. What a corporate or you will accept to get the job done and what you can actually sell are very different animals.
Good luck!
[edit]
By all means you should write an article and publish that way, this will also be instructive without the staggering burden of trying to make a commercial product. It may get ragged mildly as being like many others but so what!
[/edit]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks for the feedback.
One of my thoughts was to polish it enough so that even a non-programmer could use it ( but that is an altogether different creature which would probably take months to complete ).
As-is it would probably be usefull only for novice programmers ( < 1 year experience ).Anyhow , I started this project because the company I'm in makes everything by hand and I couldn't stand the tedium of writting n-tier apps by hand.
|
|
|
|
|
Armando de la Torre wrote: I couldn't stand the tedium of writting n-tier apps by hand.
Yup thats why we wrtie em. Mine started life in VB5 back in the 90s and even then I snaffled it from another dev I was working with. It's been rewriten in 3 different languages using different protocols and targetting different databases, currently Oracle and SQL Server. Still does basically the same thing for the database but now does all the WCF model and DAL stuff with an initial ViewModel shell but this is not really valid any more.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
That's fair enough, but there are already code generators on the market. Some are paid for, and some are free. It would be worth taking a look at what they have to offer and see how they are packaged.
|
|
|
|
|
Mycroft Holmes wrote: I predict that almost no one will actually pay money for it if/when you do publish (remember we all built our own).
Hmmm... I was thinking in selling it at a VERY affordable price ( e.g USD $20 - 25 , trainning videos included ). My bet is that it will draw the attention of novice programmers, but mostly it will be done just for the experience of getting a comercial product on-line.
Once again , thanks for the feedback.
|
|
|
|
|
Publish it here, at least it's like a code review with many experts with many years experience in a wide variety of scenarios giving you feedback.
|
|
|
|
|
I am doing a project which requires me to have a link from one page that will direct/take me to another page. How can i do this..?
|
|
|
|
|
Do not cross post - pick a forum and post in that forum only!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
sorry.! i was not sure whether to post in C# or ASP.Net
|
|
|
|
|
Go read a book, this is ridiculously easy.
|
|
|
|
|
Easiest way :
response.redirect("MyOtherPage.aspx");
if you need to pass data you can use the session object ( e.g Session["firstPage"] = myObject) and retrieve it from the second page ( many programmers see the session as the root-of-all-evils, but I think its ok to use it to pass small( <10k ) object).
|
|
|
|
|
Hi,
I am having a problem with the Graphics Object in the Paint Event.
when I use Graphics g=e.Graphics in the Paint Event handler and then
I go and and use g.DrawImage, etc
textboxes on the same form work properly, but when I add the statement, this.Invalidate(); in the Paint event
the draws will auto update, but the textbox's cursor dissapears
I can still enter text
but it seems the textbox's event and the Paint event are causing troubles.
I am trying to create a 2d racing game for an academic project and require gdi+ or xna , I chose to start in GDI+ and I am drawing all my menus with DrawString method, but when I want input say player name, I choose to add a textbox and get it from there, since my drawing canvas is the whole form, I solved the problem using a panel to draw in, had double buffering issues which I solved but then I have these conflicts with the windows form controls.
Any assistance is highly recommended
Jase
|
|
|
|
|
Why are you calling Invalidate in the Paint event?? All you're doing is constantly telling the control to repaint itself from inside the Painting code of the control! You don't see a problem with this?
|
|
|
|
|
Hi Jase,
I agree with what Dave said; Invalidate does not belong in the Paint handler, the Paint handler should paint, and do nothing else; and elsewhere Invalidate/Refresh/Update should be called when something has changed in such a way that a repaint is necessary. If you want a sequence of frames, don't organize it in such a way that Paint calls Invalidate to call Paint again, instead use an explicit sequencing mechanism such as a periodic timer.
For best performance, you should keep your Paint handler code minimal:
- no blocking calls (e.g. no delays, no database access!);
- at best: no creation of objects (keep the Pens, Fonts, Brushes you need in class members, create them once and reuse them)
- if you must create an object, make sure you either keep it around for reuse OR dispose of it properly (calling Dispose for those classes that offer it).
|
|
|
|
|
Luc,
I noticed this anomaly with the doublebuffered control:
1. I use a different namespace from your animation, say PanelForm (or class):
and when I try to add controls on my form with the panel, in the Windows Form Designer,
it will add the following extra syntax in bold:
(in bold)
this.panel1 = new PanelForm.PanelForm.DoubleBufferedPanel();
and during a compile I get an error so the following is correct:
this.panel1 = new Menu.DoubleBufferedPanel(); (Removing the extra PanelForm. fixes the problem)
How come everytime I resize the panel or add something on the same form, it adds the Panel. extra in between PanelForm.Double Buffered -> PanelForm.PanelForm.DoubleBuffered in Windows Form Designer?
I can easily delete it everytime but after say 10 times it becomes frustrating.
2.I understand how you are saying do not use Invalidate in the Paint Event handler,
eventually when we put a car image on the form and use Vectors to move it, Invalidate will need to be done else the car will not move by itself ? or should I use a timer to achieve the same result !
I am just wanting to know, having GDI+ Graphics like Drawstring, DrawRectangle coupled with textboxes and labels is bad form ? and bad design ?
I can send some code over if you cannot understand what I am trying to achieve ? Would that be better?
I am a novice c# programmer, Object Orientation is new to me, so I am still learning the fundamentals after so much time on procedural old style programming !
Thanks also Dave for your feedback !
Regards,
Jase
|
|
|
|