Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
L

Luc Pattyn

@Luc Pattyn
About
Posts
22.2k
Topics
272
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Interface with a default implementation
    L Luc Pattyn

    Ah, sorry, I missed the sentence "You can't declare auto-implemented properties in interfaces" in Auto-Implemented Properties - C# | Microsoft Learn[^] . Makes sense. :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# debugging help question

  • Interface with a default implementation
    L Luc Pattyn

    You could use properties rather than variables, couldn't you? That is what the example does... :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# debugging help question

  • Interface with a default implementation
    L Luc Pattyn

    Hm. The one link shows there are many aspects to the default implementation inside interfaces, that article is hard to read and understand in one go. The first answer in the SO link shows how a default property getter could be written; that is simple, and at first glance what you want could be implemented likewise as a default setter. :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# debugging help question

  • How to use functions of a dll in another dll "on the fly"
    L Luc Pattyn

    Hi, I have an appliction that loads extensions from a specific folder; each extension is a class that derives from a base class DTF_ComponentBase, which happens to be a UserControl as all extensions need a very similar dialog window. Each extension is built into a separate DLL file. This is the heart of the code that loads those DLL files:

    		private readonly List DTFlist=new List();
    			...
    		// scan DTFAddins folder
    		DTFlist.Clear();
    		string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
    		//folder += @"\\DTFAddins";
    		log("folder=" + folder);
    		Directory.CreateDirectory(folder);
    		string\[\] dlls = Directory.GetFiles(folder, "\*.dll");
    		Exception firstException = null;
    		List errors = new List();
    		foreach (string dll in dlls) {
    			if (dll.Contains("LPplatformDLL.dll")) continue;
    			try {
    				log("File: " + dll);
    				if (dll.Contains("DTF\_ComponentBase.dll")) continue;
    				Assembly asm2 = Assembly.LoadFile(dll);
    				Type\[\] types = asm2.GetTypes();
    				// find all classes implementing DTF\_ComponentBase
    				foreach (Type type in types) {
    					//log("    Type=" + type.FullName);
    					if (type.IsSubclassOf(typeof(UserControl))) {
    						UserControl uc = (UserControl)Activator.CreateInstance(type);
    						if (uc is DTF\_ComponentBase comp && !comp.Skip) {
    							DTFlist.Add(comp);
    							break;
    						}
    					}
    				}
    			} catch (Exception exc) {
    				if (firstException == null) firstException = exc;
    				errors.Add("Error loading "+dll+"; "+exc.Message);
    			}
    		}
    

    At the end DTFlist contains all the extensions that were found and instantiated; a foreach loop can then be used to issue commands such as Start, Stop, ... whatever the base class provides. Hope this helps. :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# visual-studio help tutorial

  • Interface with a default implementation
    L Luc Pattyn

    Hi Richard, I haven't used default implementations yet, what struck me in your code is IClientFormHelper isn't referenced anywhere, and does not belong to the interface, as it sits outside the curly brackets of public interface IClientForm. If you want to know all about it, I guess Default interface methods - C# feature specifications | Microsoft Learn[^] is what you need. It seems to be a very complex matter. If all you want is some inspiration, I'd recommend https://stackoverflow.com/questions/53700939/default-interface-methods-and-default-values-for-auto-properties[^]. Cheers :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# debugging help question

  • "Out of memory exception when loading image with bitmap
    L Luc Pattyn

    :rose: Today, I need to fix that statement; it should read:

    some image operators (e.g. Image.FromFile) MAY throw an OOM Exception when the data is not valid.

    There is no guarantee an OOM will occur on every damaged image! :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# graphics help mysql design sysadmin

  • Read information from serial port in Mathlab format
    L Luc Pattyn

    you're welcome. :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# sharepoint help tutorial

  • Read information from serial port in Mathlab format
    L Luc Pattyn

    OK, so message traffic would be pretty low, and problems with the serial communication are rather unlikely. This is my first attempt (not tested!), it does NOT include communication recovery, that is: if something goes wrong (say a serial byte gets lost), it will continue to fail.

    using System;
    using System.IO.Ports;
    using System.Threading;

    namespace ConsoleApp1 {
    class PortDataReceived {
    private static SerialPort sp;
    private const string PORTNAME = "COM3";
    private const int MSGLEN = 21;

    	public static void Main(string\[\] args) {
    		sp = openPort();
    		Console.WriteLine("Press any key to terminate...");
    		Console.ReadKey();
    		if (sp!=null) sp.Close();
    	}
    
    	private static SerialPort openPort() {
    		try {
    			SerialPort port = new SerialPort(PORTNAME);
    			port.BaudRate = 56000;
    			port.Parity = Parity.None;
    			port.StopBits = StopBits.One;
    			port.DataBits = 8;
    			port.Handshake = Handshake.None;
    			port.RtsEnable = true;
    			port.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
    			port.Open();
    			output("serial port " + PORTNAME + "opened");
    			return port;
    		} catch(Exception exc) {
    			reportError("Error opening serial port (" + exc.Message + ")");
    			return null;
    		}
    	}
    
    
    	private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) {
    		// we will process one or more messages in a loop
    		// WARNING: if for some reason the serial data gets out of sync (first byte isn't 0xE0)
    		//			then we will not recover, and the data will not be understood at all!
    
    		byte\[\] message = new byte\[MSGLEN\];
    		while (true) {
    			int count = sp.BytesToRead;
    			if (count == 0) return; // no more data, exit the handler
    			if (count >= MSGLEN) {
    				// we now read exactly 21 bytes, no more no less, so when several messages could be present
    				// we only obtain the first one in this iteration of the while loop
    				int got=sp.Read(message, 0, MSGLEN);
    				if (got == MSGLEN) {
    					processMessage(message);
    				} else {
    					// this should never happen
    					reportError("Insufficient data bytes in DataReceivedHandler");
    				}
    			} else {
    				// some bytes are present, but not enough; so wait some more
    				Thread.Sleep(100);
    			}
    		}
    	}
    
    	private static void processMessage(byte\[\] bb) {
    		// WARNING: this method gets called by DataReceived handler, so it will NOT run on the GUI thread,
    		//			and would need Invoking when used in a Windows Forms project
    		int count = bb.Le
    
    C# sharepoint help tutorial

  • Read information from serial port in Mathlab format
    L Luc Pattyn

    Your problem description is way too vague to get useful suggestions. A couple of points: 1. why are you calling sp.DiscardInBuffer() ? all the data that you get by executing Read operations is removed from the serial stream automatically, however if any data comes in while your handler is running will be thrown away, more specifically anything that comes in after sp.BytesToRead is not read and discarded. 2. you are ignoring the return value of sp.Read(). this method will not always return the number of bytes requested: when fewer are available, fewer will be returned! 3. you should not switch on the number of bytes read, as sp.BytesToRead may return just any value: it could be as low as 3, or as high as 300, all depending on what your peripheral is sending and how fast Windows is dealing with it. 4. you need to see the incoming data as chunks of one big stream, and provide code to detect the messages in that stream, then act on them. A serial port does not care about messages, it just sends bytes; so a DataReceived handler might get only half a message, or several messages, or ... 5. serial ports (and all interfaces to external devices) may temporarily fail, e.g. loose a few bytes; to get a reliable program your code must be capable of surviving such mishaps. 6. as I mentioned before, I would avoid DataReceived; collecting the incoming data, discovering the messages in the stream, and acting on them is way easier in a dedicated thread. If you want someone to help, you need to provide lots of very specific information, such as: 1. description of the application. What is it about, is this a commercial peripheral (make & type), is the peripheral's software fixed? 2. is there a document that describes the protocol your peripheral is using on its serial port? 3. how often will a message be sent? 4. is there a master-slave relationship? i.e. send one command to get one response? that would be easy. or is the peripheral free to send whatever and whenever it likes to do so? etc. All this info is needed to come up with a reliable approach. :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# sharepoint help tutorial

  • Read information from serial port in Mathlab format
    L Luc Pattyn

    Suggestions: 1. don't use ToString("X"), use ToString("X2") instead, so you always get two characters 2. don't use ToString at all, you can simply replace

    data[8].ToString("X").Equals("A9")

    by

    data[8]==0xA9

    3. be warned, the DataReceived handler executes on a different thread and therefore cannot access GUI Controls directly. See for instance Invalid cross-thread operations[^] :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# sharepoint help tutorial

  • Read information from serial port in Mathlab format
    L Luc Pattyn

    Hi, 1. to read binary data use the method SerialPort.Read(Byte[], Int32, Int32)[^] 2. I seldom use the DataReceived event as it is the source of a number of problems. I'd rather use a separate thread (or a BackGroundWorker) that periodically calls a Read method. 3. I am puzzled by the fact that your second data format shows 15 bytes per line, not 16 as is usual. 4. I noticed your data seems to have a periodicity of 21 bytes; when reformatted it looks like this:

    e0 08 15 03 00 04 4c 00 b1 01 00 06 00 00 00 00 00 00 28 00 eb
    e0 09 15 03 00 04 4c 3e a1 00 06 00 00 00 00 00 00 00 56 00 eb
    e0 0a 15 03 00 04 4c 00 a2 00 00 00 00 00 00 00 00 00 14 00 eb
    e0 0b 15 03 00 04 4c 00 a3 00 00 00 00 00 00 00 00 00 16 00 eb
    e0 0c 15 03 00 04 4c 00 a7 00 00 00 00 00 00 00 00 00 1b 00 eb

    Hope this helps. :)

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    C# sharepoint help tutorial

  • Wordle 990
    L Luc Pattyn

    Same here. And that terminated my streak, I was fortunate to reach 100 yesterday. :-D :~

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    The Lounge

  • Wordle 989
    L Luc Pattyn

    Wordle 989 6/6 ⬜⬜🟨🟨⬜ ⬜⬜⬜⬜⬜ ⬜🟨🟩⬜⬜ ⬜⬜🟩🟨🟩 🟨⬜🟩⬜🟩 🟩🟩🟩🟩🟩 Phew too, as I was missing some consonants, and quite some possibilities remained. I got lucky with the last try, and that was important, as it would (and did) finally yield me a 100 streak.

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    The Lounge

  • win11 dismay: can't have vertical taskbar?!
    L Luc Pattyn

    I feel your pain. Of course you want a vertical taskbar, screen height is the most valuable asset of a computer. Only idiots remove features and call it an upgrade. Fortunately there is a third-party solution[^] that I'm happy about. For as long as it continues to work that is.

    Luc Pattyn [My Articles] The Windows 11 taskbar is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    The Lounge question css com data-structures tutorial

  • Wordle 962
    L Luc Pattyn

    Wordle 962 4/6 ⬜⬜⬜⬜⬜ 🟨⬜⬜⬜⬜ ⬜⬜⬜⬜⬜ 🟩🟩🟩🟩🟩 excellent starting words?

    Luc Pattyn [My Articles] The Windows 11 "taskbar" is a disgrace; a third-party add-on is needed to reverse the deterioration. I decline such a downgrade.

    The Lounge

  • wordle 595
    L Luc Pattyn

    Funny situation: ⬜⬜🟩⬜⬜ 🟨🟩⬜🟨🟩 5 letters in two tries, two letters still need to be swapped...

    Luc Pattyn [My Articles] The Windows 11 "taskbar" is a disgrace. It should be at the left of the screen, with real icons, with text, with progress, etc. So I declined the "upgrade" to Abomination 11. I can only hope they will continue to honor my choice...

    The Lounge php com

  • Wordle 487
    L Luc Pattyn

    Wordle 487 4/6 ⬜⬜⬜⬜🟨 🟨⬜⬜🟨⬜ 🟨⬜⬜⬜⬜ 🟩🟩🟩🟩🟩

    Luc Pattyn [My Articles] The Windows 11 "taskbar" is a disgrace. It should be at the left of the screen, with real icons, with text, with progress, etc. So I declined the "upgrade" to Abomination 11. I can only hope they will continue to honor my choice...

    The Lounge

  • Wordle 406
    L Luc Pattyn

    It is just a matter of elimination... Wordle 406 5/6 ⬜⬜🟨⬜⬜ ⬜⬜⬜🟨⬜ ⬜⬜⬜⬜⬜ ⬜⬜⬜⬜⬜ 🟩🟩🟩🟩🟩 :)

    Luc Pattyn [My Articles] The Windows 11 "taskbar" is a disgrace. It should be at the left of the screen, with real icons, with text, with progress, etc. So I declined the "upgrade" to Abomination 11. I can only hope they will continue to honor my choice...

    The Lounge

  • How do I debug my hubby?
    L Luc Pattyn

    Drop the noisy hardware: Remove the speaker, let an ES32 capture the audio signal and stream it to shazam. They'll let you know if it is any good. :)

    Luc Pattyn [My Articles] The Windows 11 "taskbar" is a disgrace. It should be at the left of the screen, with real icons, with text, with progress, etc. So I declined the "upgrade" to Abomination 11. I can only hope they will continue to honor my choice...

    The Lounge question debugging

  • Wordle Hurdle
    L Luc Pattyn

    got lucky: Wordle 304 3/6 ⬜🟩⬜⬜🟩 ⬜⬜⬜⬜⬜ 🟩🟩🟩🟩🟩

    Luc Pattyn [My Articles] The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.

    The Lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups