|
if the problem is that you require smoothing between points you could use something like a bezier curve to draw your sine wave
|
|
|
|
|
Hi,
We are using a C++ dll from our C# code.
The C++ code reads data from a serial communication port, and fills up a buffer with the data read.
We are sometimes experiencing a big delay (around 5 seconds) when the C++ function returns.
The C# code looks something like this:
class Program
{
[DllImport("SerialCommunication.dll", EntryPoint = "SerialCommRead", SetLastError = true)]
protected static extern unsafe SERIAL_COM_STATUS SerialCommRead(uint handle,
[MarshalAs(UnmanagedType.LPArray)] byte[] buffer,
uint length, [MarshalAs(UnmanagedType.LPArray)] uint[] bytesRead);
protected void Read()
{
StreamWriter logWriter = new new StreamWriter("test.log", true);
SERIAL_COM_STATUS status = SerialCommRead(m_PortHandle, m_ReadBuffer,(uint)m_ReadBuffer.Length, bytesRead);
DateTime t = DateTime.Now;
logWriter.Write(t.Day.ToString() + "/" + t.Month.ToString() + "/" + t.Year.ToString() + " " +
t.Hour.ToString() + ":" + t.Minute.ToString() + ":" + t.Second.ToString() + "." +
t.Millisecond.ToString() + " ");
logWriter.WriteLine("After SerialCommRead(), status: " + status.ToString() + " bytesRead: " +
bytesRead[0].ToString());
logWriter.Flush();
}
}
The C++ code:
__declspec(dllexport) SERIAL_COM_STATUS SerialCommRead(HANDLE handle, unsigned char *buffer,
unsigned int length, unsigned int *bytesRead)
{
COMSTAT ComStat;
DWORD errorFlags, err;
*bytesRead = 0;
OVERLAPPED overlappedRead;
memset(&overlappedRead, 0, sizeof(OVERLAPPED));
overlappedRead.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!overlappedRead.hEvent) {
err = GetLastError();
return(SER_COM_CREATE_EVENT_ERROR);
}
if (!ClearCommError(handle, &errorFlags, &ComStat)) {
err = GetLastError();
CloseHandle(overlappedRead.hEvent);
return(SER_COM_READ_ERROR);
}
if (!ComStat.cbInQue) {
CloseHandle(overlappedRead.hEvent);
return(SER_COM_OK); // There is nothing in queue to read
}
DWORD numOfBytesRead = 0;
if (!ReadFile(handle, (LPVOID)buffer, (DWORD)length, &numOfBytesRead, &overlappedRead)) {
err = GetLastError();
if (ERROR_IO_PENDING == err) {
DWORD res = WaitForSingleObject(overlappedRead.hEvent, SER_COM_OVERLAP_READ_TIMEOUT);
switch (res) {
case WAIT_OBJECT_0:
if (!GetOverlappedResult(handle, &overlappedRead, &numOfBytesRead, TRUE)) {
err = GetLastError();
CloseHandle(overlappedRead.hEvent);
return(SER_COM_GET_OVERLAP_ERROR);
}
break;
case WAIT_TIMEOUT:
*bytesRead = (unsigned int)numOfBytesRead;
CloseHandle(overlappedRead.hEvent);
return(SER_COM_TIMEOUT_ERROR);
case WAIT_FAILED:
err = GetLastError();
*bytesRead = (unsigned int)numOfBytesRead;
CloseHandle(overlappedRead.hEvent);
return(SER_COM_WAIT_ERROR);
default:
*bytesRead = (unsigned int)numOfBytesRead;
CloseHandle(overlappedRead.hEvent);
return(SER_COM_ERROR);
}
} else {
CloseHandle(overlappedRead.hEvent);
return(SER_COM_READ_ERROR);
}
}
CloseHandle(overlappedRead.hEvent);
*bytesRead = (unsigned int)numOfBytesRead;
PrintToFile("SerialCommRead(): going to return");
return(SER_COM_OK);
}
void PrintToFile(char *str)
{
struct _timeb timebuffer;
_ftime( &timebuffer );
char timeline[26];
ctime_s( timeline, 26, & ( timebuffer.time ) );
static FILE *fHandle = NULL;
if (NULL == fHandle)
{
// First time, open th file
fHandle = fopen(“test2.log”, "wt");
}
if (fHandle) {
fprintf(fHandle, "%.19s.%hu ", timeline, timebuffer.millitm);
fprintf(fHandle, "%s\n", str);
fflush(fHandle);
}
}
In file “test2.log” the printout of “SerialCommRead(): going to return” appears with a timestamp that is sometimes 5 seconds earlier than the printout to “test.log” from the C# code.
Looks like it takes the C++ function 5 seconds to return…
Any ideas?
Thanks,
Galit.
|
|
|
|
|
ive got an idea...
PUT YOUR CODE IN [pre] and [code] TAGS!!!
no one wants to read unindented code. especially if its as much code as you posted
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
Hi Guys. I have an application that writes a bunch of records to Excel. At the end of writing the data I need to sum a column. However, I don't know how many records there will be in the file so I can't set the range to sum in the code. I tried this by setting it something like the below but for some reason it doubles the Total that is summed.
I need to know how to get the last range and set that in the formula dynamically.
objRange = objSheet.get_Range("E1", System.Reflection.Missing.Value);
objRange.Formula = "=SUM(J4:J50000)";
objRange.FormulaHidden = true;
objRange.Calculate();
objRange.Font.Bold = true;
objRange.Font.ColorIndex = "5";
From the above I am selecting cel E1 and in this cell I have the formula to sum the totals of the data in Column J. As I don't know what the last line of data is going to be I set the final cell to calculate as J50000.
Can somebody please help me with this??
Cheers
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
int lastUsedColumn = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing).Column;
int lastUsedRow = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing).Row;
should tell you the last used row and column
|
|
|
|
|
Thanks mate. Then how do I use that in the formula. Sorry for asking.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
instead of summing from J4 to J5000 sum from J4 to J[last used row]. then you won't be including any extra rows in your sum
|
|
|
|
|
Brilliant. I'll give that a shot.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi Jimmanuel. I have used the below and I get an error when it does the calculation. Am I doing this right?
int lastUsedRow = objSheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,
Type.Missing).Row;
And this is where I add it into the formula.
objRange = objSheet.get_Range("E1", System.Reflection.Missing.Value);
objRange.Formula = "=SUM(J4:J[lastUsedRow])";
objRange.FormulaHidden = true;
objRange.Calculate();
objRange.Font.Bold = true;
objRange.Font.ColorIndex = "5";
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
objRange.Formula = string.Format("=SUM(J4:J{0})", lastUsedRow);
it might also be a good idea to do some error checking to make sure that lastUsedRow is valid. I don't know what would happen if you tried summing from J4 to J0 for instance . . .
|
|
|
|
|
Thanks a million mate. It works 1000% now.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
glad to help
|
|
|
|
|
I have a server that upon receiving a client request would create a socket in order to send/receive data to/from the client. I'd like to be able to send this socket to another application - through http - so that this app could "talk" with the same client using the same socket. Is it posible? If not is there another way to keep the server-client connection alive to be used by another app?
|
|
|
|
|
xax wrote: Is it posible?
Not under normal circumstances, but far back in my mind I recall seeing someone blog about this on MSDN blogs a good 3-4 years back. (I did a search, but cant find it now)
Your other alternative is using Remoting, and let the other application communicate with your socket on via the socket-holding application.
|
|
|
|
|
Hi guys, in new to c# actually to programming and was wondering if anyone knows of a could place to start looking for a tutorial on how to create a setup/install package that includes things like pics, db etc. Or if anyone knows how to do this in visual studio 2005?
Phoenix
|
|
|
|
|
You can use the builtin stuff, but I prefer NSIS. InnoSetup is also very simple and easy to use.
|
|
|
|
|
Clickety
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Add "New Project ..." to the Solution
Select "Other Project Type"
Select "Setup And Deployment"
Select "Setup Wizard"
You will see a setup wizard (1 of 5)
Click Next
You will see a setup wizard (2 of 5)
select "Create a setup for a window application" then click next
You will see a setup wizard (3 of 5)
select "Primary output from Project Name" then click next
You will see a setup wizard (4 of 5)
Click Next
You will see a setup wizard (4 of 5)
click finish
Your setup project is created.
select a Setup Project then right click and then build
your setup is ready to deploy.
|
|
|
|
|
Hi friend i have zip file and i want extract it using c#Code can any body help me
wasim khan
|
|
|
|
|
SharpZipLib?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
All the world's a stage,
And all the men and women merely players.
They have their exits and their entrances;
And one man in his time plays many parts... --William Shakespeare
|
|
|
|
|
I am developing a window based application in C#.net. In this app i have to sync between flash and c#. For this i have added Shockwaveflashobjects.dll from com component.
I got idea of this via this topic
http://www.codeproject.com/KB/audio-...ternalapi.aspx
Now when i am make a call from c# to flash it gives me error like this
Error HRESULT E_FAIL has been returned from a call to a COM component.
Is there any solution for this error ????
Thanks in advance
Himal.
|
|
|
|
|
Hello,
I am beginer in C# programming..
When I add button on the form, and run the project- form doesn't change at all (the button doesn't exist on form). I put Visible= true in property for that button, but it seems it doesn't work..
What is the problem, and how can I solve it?
|
|
|
|
|
jaffa wrote: What is the problem, and how can I solve it?
I don't know. You've not explained HOW you are adding the button.
|
|
|
|
|
I just dragged and dropped on the form, and set Visible= true..
When I debug and entered into the InitialComponent method, there are code for that button
(....this.btnSend = new System.Windows.Forms.Button()...)
|
|
|
|
|
Is it in a container that is not visible, such as a panel or groupbox?
|
|
|
|