|
Since my list box is populated from several functions and has over 50,000 lines it would seem the simple "RemoveAt" solves the problem. But thanks for the clarification and example.
|
|
|
|
|
Use listBox1.Items.RemoveAt(ListBox1.SelectedIndex); in place of your code then it will remove your selected item from List Box.
|
|
|
|
|
As I discovered but the listBox1.Remove is logical. Why create this special case.
|
|
|
|
|
how to call base class constructor during creation of derive class object?
|
|
|
|
|
public class BaseClass
{
public BaseClass(string something)
{
}
}
public class DerivedClass : BaseClass
{
public DerivedClass(string something, int other)
: base(something)
{
}
}
This is real basic stuff, which you would pick up really easily with a good book. I can suggest anything by Jon Skeet.
|
|
|
|
|
Hi All
I am developing a windows application in C#. One of its module need to send and receive data from USB port.
How to do this in c#? Is there any Namespase or thrd party dll available?
Regards
Willington
|
|
|
|
|
Plenty[^] if you care to look.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi.. I have googled.. but couldn't find any solution... 
|
|
|
|
|
The first article in the list of links I found for you has sample code.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Perhaps the problem is in thinking that USB is a port. It's not. It's a bus, not unlike the expansion slots inside your computer. You canot treat the USB "ports" like they were Serial or Parallel ports.
|
|
|
|
|
You can treat them as Serial port (see my example I added as answer). But indeed it is very cause-dependent if you can use them as serial port or not.
I use USB as serial port in my Arduino-Example[^] and it turned out working well . Please tell me if I am wrong...
|
|
|
|
|
Marco Bertschi wrote: You can treat them as Serial port
PROVIDED you have a driver that exposes a device as a serial port. It does not convert the USB port to a Serial port. Why? Because you can drop a USB hub in between the Arduino and the computer and your Arduino will still work as a serial device and the USB port will still work with other non-serial devices attached to the same hub.
You're using the USB port, actually bus, to communicate with a device that is exposed as a serial device. You did not treat the USB port as a serial port. USB is mearly supplying the transport mechanism carrying your serial protocol.
|
|
|
|
|
Ooops. off course, I totally forgot that I had to install a driver for the Arduino board before I was able to use it
Nevermind 
|
|
|
|
|
willington.d wrote: How to do this in c#? Is there any Namespase or thrd party dll available?
You can use the SerialPort class which is available in the namespace System.IO.Ports.
You need the following variables to initialize a serial port (you can treat the USB port as a serial port).
private SerialPort _port;
const int BAUDRATE = 9600;
const string COMPORT = "COM8";
delegate void DisplayArduinoSerialOutput(string arduinoSerialOutput);
In the constructor of your App, you need to call the following method to initialize your serial port:
private void InitCOMPort()
{
_port = new SerialPort(COMPORT) { BaudRate = BAUDRATE };
_port.DataReceived += new SerialDataReceivedEventHandler(_port_DataReceived);
_port.Open();
}
Afterwards, your port is ready to use:
private void _port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
DisplayArduinoSerialOutput displayArduinoSerialOutput = new DisplayArduinoSerialOutput(arduinoSerialOutputTextBox.AppendText);
SerialPort spL = (SerialPort)sender;
this.Dispatcher.Invoke(displayArduinoSerialOutput, spL.ReadExisting());
}
In my case, I invoke the UI to add the data to a text box using the Delegate located near my other variables.
Please note: Maybe you have to change the piece of code in the _port_DataReceived-Eventhandler (because I used WPF for this snippet).
However, hope I was able to answer your question.
|
|
|
|
|
Forgive me if you've answered this already, but what would be the name of the port when using the USB?
Marco Bertschi wrote: const string COMPORT = "COM8";
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Uhh, yes, Dave Kreskowiak remembered me about something: You need a driver which exposes the USB as serial ports to your computer (My fault, I am sorry for this one).
Imagine, every Serial Port has its name. In my case, they are numbered from "COM1", "COM2", [...], "COM8", "COMx". I am unsure if this naming is a standard or if it is driver-specific, you might need to do some further research on this naming thing...
However: detecting available COM ports is not that difficult, I found some information about that on Codeproject[^] and on Stackoverflow.com[^]. I'm not sure if this fits your needs, but have a look at it.
Cheers
Marco
|
|
|
|
|
Hi,
I am trying to use functions in C++ dll from C#, but I got an error: "attempt to read or write protected memory. This is often indication that other memory is corrupt"
Anyone know how to fix ?
Here is C++ functions:
typedef void *DGNHandle;
__declspec(dllexport) DGNHandle CPL_DLL DGNOpen( const char *, int );
__declspec(dllexport) DGNElemCore CPL_DLL *DGNReadElement( DGNHandle )
Here is structure in C++:
typedef struct {
int offset;
int size;
int element_id;
int stype;
int level;
int type;
int complex;
int deleted;
int graphic_group;
int properties;
int color;
int weight;
int style;
int attr_bytes;
unsigned char *attr_data;
int raw_bytes;
unsigned char *raw_data;
} DGNElemCore;
And below converted codes are in C#:
[StructLayout(LayoutKind.Sequential )]
public class DGNElemCore
{
public int attr_bytes;
public byte[] attr_data;
public int color;
public int complex;
public int deleted;
public int element_id;
public int graphic_group;
public int level;
public int offset;
public int properties;
public int raw_bytes;
public byte[] raw_data;
public int size;
public int style;
public int stype;
public int type;
public int weight;
}
[DllImport("DgnLib.dll", EntryPoint = "DGNOpen")]
public static extern IntPtr DGNOpen(string fileName, int bUpdate);
[DllImport("DgnLib.dll", EntryPoint = "DGNReadElement")]
public static extern DGNElemCore DGNReadElement(IntPtr DGNHandle)
Codes for testing:
DGNElemCore element = new DGNElemCore();
element = DgnFile.DGNReadElement(dgnFile.oDgnFile)
|
|
|
|
|
The error message is quite clear about what went wrong, but you will need to use your debugger to track down exactly where it occurs.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi,
It throwed error at the last line: element = DgnFile.DGNReadElement(dgnFile.oDgnFile)
|
|
|
|
|
As I said before, you need to use your debugger to find out what is happening. There is no way we can guess what is going on inside the program.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you.
But, the exception window only show that messeage. And, the below is output from debug:
Quote: A first chance exception of type 'System.AccessViolationException' occurred in mscorlib.dll
The thread 'vshost.RunParkingWindow' (0x518) has exited with code 0 (0x0).
The thread '<no name="">' (0x1fdc) has exited with code 0 (0x0).
The program '[7952] CLCLis.vshost.exe: Managed (v2.0.50727)' has exited with code 0 (0x0).
The program '[7952] CLCLis.vshost.exe: Program Trace' has exited with code 0 (0x0).
I still haven't found the reason for this error
|
|
|
|
|
Well it looks as if some code is passing a bad pointer to a function in mscorlib.dll . Where does this DLL come from, is it your code or from a third party? If the latter then contact the people who wrote it and ask for assistance.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you.
I used Visual Studio (project type: win 32 console application) to create this dll file from a C++ files collection (.h and .cpp) of a third-party (Here is the link of source code: http://dgnlib.maptools.org/dl/dgnlib-1.11.zip )
|
|
|
|
|
Since you have the source code you can step through it in your debugger to trace the error.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
How I can trace the error through source codes while I am using dll file ? and I think the source codes don't have error, because I still can use it in Visual C++, but I got the error while trying in C#
|
|
|
|