|
bring back hungarian notation!!!
|
|
|
|
|
I'd never been a fan till i worked on a a java project recently where this. and super. had been used religiously throughout the project. After a while i started to quite like being able to instantly know where in the inheritance heirarchy something had come from.
Saying that I still leave them out in my own projects, just too lazy i suppose.
Russell
|
|
|
|
|
Jugnu wrote: if (this.ColorGrade ="31-1" || this.ColorGrade="31-2" || this.ColorGrade="31-3")
{this.QGrd='F';}
|| is a boolean condition, which means that it is expecting boolean tests around it. So, you need a boolean condition. Now in this if statement, the boolean condition is going to be == rather than = because = is an assignment statement and not a boolean condition. I hope that's clear enough.
|
|
|
|
|
I've written a plug-in to work with a 3rd party app.
The code has to be installed to 3rdPartyPath\Plugins so I need to override the install path choice for the user. I can delete the page where the user gets to choose an install path but I can't work out how to tell the app to install to my custom location. I seem to be able to call out to my own dlls which should be able to tell me where to install but i can't work out how to do anything with the return value.
Does anyone know how to do this?
Cheers,
Russell
|
|
|
|
|
I would say look into this[^] MSDN site. This website was discovered by looking through links on this[^] message thread. Hope these help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hey guys, ive ran into a little problem here.. im interfacing with an unmanaged c++ dll in my c# application.
the dll structure is as follows:
APIENTRY ReadImage(
hInstance hObject,
unsigned char* pData,
unsigned long dataSize);
with pData being the top address of the image reading buffer allocated by the calling application.
how would i declare a variable in c#, allocate a specific ammount of memory to it, then return the
memory address of said variable. this is got me stumped :/
|
|
|
|
|
Take a look at System.Runtime.InteropServices.Marshal and associated information
|
|
|
|
|
Thanks for the info mike, i took a look at the class but i still have no idea how to pass the memory address as a parameter to the dll.
|
|
|
|
|
|
Off the top of my head, I would expect you to pass in a StringBuilder object as pData.
|
|
|
|
|
Pete O'Hanlon wrote: I would expect you to pass in a StringBuilder object as pData.
Given the name of the function is ReadImage I assumed it would not be text data and therefore StringBuilder would not work?
|
|
|
|
|
Hi,
assuming the native function expects to get a buffer of sufficient size, this is
how you should do it:
- include a line using System.Runtime.InteropServices; // DllImport
- declare the native function as
[DllImport("myLibrary.dll")]
private extern static int ReadImage(IntPtr hObject, IntPtr pData, ulong dataSize);
- allocate an array of sufficient size (type is byte, uint, whatever you like);
- use class GCHandle methods Alloc (GCHandleType.Pinned) and AddrOfPinnedObject to get
pointer you need (an IntPtr). Pinning prevents the GC to move the array object around
until it gets freed again.
- call the native function as if it were part of your class (the extern static declaration
makes that possible)
- use GCHandle.Free to undo the pinning
|
|
|
|
|
Hi there.
I have an USB Device whick have to small functions.
It should be possible if I write 'GET' to it, it should then return a integer value. And if I write 'RES' it should reset the Integer value.
The Device is connected to my Computer with a USB-Serial cable. I have installed a driver i got with the cable.
I have tried using LibUsbDotNet, but when i tries to open a connection to the device the program just crashes and i cant do anything.
Anyone who can tell how to communicate with my device?
|
|
|
|
|
You said it was connected using a USB Serial cable?? Is the device exposed on a COM port?? Like COM1, COM2, Com3, ... Try talking to it over the serial port instead of going through the headache of using the devices' drivers.
|
|
|
|
|
The device has a serial port, so i have connected it to an USB port using a USB-Serial cable.
|
|
|
|
|
Then the device is more-than-likely exposed on a normal COM port. You can probably get to it using any terminal emulator software that uses serial communication (like HyperTerminal). If so, then you can use the SerialPort class in the .NET Framework 2.0 (System.Io.Ports namespace) to talk to it from your code.
|
|
|
|
|
Ok. Sounds great.. thanks
I will buy a serial cable tomorrow and try it..
|
|
|
|
|
Could this be a possible way to call the GET function on the device?
<br />
SerialPort sp = new SerialPort("COM1");<br />
<br />
sp.Write("GET");<br />
char[] buffer = new char[64];<br />
int ans = sp.Read(buffer, 0, 64);<br />
|
|
|
|
|
In a very, very "quick'n'dirty" implementation, no. You still have to give the SerialPort class constructor the parameters the device is expecting for serial communication, like which COM port (you already have it), baud rate, parity, data bits, and stop bits.
Then you need to Open the port before you try to read/write from it. Then you need to Close the port when you're done.
Read this...[^]
|
|
|
|
|
You just told me you HAD a serial cable and had the device connected to it...??
|
|
|
|
|
I told you I had a USB-Serial cable connected to it.. It is an adapter from Serial to USB.. The port on the device is Serial and on the computer it has to be USB.
|
|
|
|
|
Hi again..
I found out that the Computer the device has to be connected to, does not contain any serial port.. So I have to use USB to this.
Is it really that hard to communicate with an USB port?
|
|
|
|
|
haolan wrote: Is it really that hard to communicate with an USB port?
You don't talk to a USB port. USB is not really a port. What does USB stand for?? "Universial Serial BUS". It works more like the slots inside the computer, not like the ports on the back of it.
Yes, it's THAT difficult. You don't take to the bus itself. You talk to each device using whatever methods that device exposes. That could be through drivers, Device I/O calls, normal file system functions, or, in your case, through a COM port.
|
|
|
|
|
Ahh ok..
I connected the device again, and found out that if I run:
string[] ports = SerialPort.GetPortNames();
foreach (string p in ports)
{
Console.WriteLine(p);
}
It has created a new COM port named COM6. So i guess i should be able to communicate with my device through that port?
I have created the following code for communication:
SerialPort sp = new SerialPort("COM6", 1200, Parity.None, 8, StopBits.One);
try
{
sp.Open();
sp.Write("GET");
sp.ReadTimeout = 10000;
string ans = sp.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
sp.Close();
}
I get timeout when I am waiting for answer, but I guess it could be a mistake of how to communicate with the device.
|
|
|
|
|
haolan wrote: It has created a new COM port named COM6. So i guess i should be able to communicate with my device through that port?
Probably. Noone except you can relly tell that. Open up HyperTerminal, set the port to COM6, set the parameters to what the device expects, connect, type in your commands and see what happens.
haolan wrote: SerialPort sp = new SerialPort("COM6", 1200, Parity.None, 8, StopBits.One);
If you don't get a response, or you get a response containing garbage, then you've most likely either got the wrong COM port, or got the communication parameters wrong.
|
|
|
|