|
Hi,
I purchased an USB based oscilloscope DSO-2150 from Hantek. Along with it came the VC++ DLLs (dll, lib and ocx).
I need to create a Winform application using C# Visual Studio Express Edition.
Please tell me is it possible to use VC++6 DLL in a C# appllication and if yes How?
Following is scrap from the manual provided with the DLL files.
DSO-XXXX USB SDK Manual
SDKXXXX.dll (VC++ 6.0)
Define struct
struct PictureRange{
WORD width;
WORD height;
WORD left;
WORD right;
WORD top;
WORD bottom;
};
struct ControlStruct{
WORD TriggerSource;
WORD SelectedChannel;
WORD Timebase;
WORD TriggerPosition;
WORD DataLengh;
WORD BufferSize ;
WORD isAlt;
};
struct LeversStruct{
WORD Ch1Position;
WORD Ch2 Position;
WORD Ch1TriggerPosition;
WORD Ch2TriggerPosition;
WORD EXTTriggerPosition;
};
struct StateStruct{
WORD Ch1Filt;
WORD Ch2Filt;
WORD TriggerFilt;
WORD TriggerMode;
WORD TriggerSlope;
};
struct LineColor{
WORD R;
WORD G;
WORD B;
};
struct AutosetStruct{
WORD WhichChannel;
WORD Ch1Voltage;
WORD Ch2Voltage;
WORD Ch1Timebase;
WORD Ch2Timebase;
WORD Ch1InGND;
WORD Ch2InGND;
WORD Ch1Enabled;
WORD Ch2Enabled;
};
struct TimeStruct{
double Timer;
double Time;
double ScrollTime;
double ScrollStart;
};
Functions:
1. Functions for hardware:
WORD __stdcall sdSearchDevice (WORD DeviceIndex)
Variables introduction:
DeviceIndex: index of the device.
Note: This function is used for finding device.
If successful return 1, else return 0.
WORD __stdcall sdSetVoltageAndCoupling(WORD DeviceIndex,
WORD Ch1Voltage
WORD Ch2Voltage,
WORD Ch1_ACDC,
WORD Ch2_ACDC,
WORD TriggerSource)
Variables introduction:
Ch1Voltage: index of the CH1 voltage
Ch2Voltage: Index of the CH2 voltage
Ch1_ACDC: index of the CH1 Coupling ( AC is 1, DC is 0, GND is 0 )
Ch2_ACDC: index of the CH2 Coupling
TriggerSource: index of the trigger source (CH1 trigger is 0, CH2 trigger is 1, ALT trigger is 2, EXT trigger is 3)
Note: This function is used for setting voltage and Coupling. If successful return 1, else return 0.
WORD __stdcall sdSetTriggerAndSampleRate(WORD DeviceIndex,
WORD TriggerSlope,
Struct ControlData *Controlstate)
Variables introduction:
TriggerSlope: the trigger type (Rising edge is 0, Failing edge is 1)
Note: This function is used for setting trigger and timebase.
If successful return 1, else return 0.
bool __stdcall sdSetOffset(WORD DeviceIndex,
struct LeversData * Levers,
WORD Ch1_Att,
WORD Ch2_Att,
WORD TriggerSource,
WORD * level)
Variables introduction:
level: array of the channel position adjust data, read from hardware.
Note: This if used for adjusting the position of the channel. If successful return true, else return false.
WORD __stdcall sdSetFilt (WORD DeviceIndex,
struct StateStruct *FiltAndTrigger)
Note: This function is used for setting channel and trigger filter. If successful return 1, else return 0.
WORD __stdcall sdCaptureStart(WORD DeviceIndex)
Note: This function is starting to capture data. If successful return 1, else return 0.
long __stdcall sdTriggerEnabled(WORD DeviceIndex)
Note: This function is used for setting the trigger. If successful return 1, else return 0.
WORD __stdcall sdGetLevel(WORD DeviceIndex,WORD * level)
Note: This function is used for reading the waveform position adjust data from hardware. If successful return 1, else return 0.
WORD __stdcall sdGetData(WORD DeviceIndex,
WORD Ch1_Att,
WORD Ch2_Att,
WORD * Ch1HardwareData,
WORD * Ch2HardwareData,
struct ControlData *Controlstate,
struct StateStruct *FiltAndTrigger,
struct LeversData *levers,
WORD *level,
int StartCapture
)
Variables introduction:
Ch1HardwareData: save ch1 data from hardware
Ch2HardwareData: save ch2 data form hardware
StartCapture: capture data flag. If start to capture is 1, else is 0.
Note: This function is used for reading data from the hardware. If successful return 1, else return 0.
2. Functions for software:
WORD __stdcall sdMainPanelDrawGrid (HDC hdc,
struct PictureRange * view_data)
Variables introduction:
Hdc:
Note: This function is used for drawing grid on panel. If successful return 1, else return 0.
WORD __stdcall sdDisplayDataXYMode(HDC hdc,
struct PictureRange * view_data,
WORD isLine,
WORD * ch1_data,
WORD * ch2_data)
Variables introduction:
isLine:
Note: This function is used for displaying data with X-Y Mode. If successful return 1, else return 0.
WORD __stdcall sdGetDisplayData(struct ControlData *Controlstate,
WORD * ChDispalyData,
WORD * ChBufferData
)
Variables introduction:
ChDisplayData:
ChBufferData:
Note: This function is used for getting display data. If successful return 1, else return 0.
WORD __stdcall sdDisplayData (HDC hdc,
struct PictureRange * DisPicture,
WORD PointOrLine,
WORD * ChDisplayData,
struct LineColor * ch_color)
Note: This function is used for displaying data on screen.
WORD __stdcall sdChannelDataBuffer (struct ControlData *Controlstate,
WORD InterpolationLineMode,
WORD * chx_data,
WORD * ch_data)
Variables introduction:
InterpolationLineMode:
Note: This function is used for processing data and copying data to "chx_data" from "ch_data". If successful return 1, else return 0.
WORD __stdcall sdChannelInGND (WORD Ch1Position,
WORD *chdata)
Note: This function is used for processing data when channel is in GND. If successful return 1, else return 0.
WORD __stdcall sdAutoset (WORD DeviceIndex,
struct ControlData *Controlstate,
struct AutosetStruct *AutosetData,
struct StateStruct *FiltAndTrigger,
struct LeversData * levers,
WORD *level
)
Note: This function is used for automatically setting. If successful return 1, else return 0.
WORD __stdcall sdGetScrollData(WORD DeviceIndex,
struct ControlData *Control_Data1,
struct LeversData *levers,
struct TimeStruct *TimeState,
WORD Ch1Voltage,
WORD Ch2Voltage,
WORD *Ch1ScrollData,
WORD *Ch2ScrollData,
WORD *Ch1DisplayData,
WORD *Ch2DisplayData,
WORD TriggerPosition,
bool Ch1InGND,
bool Ch2InGND
)
Note: This function is used for getting and processing data when channel is in scroll mode. If successful return 1, else return 0.
double __stdcall sdDisplaySampling (bool Ch1Enabled,
bool Ch2Enabled,
WORD TriggerSource,
WORD Timebase,
WORD BufferSize)
Note: This function is use for Display Sampling on main panel status bar.
Wish a very Happy New Year,
Thanks and Warm Regards,
Karmendra
|
|
|
|
|
Hi,
that seems doable, but it is not at a beginner's level. You will need a lot of P/Invoke.
If you are not familiar with P/Invoke, I suggest:
- you read up on it, both MSDN and some CodeProject articles;
- you have a look at www.pinvoke.net[^]
- you start with something simpler; I like to create my own native C coded DLL, using simple functions
to test P/Invoke stuff.
BTW: for the array stuff (where parameters are pointers) you either need to use the fixed and unsafe keywords, or the GCHandle class.
|
|
|
|
|
Hi Luc Thanks,
It really seems tedious, need to learn lot to understand it.
A friend of mine was suggesting adding a reference to dll and that will create a class for me to use directly. But he said I has not tried it anytime, what do you think is that possible.
Thanks again,
Regards,
Karmendra
|
|
|
|
|
Hi,
C# calling native code needs P/Invoke, AFAIK there is no way around that.
Ask your friend for details of his method!
|
|
|
|
|
Hi Luc,
I just found i even have VB dlls does that help getting it done the easier way, I mean I don't mind learning new things, but don't have much time, but if their is no other go i will keep learning about accessing un-managed code in c# using pInvoke.
Thanks a lot for your help,
Regards,
Karmendra Suthar
|
|
|
|
|
Hi,
if that is old VB stuff, it is still native code and C# needs P/Invoke.
if that is managed VB.NET code, then it can be called directly, just instantiate the classes and
operate on the properties and methods as if it too were C# code.
|
|
|
|
|
Hi all,
Iam a newbie,
I retrieve the table from Database.
I need to enter values in the GridView Cells directly When i click EDIT in girdview.
protected void GridView2_RowEditing(object sender, EventArgs e)
{
GridView2.SelectedRow.Cells[3].Focus();
}
this is giving me an error.
"Object reference not set to an instance of an object".
After editing i have an "update" in gridview that updates in database, i can do this.
What code i need to put in RowEditing event, so that it takes my values entered in cells.
Thanks in advance.
|
|
|
|
|
I'm trying to read data from a specific binary file format, and have done well until now.
I need to read title and artist info from this file, but it is not in your typical string format where the first byte indicates the string length. It is also not serialized.
It is simply a string of 64 bytes.
As it is, readstring truncates the first character of the string as it's looking for the string length as the first byte which doesn't exist.
I've tried readchar with a for loop but this increases the load time of the file to an extreme.
I've also tried to use readbytes[64], but this always returns "System.Byte[]" instead of the actual info. I've not been able to find any valuable usage info for this method, so I'm certain I'm not using it correctly.
I've tried
read.readbytes[64];
and
read.readbytes[64].tostring();
both return System.Bytes[] as the value.
I've then thought of reading the bytes using readbytes, and then inserting the string length, so as to re read using readstring, but I'm not getting anywhere with this method either.
I'm looking for proper usage of readchars, or readbytes to return a meaningful value.
Any suggestions welcome, but I cannot alter the source. ReadChar works, but as stated, takes much to long to load. Not looking to use unsafe coding if at all possible, as that may be just as extensive loading as the looped readchar method.
|
|
|
|
|
Convert an array of bytes to a string with System.Text.Encoding.ASCII.GetString ( bytes ) (or one of the other encodings).
|
|
|
|
|
Hi Jeff,
when it is just bytes, read the bytes; don't even consider using chars (they aren't chars, a .NET char takes 16-bit) or strings. A .NET string is not represented by a length followed by 8-bit chars, as e.g. Pascal used to do. System.String is a sealed class, and you are not even supposed to know how a string is implemented.
And the ToString() result of a byte array simply gives its type, as you discovered, not its content.
You need to specify how things are encoded, as PIEBALD suggested.
|
|
|
|
|
Thank you both!
I think I've got it.
|
|
|
|
|
Hello everyone,
I've got a little problem.
In an office, there is a server running with a program and in that program is a button to switch off all the lights.
But I would like to have a phisical button. Let's say that we use a keyboard button.
The problem is that there is no source code for the serverprogram. So I would like to know if it is possible to make another program, which can get an keyboard-event and let this event click on the button in another program?
And a happy new year to all of you!
|
|
|
|
|
You can find the window handle of the button and send it a message. It's fiddly, hacky and ugly, but it will work.
The second half, you can write a system wide keyboard hook, or another program which, when it's got the focus, gets the keyboard event, then finds that window and sends it the message.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
hmmmm, I wanted to do this for a long time, is it possible if I just use the Mouse? a program that will set the position of the mouse on the screen using coordinates and then the mouse CLICKS (without user interaction) using a code.
|
|
|
|
|
haha, I like this anwser. Simple and maybe usefull, though it's tricky when the screen changes or is moved. But thanks for this insight.
|
|
|
|
|
Hire a programmer
I are troll
|
|
|
|
|
I am the programmer, still learning, but I just needed some solution-idea's to the problem.
As I have the idea's, I can try to build the app.
|
|
|
|
|
It was a rude statement, my apologies.
The server-application is running under Windows? In that scenario, FindWindow and SendKeys will do the trick, as other people already mentioned.
I are troll
|
|
|
|
|
I forgive your stupidity
Thank you very much. I guess I'll conquer this problem.
|
|
|
|
|
i have a class
public class Command
{
public int Number;
public int Parameters;
}
then 1 xml file :
<common>
<command number="0">
<response parameters="2">
<command number="1">
<response parameters="5">
i wanna assign attribute of the class to value in xml file:
Command[] Response = new Command[200];
XmlDocument Reader = new XmlDocument();
Reader.Load("Sample.xml");
XmlNodeList List = Reader.SelectNodes("/Common/Command");
foreach (XmlNode commandnode in List)
{
int i = int.Parse(commandnode.Attributes["value"].InnerText);
Response[i] = new Command();
HartResponses[i].Number = i;
XmlNodeList Child1List = commandnode.ChildNodes;
foreach (XmlNode Child1 in Child1List)
{
if (Child1.Name == "Response")
Response[i].Parameters = int.Parse(Child1.Attributes ["Parameters"].InnerText);
}}
i got error :"Object reference not set to an instance of an object" at the line
Response[i].Parameters = int.Parse(Child1.Attributes["Parameters"].InnerText);
The code can be executed with i=0,but when i increase to 1, i got this error?
How do i solve it?
Thanks
|
|
|
|
|
hung1984 wrote: Command[] Response = new Command[200];
This creates an array of 200 instances of null. Each must be created before you assign values to it.
Response[i] = new Command();
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
they are already created here:
foreach (XmlNode commandnode in List)
{
int i = int.Parse(commandnode.Attributes["value"].InnerText);
Response[i] = new Command();
HartResponses[i].Number = i;
.............
|
|
|
|
|
Any code that assumes a child node exists, is bad code. I guess this attribute is not always there.
A good way to debug this code is to break it up into as many lines as possible, and see which line blows up. The debugger is also a powerful tool.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
i use it cause my xml file surely have the node named Response. But why the error started with Response[1]?
|
|
|
|
|
I assume because that's the one that doesn't have the attribute. Hard to say, I don't see your XML, and you don't say if you did what I told you to do to work out the exact problem.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|