Jump to content
Xtreme .Net Talk

MTSkull

Avatar/Signature
  • Posts

    153
  • Joined

  • Last visited

Everything posted by MTSkull

  1. Good question, I had not thought to investigate. I was too busy fixing it (with my boss breathing down my neck). My computer automatically downloaded the following the morning of 10/15/2008 Windows XP Security Updates: KB956803, KB956391, KB957095, KB956390, KB954211, KB956841 Office 2007: KB955936 Office 2003: KB955466, KB957257 My guess is the Office 2007 might have killed it since it... I am not really sure though. MTS
  2. I just ran into this problem and thought you guys should know. I came into work yesterday morning and my computer said it had installed a critical update and had to restart. This happens every now and again so I paid it no mind. I opened my project that uses Microsoft.Office.Interop.Excel made some changes then Attempted to compile, which generated an error "Can't find Microsoft.Office.Interop.Excel". The project worked great and compiled the night before. I have spent about 2 days trying to locate the fix. One site said I can use Interop.Excel which I can see in the Object Browser but could not figure out how to connect to. I fixed the problem by tracing though this thread which pointed me to this download for the Office 2003 Primary Interop assemblies. After I registered the dll's i had to make a minor code modification to get up and running again. I was curious if any one else saw this, especially since the project worked the night before an update and did not the morning after. Cheers MTS
  3. Is it possible to set up a (C# or VB) program to remotely reboot another machine (say a server). The Sys Admin asked about it and I have no clue where to even start looking for something like that. Thanks MTS
  4. I modifed your code slightly :rolleyes: [CS] StreamWriter Results = new StreamWriter("C:\\TimeResults.txt"); this.Text = "Starting..."; DateTime Start = DateTime.Now; DateTime TryStart = DateTime.Now; TimeSpan Difference; for (int x = 0; x < 1000; x++) { try { TryStart = DateTime.Now; Application.DoEvents(); StreamReader Test = new StreamReader("r:\\birthcrt\\999\\9995\\9995000M.txt"); Test.Close(); Test.Dispose(); } catch { Difference = DateTime.Now.Subtract(TryStart); Results.WriteLine(x.ToString().PadRight(6, (char)32) + Difference.TotalMilliseconds.ToString()); } } Difference = DateTime.Now.Subtract(Start); Results.WriteLine("DONE " + Difference.TotalMilliseconds.ToString()); Results.Close(); Results.Dispose(); this.Text = "Finished..."; [/CS] The mods allow me to see the time it took for each individual try when trying to open a file on the network drive. I wanted to simulate stuff actually going on with the system while it was tring to run. So while it was running the simulation I was opening and closing stuff on the desktop. Quickest was 0mSecs and slowest was ~47mSecs with an average of 6.4mSecs for the 1000 samples. Total time was ~6 seconds. So not slow enough that it would not be noticed. Especially since I will be introducing a wait time between each pass. Thanks Brian
  5. In this case I can be more then reasonably assured that it won't be opened after I check it. We have a server process which I flag when I am done writing. It then extracts info it needs for database processing. Occasionally it hangs and holds files open, or is lazy in how it closes and releases the files. I need a way to test to see that I am not colliding with this process. It is a relatively rare occurrence but I would like to handle it better then Try/Catch/Finally which is slow and I plan on hitting it several times before throwing an error. If this is even possible. I tried exploring FileAccess, FileAtributes and AccessControl.FileSecurity, but did not see anything in there that looked promising. Thanks MT
  6. Can you check if a file is open and/or locked without the try/catch/finally statement? I saw this asked in another thread but the topic turned to exception handling and the original question never seemed to be answered. Thanks MTS
  7. This is the helper class included with the code above. Also when Attaching long documents like this is it more appropriate to post as an attachment or a code block? class HexCon { //converter hex string to byte and byte to hex string public static string ByteToString(byte[] InBytes) { string StringOut = ""; foreach (byte InByte in InBytes) { StringOut = StringOut + String.Format("{0:X2} ", InByte); } return StringOut; } public static byte[] StringToByte(string InString) { string[] ByteStrings; ByteStrings = InString.Split(" ".ToCharArray()); byte[] ByteOut; ByteOut = new byte[byteStrings.Length - 1]; for (int i = 0; i == ByteStrings.Length - 1; i++) { ByteOut[i] = Convert.ToByte(("0x" + ByteStrings)); } return ByteOut; } }
  8. I need to implement CTS only flow control. Is there a way to do it using the Serial Port Control, or is there another way? For example I found this class on another help site and it states that you can set CTS Flow Control via "Bit Twiddling". When it comes to this I have 1/2 a clue but am not sure quite how to get this class to work. using System; using System.Runtime.InteropServices; namespace JustinIO { class CommPort { public int PortNum; public int BaudRate; public byte ByteSize; public byte Parity; // 0-4=no,odd,even,mark,space public byte StopBits; // 0,1,2 = 1, 1.5, 2 public int ReadTimeout; //comm port win32 file handle private int hComm = -1; public bool Opened = false; //win32 api constants private const uint GENERIC_READ = 0x80000000; private const uint GENERIC_WRITE = 0x40000000; private const int OPEN_EXISTING = 3; private const int INVALID_HANDLE_VALUE = -1; [structLayout(LayoutKind.Sequential)] public struct DCB { //taken from c struct in platform sdk public int DCBlength; // sizeof(DCB) public int BaudRate; // current baud rate /* these are the c struct bit fields, bit twiddle flag to set public int fBinary; // binary mode, no EOF check public int fParity; // enable parity checking public int fOutxCtsFlow; // CTS output flow control public int fOutxDsrFlow; // DSR output flow control public int fDtrControl; // DTR flow control type public int fDsrSensitivity; // DSR sensitivity public int fTXContinueOnXoff; // XOFF continues Tx public int fOutX; // XON/XOFF out flow control public int fInX; // XON/XOFF in flow control public int fErrorChar; // enable error replacement public int fNull; // enable null stripping public int fRtsControl; // RTS flow control public int fAbortOnError; // abort on error public int fDummy2; // reserved */ public uint flags; public ushort wReserved; // not currently used public ushort XonLim; // transmit XON threshold public ushort XoffLim; // transmit XOFF threshold public byte ByteSize; // number of bits/byte, 4-8 public byte Parity; // 0-4=no,odd,even,mark,space public byte StopBits; // 0,1,2 = 1, 1.5, 2 public char XonChar; // Tx and Rx XON character public char XoffChar; // Tx and Rx XOFF character public char ErrorChar; // error replacement character public char EofChar; // end of input character public char EvtChar; // received event character public ushort wReserved1; // reserved; do not use } [structLayout(LayoutKind.Sequential)] private struct COMMTIMEOUTS { public int ReadIntervalTimeout; public int ReadTotalTimeoutMultiplier; public int ReadTotalTimeoutConstant; public int WriteTotalTimeoutMultiplier; public int WriteTotalTimeoutConstant; } [structLayout(LayoutKind.Sequential)] private struct OVERLAPPED { public int Internal; public int InternalHigh; public int Offset; public int OffsetHigh; public int hEvent; } [DllImport("kernel32.dll")] private static extern int CreateFile( string lpFileName, // file name uint dwDesiredAccess, // access mode int dwShareMode, // share mode int lpSecurityAttributes, // SD int dwCreationDisposition, // how to create int dwFlagsAndAttributes, // file attributes int hTemplateFile // handle to template file ); [DllImport("kernel32.dll")] private static extern bool GetCommState( int hFile, // handle to communications device ref DCB lpDCB // device-control block ); [DllImport("kernel32.dll")] private static extern bool BuildCommDCB( string lpDef, // device-control string ref DCB lpDCB // device-control block ); [DllImport("kernel32.dll")] private static extern bool SetCommState( int hFile, // handle to communications device ref DCB lpDCB // device-control block ); [DllImport("kernel32.dll")] private static extern bool GetCommTimeouts( int hFile, // handle to comm device ref COMMTIMEOUTS lpCommTimeouts // time-out values ); [DllImport("kernel32.dll")] private static extern bool SetCommTimeouts( int hFile, // handle to comm device ref COMMTIMEOUTS lpCommTimeouts // time-out values ); [DllImport("kernel32.dll")] private static extern bool ReadFile( int hFile, // handle to file byte[] lpBuffer, // data buffer int nNumberOfBytesToRead, // number of bytes to read ref int lpNumberOfBytesRead, // number of bytes read ref OVERLAPPED lpOverlapped // overlapped buffer ); [DllImport("kernel32.dll")] private static extern bool WriteFile( int hFile, // handle to file byte[] lpBuffer, // data buffer int nNumberOfBytesToWrite, // number of bytes to write ref int lpNumberOfBytesWritten, // number of bytes written ref OVERLAPPED lpOverlapped // overlapped buffer ); [DllImport("kernel32.dll")] private static extern bool CloseHandle( int hObject // handle to object ); [DllImport("kernel32.dll")] private static extern uint GetLastError(); public void Open() { DCB dcbCommPort = new DCB(); COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS(); // OPEN THE COMM PORT. hComm = CreateFile("COM" + PortNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); // IF THE PORT CANNOT BE OPENED, BAIL OUT. if (hComm == INVALID_HANDLE_VALUE) { throw (new ApplicationException("Comm Port Can Not Be Opened")); } // SET THE COMM TIMEOUTS. GetCommTimeouts(hComm, ref ctoCommPort); ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout; ctoCommPort.ReadTotalTimeoutMultiplier = 0; ctoCommPort.WriteTotalTimeoutMultiplier = 0; ctoCommPort.WriteTotalTimeoutConstant = 0; SetCommTimeouts(hComm, ref ctoCommPort); // SET BAUD RATE, PARITY, WORD SIZE, AND STOP BITS. GetCommState(hComm, ref dcbCommPort); dcbCommPort.BaudRate = BaudRate; dcbCommPort.flags = 0; //dcb.fBinary=1; dcbCommPort.flags |= 1; if (Parity > 0) { //dcb.fParity=1 dcbCommPort.flags |= 2; } dcbCommPort.Parity = Parity; dcbCommPort.ByteSize = ByteSize; dcbCommPort.StopBits = StopBits; if (!SetCommState(hComm, ref dcbCommPort)) { //uint ErrorNum=GetLastError(); throw (new ApplicationException("Comm Port Can Not Be Opened")); } //unremark to see if setting took correctly //DCB dcbCommPort2 = new DCB(); //GetCommState(hComm, ref dcbCommPort2); Opened = true; } public void Close() { if (hComm != INVALID_HANDLE_VALUE) { CloseHandle(hComm); } } public byte[] Read(int NumBytes) { byte[] BufBytes; byte[] OutBytes; BufBytes = new byte[NumBytes]; if (hComm != INVALID_HANDLE_VALUE) { OVERLAPPED ovlCommPort = new OVERLAPPED(); int BytesRead = 0; ReadFile(hComm, BufBytes, NumBytes, ref BytesRead, ref ovlCommPort); OutBytes = new byte[bytesRead]; Array.Copy(BufBytes, OutBytes, BytesRead); } else { throw (new ApplicationException("Comm Port Not Open")); } return OutBytes; } public void Write(byte[] WriteBytes) { if (hComm != INVALID_HANDLE_VALUE) { OVERLAPPED ovlCommPort = new OVERLAPPED(); int BytesWritten = 0; WriteFile(hComm, WriteBytes, WriteBytes.Length, ref BytesWritten, ref ovlCommPort); } else { throw (new ApplicationException("Comm Port Not Open")); } } } /////Insert Helper Class Here///// }
  9. Must have been anouther language I was thinking about. Thanks
  10. Not quite the same. For example. I have a label named "User Name" it gets its text from a login form. My boss decided he does not like the way the program works and wants to be able to enter text where the label displays data. So instead of creating a new control and doing find replace for all references to the old control name, I thought there was a way to select the label and say "I want to change you to a text box." Just trying to save myself some work. MT
  11. Can I convert a Label into a Text Box, and if so how? MT
  12. Here's how I solved it. I thought maybe it was not recognizing it as a string, so I terminated the characters with a "\x00" or an ASCii null char 0. This worked but it placed white space at the end. Next I tried sTemp = "S00" + Station_Num.ToString() + "_" + BootVariables.Model_Code;// +"\x00"; LFWrite.Write(sTemp, false, System.Text.ASCIIEncoding.ASCII); so I could check the string contents in debug before actually sending it out. Then I tried dropping the null char to see what would happen and it worked correctly. I think this works because the string variable handled formatting it as a string where pushing the raw text directly into the write function did not. Or something like that. MTS
  13. No Change I did however do this which is almost right LFWrite.Write("S001_D1C\x00", false, System.Text.ASCIIEncoding.ASCII); Forcing the null to the end of the string to get it to see this as a string. This produces the file text "S001_D1C " Then if I could just get it to drop the white space at the end I would be alright.
  14. I am creating an application that will interface with an old service. I need to put a single line code into a text file to get it to do stuff elsewhere on the network. One of the requirements is the code must be a single line with no new line or whitespace beginning or end. Here is the code I am attempting to use. When I write the single line to the file and then read the file it shows as 4boxes (unrecognized char code?). Thanks MTS //c# public Int32 IssueSerialNumber() { //Writes to a file monitored by a server service. When the service detects the appropriate code Int32 PassFail = LocalError.ERROR_GEN_PASS; StreamReader LFRead = new StreamReader("C:\\Lock001.txt"); string sTemp = LFRead.ReadLine(); if (sTemp != "RU") { //TODO the file is not ready, handle it //return LocalError.ERROR_FILE_Something_New_Happened; } LFRead.Close(); StreamWriter LFWrite = new StreamWriter("C:\\Lock001.txt"); LFWrite.Write("S001_D1T"); LFWrite.Close(); return PassFail; }
  15. Fixed... using Excel = Microsoft.Office.Interop.Excel; Just noticed this old post, this is how I fixed it, by setting the word "Excel" equal to the library name. MTS
  16. //initialize excel objects //FileName is passed in from the calling function which is loaded via // an ini file with this value "R:\Production_Test_Files\Command_Scripts\Bootload_Test.xls" //When I view this value while the code is running, it changes the "\" to "\\" string ExWorkBook = FileName; //if I uncomment the next line there are no problems. //ExWorkBook = "R:\\Production_Test_Files\\Command_Scripts\\Bootload_Test.xls"; Excel.Application oApp = new Excel.Application(); //CRASHES next line with 'File not found error', NOTE: the Gap in the value is not present in the IDE... Excel.Workbook oWB = oApp.Workbooks.Open(ExWorkBook,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value); //Cleanup: GC.Collect(); GC.WaitForPendingFinalizers(); oWB.Close(false,Missing.Value,Missing.Value); //Save changes = false Marshal.FinalReleaseComObject(oWB); oWB = null; oApp.Quit(); Marshal.FinalReleaseComObject(oApp); oApp = null; I have an application that reads values in from an XL spread sheet. If I pass a network path in that I read from an INI file, I get a file cannot be found error. If I place the same value into the variable locally the file opens reads and then closes just fine. I am using .net 2005. MTS
  17. I am trying to create an application to read data from an Excel file. I have added a COM reference to excel using the reference add utility. using Microsoft.Office.Interop.Excel; I though this command would expose the excel commands to intellisense but that is not the case. Does doing the above make the excel stuff work even though it does not come up in Intellisense or am I missing a step? MT
  18. I used to use a servers event scheduler to push/pull data from remote SQL DBs. I could set up the event to run at 1 am so it had full use of down time. I have also set up auto fax blasters that run off a scheduler late at night. To set it up you just tell it what exe to run, when and how often. If you use this approach setting up error logging is critical to figuring out problems that might occur when you are not around. MT
  19. The second block behaves better, but both still jump to the end when new text comes in. This is not a worry though since I am the intended user. This project is meant to be a simpler Hyper Terminal, as well as letting me do experiments in the future. This also allows me to scroll through the entire session. In order to do that in Hyper Terminal you have to push the results out to a text file. Thanks MT
  20. Worked Kind of... rtxtStatus.Text = rtxtStatus.Text + serialPort1.ReadExisting(); //Add text rtxtStatus.SelectionLength = 0; rtxtStatus.SelectionStart = rtxtStatus.Text.Length; //Move to end //Added rtxtStatus.ScrollToCaret(); The selection did not scroll down just moved the carat to the end allowing the scroll to carat function to work. Thanks Mr Paul you are awesome. MT
  21. I wrote a Simple Hyper Terminal Emulator because my regular hyper terminal keeps locking up my computer. I have gotten the functionality pretty close to what I want with one exception. I am outputting the contents of the serial buffer to a rich text box that will also take key strokes and send them back to the device under test. The problem I am having is getting the richtext box to stay scrolled down so it displays only the latest received data. Approaches I have tried... richtext.scrolltocarat(); every time new serial data enters the text box the carat jumps back to the home position so scroll to carat does nothing. SendKeys.Send("^{END}"); because I am reacting to keystroke events this sends the program into an infinite loop, I think. Limiting the text box to 30 lines of the most recent data. Worked great when I was reading serial data in Line by Line, just push the results into a string collection. But the application needed to react to partial lines of incoming data. Attached is the whole project if anyone would like to take a look. but here is the pertinent code. private void timer1_Tick(object sender, EventArgs e) { //function checks the input stream for buffered text, if it is there read it out to the rtxtbox if (serialPort1.IsOpen != true) return; //get input stream from port1 // check buffer? if (serialPort1.BytesToRead > 0) { try { rtxtStatus.Text = rtxtStatus.Text + serialPort1.ReadExisting(); //Does not work, need to force carat to end so it will subequently scroll to the carat. // Carat returns to home and does not stay at the end of the control. //rtxtStatus.Focus(); //rtxtStatus.ScrollToCaret(); //Sending Cntrl End to move to the end of the rich text box //send keys cause endless loop in conjunction with form keypress event. //rtxtStatus.Focus(); //SendKeys.Send("^{END}"); //txtSendText.Focus(); //Trying to limit the lines of text to 30 keeping the most current info in view //if (FromRadio.Count > 30) //{ // rtxtStatus.Text = ""; // for(int x = (FromRadio.Count-31);x<FromRadio.Count;x++) // rtxtStatus.Text = rtxtStatus.Text + FromRadio[x]; //} //else // rtxtStatus.Text = rtxtStatus.Text + FromRadio[FromRadio.Count-1]; } catch { //do nothing?? // if it errors I don't care just keep going... for now } } this.Update(); Application.DoEvents(); } HyperTermEmulator.zip
  22. I typically use //TODO that shows up automatically in the Task list. Also the blue arrow is gone since my reboot. Go figure. Here is my other favorite beer quote: "You can't be a real country unless you have a beer and an airline - it helps if you have some kind of a football team, or some nuclear weapons, but at the very least you need a beer." Frank Zappa
  23. HUZZAH! I had been avoiding using Firefox at work since our sys admin is a :mad: I used Firefox instead of IE and it worked fine.
  24. Still Trying to attach picture Attaching the picture BlueArrowGlyph.bmp
  25. Is there a way to override this?
×
×
  • Create New...