Click here to Skip to main content
15,355,296 members

Comments by honey the codewitch (Top 171 by date)

honey the codewitch 6-May-22 13:33pm View
When you're compiling for little devices -Os is in effect on GCC.
honey the codewitch 6-May-22 8:51am View
*facepalm* I forgot that shift left and shift right are endian dependent. stupid stupid stupid. i know better.
honey the codewitch 6-May-22 8:42am View
that's weird to me, because Most significant would refer to the value that affects the high numbers, and Least significant would be the value that affects the low numbers no? That would be different for machines of different endian types, unless I'm missing something. It's frightfully early and I'm still catching up on coffee.
honey the codewitch 6-May-22 7:53am View
It shoves the bits high if it's little endian - as seen by the shift, otherwise it shifts them low.

If it shifts them high, is that MSB or LSB? That's what I'm trying to figure out. Right now I call it MSB
honey the codewitch 6-May-22 7:18am View
I'm confused. "Take, for instance your msb function (I didn't scrutinize the other ones), it takes value and stores it in the second byte of value16 on a little endian machine."

Masking off the 8th bit is part of the midi spec.

That's what it's supposed to do. My only question is is that LSB or MSB?
honey the codewitch 6-May-22 0:04am View
That's not my question though. I already do those checks at compile time. Those ifs are not evaluated at run time.

What I want to know is if my msb() and lsb() accessors are named correctly from big endian perspective, or if I have them backward
honey the codewitch 2-May-22 8:38am View
As long as it's clear, I'm cool with it. I do weird things like that too. :)
honey the codewitch 2-May-22 8:01am View
Nope. It's shorter. I'm increasing the top y value, so it starts further down the screen, and since y2 is unchanged that makes the rectangle less tall. I swear to you it works, I'm looking at it running right now. Remember that all the rectangles are effectively anchored to the center on their bottom edge. That might be an area where I should clarify what I'm doing.
honey the codewitch 2-May-22 7:45am View
Thank you for your feedback! GFX is targeted more toward intermediate to advanced developers and those that actually do IoT for work like I do so some familiarity with "real"/modern C++ is assumed. Basically once you've graduated from Arduino IDE and want to do something more powerful - like utilize the capabilities of that fancy ESP32 you just bought, then GFX is the way to go. LVGL is comparable featurewise, though I don't provide widgets, and I *do* provide full TrueType support, even under Arduino. LVGL can support truetype in limited instances, and it uses gobs of RAM and the firmware must be compiled on a linux machine. Also only targets the ESP32 WROVER. Mine targets whatever GFX does. =)
honey the codewitch 2-May-22 7:42am View
First, GFX doesn't work with the Arduino IDE because it won't compile with C++11. I use the platformIO IDE with it, which runs inside VS Code so you get all that autocomplete goodness, and just far more control over your project builds than you can get with the Arduino IDE.

Spoiler on the code:

Yeah, the clock basically forces the rectangle you pass it to be square by looking at the shortest edge and treating that as both the width and the height. That's what w is.

Then it *is* centered. horizontally. See, all hands are drawn effectively at the 12:00 position (before rotation), and then rotated based on the corresponding time figure.

Notice the center of the viewport is set at the beginning. That means the rotation will be around that point. =)
honey the codewitch 2-May-22 6:35am View
What I'm trying to do is create examples for people that don't read the documentation.

A lot of times people that use arduino are hobbyists and don't RTFM.

Assuming autocomplete, and the above, can figure out what it's doing from the context?

Not necessarily precisely - just imagine you're looking at a code sample to figure out how to do something. How hard is this one to figure out enough to fiddle with it, if that makes sense?
honey the codewitch 2-May-22 5:44am View
hahaha I had changed the order above after-the-fact for readability and it's early. I fixed it.
honey the codewitch 25-Apr-22 6:54am View
That's what I thought too so I recloned the git in a separate project. Same deal. I also am manually checking the compiler error line # with the line # shown by VS Code and it matches.

I'm starting to think there's a bug in the GCC compiler? I need to rename my variable again to see if I wasn't hallucinating.
honey the codewitch 25-Apr-22 6:53am View
it's just a temporary holder for an error return value. Typically for things like this I use one letter names. It actually makes it clearer because it's easier to scan visually what is "throwaway" and what is part of the actual algorithm.

There are two reasons I know I'm not looking at the wrong code. For one VS Code provides line #s and click to jump to the location of compiler error messages. I've also manually verified.
honey the codewitch 19-Apr-22 18:05pm View
I wouldn't be surprised if it's off. I was actually trying a number of things. CPallini caught a show stopper for me that explains why i got nothing.
honey the codewitch 19-Apr-22 18:04pm View
I shouldn't said the thing about the top left. I want the colors to start at the start color and radiate away from the center point where the start color is, toward the extents of the rectangle, where at least somewhere, end_color should be represented. This is actually easier to do spherically, but I want to do it so it is along an imaginary line instead of radiating away from a point, if that makes sense.
honey the codewitch 19-Apr-22 18:01pm View
If rect.y1>rect.y2 xd will be -1, oooooh thank you. I just saw it.
honey the codewitch 19-Apr-22 15:49pm View
I learned a long time ago to first make it work, then make it work fast. It serves me well, except if there are design issues tied up with performance. The blast radius of any design changes are limited pretty much to this routine, so if i have to rewrite it for performance I will. I wrote this to try things out, and I didn't want it too laden with premature optimizations.

Edit: Looking at your solution, it's too simple for my application, as it only does a gradient in one direction, not at arbitrary angles with arbitrary starting points.

Pixel blending by channel is something my library already does when you call blend.
honey the codewitch 1-Apr-22 8:40am View
Have you considered studying? Imagine you "earned" your degree by way of other people and landed a programming job. Are those other people to do your work for you as well? Maybe if you're going to school, take advantage of it.
honey the codewitch 26-Mar-22 21:59pm View
Yes that would be correct. As far as your solution, I'll have to think about it. It does give me an idea. There's a chance it will complicate another part of the code and right now I'm too foggy to determine whether it will without diving into it.
honey the codewitch 17-Mar-22 3:29am View
That's one of the reasons I haven't really bothered doing much fixed integer arithmetic. There is one area in that routine where it does, but it makes sense to because it's just blending RGB888 color channel values.
honey the codewitch 16-Mar-22 18:12pm View
Yeah unfortunately optimizations like this won't take my minute down to seconds, which is what I need. I need orders of magnitude of performance improvement.
honey the codewitch 16-Mar-22 14:19pm View
Starting at line 573 here

the tables are here:

I'm using "mixing_plan_fast" although I have two.

Sorry for the length and interdependencies. This code is not really user friendly.
honey the codewitch 11-Mar-22 13:04pm View
That's basically where I'm at right now. I'm going to keep this open to see what other ideas there are out there before I put a lid on it. Just in case there's some cleverness yet to be mined kicking around in someone's head.
honey the codewitch 11-Mar-22 4:45am View
I totally didn't even see the link when i first read the question. must have been having a day.
honey the codewitch 10-Mar-22 13:23pm View
I second PIEBALDconsult here. Where is your stream coming from? If it's coming from a network source Peek() will fail. You really shouldn't Peek() if you want your code to be robust. Use Read() and just keep a copy of the current character around in a variable instead of using peek.
honey the codewitch 8-Mar-22 17:17pm View
Earlier there was an error in my question. I tried two different ways, in the question, and have settled on this

See the edit to the question. The code was right, but my description of what i was doing was wrong in the question before I edited it. Sorry.

Edit: It turns out it was an unrelated bug. My color matching code worked fine.
honey the codewitch 8-Mar-22 16:27pm View
I'm working on figuring that out. I had to take a cat nap =)

Edit: I've edited my question significantly to update where I'm at.

Edit 2: There was nothing wrong with my code to begin with. It was an unrelated bug.
honey the codewitch 8-Mar-22 15:19pm View
And I did check it. Turns out the formula in my question is wrong, but in the code it isn't. I use a variant of the Euclidian method sans the final sqrt() since I don't need it (i'm only comparing relative distances so if i sqrt none of them it's the same as sqrting all of them). I've since updated the question with the proper formula. thanks for catching that. unfortunately it doesn't fix my code. =/
honey the codewitch 8-Mar-22 14:47pm View
the first method is a variant of the Euclidian distance method. The final sqrt is removed as it's not necessary in this case.

... and as I was typing this I realized I was doing it wrong above compared to the wiki.

so thank you for probably solving my issue, albeit just by making me check my work.
honey the codewitch 6-Mar-22 19:31pm View
The problem there is I need to friend the other way around, and I don't have all the template arguments.
honey the codewitch 5-Mar-22 12:21pm View
This is the Arduino framework. setup() is the entry point, and loop() is called repeatedly by the framework for the life of the app once setup exits. There is no exiting "main" - main is implemented as main() { setup(); while(true) loop(); } basically (simplified)
honey the codewitch 8-Jan-22 1:03am View
Happy new year to you as well.
honey the codewitch 8-Jan-22 0:38am View
Yeah, I'm not trying to execute the regular expressions. I'm trying to simplify and compact them programmatically.
honey the codewitch 7-Jan-22 8:25am View
I should have clarified. This is DFA regex. No backtracking constructs. I can already convert to a regex string from a state machine. this is only about simplifying the result.
honey the codewitch 7-Jan-22 8:25am View
I should have clarified. This is DFA regex. No backtracking constructs. I can already convert to a regex string from a state machine. this is only about simplifying the result.
honey the codewitch 25-Dec-21 1:28am View
You're not hearing me. Even if I provided you an example, you would not understand it, and so it wouldn't benefit you. If you were to use it, you could not maintain that code, and I'm not going to maintain it for you.

Therefore I will not give you that. It would be like giving someone my loaded gun.

This is not something you should be trying before you even understand even the basics of how to code C++. Learn how to code some C++ first.
honey the codewitch 24-Dec-21 19:54pm View
It's because you're using cdecl as your calling convention. And how is C# supposed to know the size of your array? You'll have an easier type using stdcall as your calling convention, and yielding an out pointer to the array and an out pointer to the size of the array for your function.

your C++ code is invalid anyway. Anything you declared in the function goes away once the function is complete, meaning you're returning a bad pointer.

Also using unsafe code in C# is inadvisable, because unless something changed, it tends to require full trust, so it won't run unless it's installed in a particular way on the target machine.

I'm going to be very frank with you. You are swimming way out of your depth right now. Learn C#. Learn C++. Then learn how to use them together. Right now you don't know any of them, except maybe some C# from the looks of things.
honey the codewitch 14-Dec-21 13:52pm View
It's baking my noodle. I'll hit you up if I have questions. I'm not accepting just because I want more ideas but I'm +5ing your solution. :) Thanks.
honey the codewitch 8-Dec-21 13:59pm View
I'll look into that, thanks.
honey the codewitch 7-Dec-21 11:10am View
Totally. This code flips physical digital pins on a chip high and low, which it needs to do fast and precisely timed, because it's a driver for an 8-bit parallel bus attached to a (usually color) LCD or TFT display. The frame rates I can achieve with graphics draws are directly tied to this code.
honey the codewitch 7-Dec-21 9:10am View
Hmmm.. It seems a bit sloppy to me because I don't like the idea of introducing arbitrary template arguments just to templatize a function. The code smell, you understand. If I come along in 6 months and every function is templatized with dummy arguments, I don't what I'd do. I think I'll stick with the __attribute((always_inline)) route suggested before, because I'm targeting GCC specifically.
honey the codewitch 6-Dec-21 18:13pm View
That could work, so I'm accepting it, since I wasn't familiar with the attribute prior. I'll give it a shot. I have to optimize for size. I'm not even sure how my toolchain would react otherwise, I just can't afford the extra space, particularly on STM32 boards. I can't use clang because my toolchain relies on GCC and I don't have any control over that. Actually all my IoT toolchains require GCC at the moment.

I do like to compile with both clang and GCC (when i'm not doing IoT-only) but GCC is my primary target.
honey the codewitch 20-Nov-21 5:33am View
I'd have suggested they continue to ask the question until their code magically works.
honey the codewitch 15-Nov-21 13:31pm View
Why did you take a job you're not qualified to do?
honey the codewitch 10-Nov-21 11:54am View
Can you post several example strings, with example matches you'd like to see?

List several variations of this (including one with no matches)

And then below each one, list on a separate line each substring you'd like matched.

AB-0001234/00005-Testing My Regex hereAB-0004567/00007-Second Testing of my regex
--- matches ----

(assuming you also wanted to match Second and Testing - i know you don't, i'm just trying to give you an example)

Anyway, make at least 4 of those, including one with no matches, and I bet you'll have a better time getting an answer.
honey the codewitch 9-Nov-21 22:35pm View
Thank you! That clears it up for me perfectly.
honey the codewitch 5-Nov-21 5:02am View
That was my original plan for Python. I just wasn't sure if it was valid. Actually right now I think my multiline conditionals are indented once rather than twice but it's an easy fix in my generation template. the big issue is knowing what's valid, and secondarily what's pretty. I'm on the fence about double indenting multiline conditionals hanging off of ifs. It's prettier to corner case it, but I don't like it because it's not consistent with the general rule of indenting I follow through the rest of my code. It just rubs me wrong.
honey the codewitch 5-Nov-21 4:34am View
Not in that case, but there are other cases where it's needed. It makes code generation a bear. Fortunately in my current case the blast radius of this problem is limited to if () statements.
honey the codewitch 5-Nov-21 3:08am View
Thanks, I totally blew by the link in the reply. It's the hour that it is. I'm not altogether with it right now. =)
honey the codewitch 5-Nov-21 1:29am View
Are you sure it's not indented at the next level? My google fu isn't helpful right now, and I don't want to stop what I'm doing to start an install of that mess. Oh well. I'll figure it out one way or another. Thanks.
honey the codewitch 11-Jul-21 11:55am View
I can't target C++20 unfortunately. I'm limited by the minigw gcc version used by platformIO under windows (the least up to date build platform) and that means C++14
honey the codewitch 11-Jul-21 11:54am View
> Can't you just say that instantiations must include various has_blah functions

In some cases, maybe if I had designed it that way. However, because things are typed to a pixel definition and other things, you can't use bool functions for every case. You have to use usings in some cases. Since I already have a using for this case, I find it inelegant to require the draw target implementer to create function to say essentially the same thing.
honey the codewitch 11-Jul-21 8:28am View
I have an idea though. I'm wondering if I can't go template<typename T,size_t NativeBitDepth=T::native_pixel_type::bit_depth> struct test_for_native_pixel_type { ... } or something like that. I don't know what the compiler will do there if native_pixel_type isn't declared. My assumption is that it would error but perhaps it wouldn't. I need to check. It would only be zero if native_pixel_type was not present and the compiler had to choose a default for size_t. It *could* work, i just don't know if it will.
honey the codewitch 11-Jul-21 8:21am View
I have "draw destination" classes which are loosely defined (bound via template) and have an interface/contract that includes usings. One of the members might be something called native_pixel_type and if it's present it tells me that "virtualization" is being used which means it's dithering. If it's dithering I don't want to use anti-aliasing to smooth the edges of fonts because there's not a true grayscale to work with, just black and white.
honey the codewitch 25-May-21 11:50am View
Whoops, I forgot to increment my fill pointer. Not sure what i was thinking. Still, it doesn't solve my issue but thanks for spotting that.

Edit: Never mind. retr() will fill "fill" each time with new data. The y is just there to make sure it gets called the right number of times.
honey the codewitch 25-May-21 10:57am View
The reason it's defined that way is it's 16-bit color values, but send and retr take a byte array. It's fine - casting does nothing to the data. It only changes how the data is perceived. It is a "pure" operation with no side effects (unless it is overloaded, and in this case it isn't). say you had a 16 bit word of 0xC1A2. If you cast that to bytes you'd have a byte C1 followed by A2 (actually reversed on little endian systems but you get the idea). send and retr deal in BLOBs which are byte arrays, effectively. But it's easier to deal with pixels in their native format, hence the discrepancy there. a 16 bit pixel is R:5, G:6, B:5 so you can't split it cleanly.

As to your second question, each color is 2 bytes. The pixels are 320 across. The compiler will "fold" the value to 640 with no runtime overhead, but defining it this way makes it clearer that it's 320 pixels of 2 bytes each. It's just a way to express intent with code.
honey the codewitch 24-May-21 8:59am View
If he does, he'll regret it. I didn't post the answer for him. I posted it because it was a good question. I half assumed he'd be kicked for the autism remark.
honey the codewitch 10-Apr-21 7:37am View
Thanks. I actually tried that after I posted the question, but I had the syntax wrong. I ended up writing a helper function to disambiguate. It's for the best anyway that I did it that way, in the end. Still, this is the proper solution.
honey the codewitch 2-Apr-21 3:19am View
Prototype it in C and then simply spit the asm out using the compiler.

There's hardly any reason to use an assembler directly anymore, and many good reasons not to, but if you *must* use an assembler, use C or C++ to prototype your assembly code where you can.

The above can easily be written in C, so write it in C, and then use your favorite C compiler to get the assembly from it, and then look at that.

You haven't specified which assembly you want. Are you coding for an ATmega2560, a Tensilica, an ARM, x86?

Don't bother. Just use C and get asm that way. If you want to tune it from there you can.
honey the codewitch 17-Mar-21 12:17pm View
Okay, it sounds like what you're really trying to do is access something like a control from outside the form it's declared on. For example, you have class a that needs to access an instance of Form.cs. Where is Form created? Because first you'll need that. If it's your main form, it's created in Program.cs in the Main() routine as part of Application.Run().. it calles "new Form()" - you will need the value it returned to access any fields in it. It is simply not otherwise directly possible since that form could be anywhere in memory. Or there might even be more than one of them, or none of them. Without some sort of access to the "pointer" for the instantiated Form you are out of luck. Form is just a class. It's nothing until it's created with "new"
honey the codewitch 3-Mar-21 12:53pm View
src/vfs.hpp:152:31: error: invalid conversion from 'int (*)(int, stat*)' to 'const void*' [-fpermissive]

I can't set the permissive flag because gcc is run as part of a large, complicated toolchain and it doesn't like to be touched.
honey the codewitch 3-Mar-21 12:38pm View
Yeah i caught that a minute ago. it amazes me i let that go. I've updated the code. it still doesn't compile.
honey the codewitch 22-Dec-20 10:03am View
I know i know. it's early and i'm sleepy and typos and poorly worded thoughts flow freely from me right now.

Edit: (per yours), Yeah I may need to break out paint!
honey the codewitch 13-Dec-20 11:29am View
Normally I don't find much occasion to mix them, but I wanted a more compilery, less preprocessory way of defining a maximum capacity for a fixed length array.

I'm not aware of a better solution to the problem than what I've done above, in this particular instance. The code difficulty is limited because the class isn't that complicated. This was one wrinkle, and it was a compiler SNAFU. A good reason not to use it sure *if a better replacement can be had* but I'm not aware of one for this case.
honey the codewitch 13-Dec-20 10:37am View
Totally. They can be frustrating at times, but Accelerated C++ changed my life and I do a lot of generic programming now. Less so on Arduino stuff but still.
honey the codewitch 13-Dec-20 10:32am View
nah it should be able to forward precisely *because* it's virtual. there's a vtbl in play so it just needs to find the function.

Turns out the compiler was looking for a global function called initCapture().

Since it's part of a template there's a 2 phase resolution process in C++ and it wasn't picking it up as part of the class.

So if you do this->initCapture() it all works fine. It gives the compiler what it needs to look in the right place (the base class) for the function.
honey the codewitch 11-Dec-20 19:59pm View
Wonderful! I'm so glad when my stuff can help someone. We all start somewhere. Good luck with your project!
honey the codewitch 11-Dec-20 9:45am View
unique_ptr takes the type and decorates it so you're creating a pointer to a pointer. Solution 1 is the correct answer.
honey the codewitch 1-Dec-20 7:07am View
You've said nothing about the problem. You've just mentioned that a problem exists. How is anyone supposed to help you when they don't know the nature of the problem you are running into? "Licensing issues" is not a description of the problem, and most people may not have heard of "black duck scan"
honey the codewitch 30-Nov-20 20:36pm View
You can't use windows forms in core 3.0. Either way you're going to need to create a window from the looks of it. It might not need to be visible. That, and the code I offered is what I have. If you want to know about TWAIN you'll just have to study it as I don't know anything about it.
honey the codewitch 29-Nov-20 12:48pm View
Hey thanks. This is awesome! You don't mind if I use a derivative of this code in a commercial gadget do you?
honey the codewitch 29-Nov-20 11:47am View
Thank you!
honey the codewitch 29-Nov-20 9:23am View
I can't do it that way because readNextPoint() reads from flash which is very slow. I need to do it one sample at a time to keep things running smoothly, if I can at all.

Therefore if my solution gets me the same as your solution I prefer my way. I actually endeavored to avoid doing it the way you do.

I should add that the number of points is compile-time configurable depending on the defined resolutions so sometimes that loop might be much larger. =)
honey the codewitch 29-Nov-20 8:30am View
I'm going to add to make it explicit. It appears his data and not his query is the real culprit. I'll also explain INNER JOIN here since he was asking. Inner join simply combines columns from two tables where one or more columns in one table correspond to some columns in the other table (either directly or indirectly through a formula)
honey the codewitch 28-Nov-20 7:53am View
Beat me to it
honey the codewitch 25-Nov-20 19:34pm View
I'll have a crack at this after I've had some sleep but what really jumped out at me was it's spelled "vertical" not "virtical" and I'm having a hard time getting past that.
honey the codewitch 20-Nov-20 6:23am View
This should be in the "Demands" section.

You may have heard differently, but this site isn't full of monkeys that will simply do your bidding.

Perhaps study.
honey the codewitch 15-Nov-20 10:34am View
ooh that could be fun depending on whats on the other COM ports. :P
honey the codewitch 14-Nov-20 12:47pm View
I'll say it again: if you have to rely on undocumented functions to release an object, you are doing it wrong.

The proper way to request that a disposable object dispose itself is IDisposable.Dispose().

Disagree all you want, because it doesn't change the facts on the ground. The framework doesn't care about your disagreement, frankly.
honey the codewitch 14-Nov-20 11:37am View
I'm going to don my software architecture hat for a moment to say if you need to use undocumented functions to free objects you've been doing something terribly, terribly wrong in the first place. Take a step back and retrace how you got here, because you made a wrong turn. There are so many reasons not to do what you are trying to do. It's a large flaming anti-pattern.
honey the codewitch 13-Nov-20 11:20am View
I know it's kind of not, because Ints can interrupt anywhere, but (maybe not with the ESP32) when an interrupt is called the other code is suspended, which is why i said it's single threaded for the purpose of the code. I may have been making a bad assumption about the value of timestamp, but above is what i meant by consider this single threaded - there's no other code running at the same time, but yes i know it can pull an interrupt anywhere.
honey the codewitch 13-Nov-20 11:17am View
That's great to know. I am still brand new to the ESP32, and fairly new to the Arduino and ESP8266 modules as well, but I've at least built several things with the arduino, and ESP8266s so far.
honey the codewitch 13-Nov-20 8:32am View
I'm a member of the ESP32 forum on reddit. I looked there first but didn't see anyone posting code, so I figured I'd try here first. Wasn't sure how they'd feel about blowing up their forum with all that source.
honey the codewitch 13-Nov-20 8:26am View
Ah yeah I reread it and you're right. Still, the code shouldn't hurt. The 3rd solution was the fix.
honey the codewitch 13-Nov-20 8:25am View
BRILLIANT! Thanks so much!
honey the codewitch 13-Nov-20 8:23am View
I'm not sure the standard library is available on arduino's devkit but i'll try this. Thanks.
honey the codewitch 13-Nov-20 5:15am View
It doesn't assume that, or rather, the assumption is safe, since loop() would simply skip the timeout check on that iteration.

Also, for the sake of this question, consider the code single threaded.
honey the codewitch 13-Nov-20 4:47am View
Ummmm, ish? AFAIK all the code seems to be single threaded, and yet the thing is dual core. Also it was said I needed to use volatile on global vars accessed within interrupts like callback which suggests some sort of concurrent access I think. I didn't mark _timestamp with volatile above but i have to no avail.
honey the codewitch 13-Nov-20 4:43am View
Read the code and read the comments in the code. millis() doesn't work in that routine

If you see loop() routine

// for callback():
  if (!_timestamp)
    _timestamp = millis();

That indeed resets the timeout. The comment is correct.
honey the codewitch 15-Oct-20 14:22pm View
You're creating exactly what I'm talking about. Don't worry about it. =)

I meant the best thing is have all the hacks behind something as "clean" as you can create, but it sounds like you're doing that.
honey the codewitch 15-Oct-20 14:21pm View
I should add, EnumWindows() and its derivatives don't give you a stopping condition. They will keep calling you back with windows until there are no more but you won't know when there are no more because it will never tell you. I rig a timeout for it.
honey the codewitch 15-Oct-20 13:59pm View
About the best you can hope for is make a facade out of this and expose an API for it so you don't pollute more of your code than absolutely necessary.
honey the codewitch 15-Oct-20 9:49am View
I think you should try your next approach. It's what I would have suggested. Keep in mind you're trying to interact on some level with an app that wasn't designed to interact with your app so anything you do is going to be somewhat ugly. Windows has crappy window finding APIs - that's the bottom line. Usually an app will be designed for interaction and they will publish an API into the Running Object Table, obviating the need for window based interaction. Even if they relied on windowing for IPC the server app would publish its window in some way known to the client so the client knew how to get to it later. You don't have luxury. Given all that, you're on the right track.
honey the codewitch 2-Oct-20 15:33pm View
Presumably you have a reason you'd like the order preserved but the JSON spec does not guarantee the order of named items - that's what XML is for. Basically what you want is to hack the JSON protocol to meet your requirements. Not that it can't be done, but know that what you want to be doing is a hack.
honey the codewitch 24-Sep-20 13:05pm View
I'm not going to remote desktop with you, sorry. I don't have any more time for this right now anyway.
honey the codewitch 24-Sep-20 12:07pm View
okay, fair enough. i'm having trouble tracking down where the bottleneck is then.

If calling Reader() from another thread didn't solve it, and if the bottleneck is not that Api() stuff you're doing (which looks a whole lot like a COM port read) then I don't know where your bottleneck is in your code, and since I cannot run the code I cannot find that out.
honey the codewitch 24-Sep-20 10:54am View
I found the problem I think. I can't test it though. I think your bottleneck is either your USB or COM port (whichever you are using).

I can keep a form responsive for you, but as you said that doesn't matter. What matters is you need to be able to submit to a database while other card reads are occurring.

Here's your problem - you don't have enough bandwidth. If it's USB, you need more than one bus. If it's a COM port you're going to need a lot more of them if you want to do a lot of concurrent reads.

Going through your code, indeed, firing the Reader() method on a separate thread will keep the form responsive but it will not make the reader hardware more responsive.

Especially if you're using a COM port, there simply isn't enough bandwidth
honey the codewitch 24-Sep-20 5:56am View
Yeah, it turns out, it needs an entire rewrite.

Your code isn't usable. So I'm trying to reverse engineer the Api you have for hardware I don't even own. Be patient
honey the codewitch 22-Sep-20 10:53am View
And multithreading is not really something you want to be doing after two months.

It's like doing an engine/motor swap on a car right after learning to change the tyres/tires

I'm going to see if i can rig up something for you that avoids it
honey the codewitch 22-Sep-20 10:52am View
okay. i'll look at it. here's a temporary email address i'll look for it from
honey the codewitch 22-Sep-20 10:46am View
i don't have the hardware to run it. and I can't rewrite everything without it which is the first thing to do.

for code to be multithreaded it has to be well encapsulated. You have no consistent encapsulation from what I've seen. every member is whatever you thought you'd need at the time, and where's the planning?

sit down, plan it, then write it. consider your first attempt a draft.
honey the codewitch 22-Sep-20 10:31am View
And that's what you want? Well, since your code is all jacked up anyway, maybe try creating the entire form on its own thread.

ThreadPool.QueueUserWorkItem((state)=>{Application.Run(new myForm());});

Which may or may not work.

Honestly I'd never accept your code if I was reviewing it. So if this is for work? Rewrite it. It could get you fired.
honey the codewitch 21-Sep-20 9:50am View
Part of your problem is you're trying to run before you can walk. Multithreading is one of the most difficult programming problems. Your code isn't clean, isn't readable, and isn't properly encapsulated, so you can't build it up without it falling over under its own mess. Trying to make it multithreaded is just going to make anything wrong with it that much worse.

That's why I suggested the rewrite after the first couple of things didn't work.
honey the codewitch 21-Sep-20 9:46am View
It could be a limitation of your device. Bandwidth isn't infinite. Or it might be somewhere else in your code, who knows? Frankly your code is a mess, and I can't even make enough sense of it to tell you that what you're doing now is thread safe. That's why I suggested a rewrite in my other reply.
honey the codewitch 21-Sep-20 9:15am View
I don't want to be harsh, but that code is very difficult to read, and looks like even if it was "working" it would crash due to a race condition. I just can't make something whole with what I was given.
honey the codewitch 21-Sep-20 8:58am View
Yeah, but you're not going to like it: Go back, reread the documentation for the RFID equipment, and then rewrite the code entirely.
honey the codewitch 20-Sep-20 9:57am View
adding, I think your app has design problems that are well beyond the scope of this Question and Answer forum.
honey the codewitch 20-Sep-20 9:55am View
I think you need to take the timer or loop out of RfReader()
I think you need to move it into your loop

while(true) {
RFReader r = new RFReader();
r.Read(); // you'll have to add this method

Like that. I still have no idea what you're doing with the results of it, but I imagine whatever it is it's probably not thread safe anymore
honey the codewitch 20-Sep-20 9:43am View
while(true) {
// do work

Inside that loop you might try creating the RFReader() and using it, and then destroying it each time.
honey the codewitch 20-Sep-20 9:41am View
while(true) {
// do work
honey the codewitch 20-Sep-20 5:26am View
Let me see if I can untangle this code and figure out where your per instance data needs to be. I might not have a solution for you right away, since it's 2:30am and I need to go to sleep again at some point but I'll try to figure this out based on what you posted.

Edit: Can you use more than one instance of RfReader() at a time? if you can then I may modify the code to create one RfReader() per call and then eliminate the timer call from RfReader() entirely. If you spin a loop in your thread you won't need a timer anyway.
honey the codewitch 20-Sep-20 5:11am View
It looks like you're going to have to modify your code extensively then because your reader routine uses member fields from the looks of it. That means one reader per form which is not what you want. You should be putting those members you are using in a class, and using one class instance per reader call. Something like that anyway. I can't see enough of your code to be sure exactly what you're doing there but basically, you have a design issue from the looks of it. Your member variables are one per form, and i think you need them to be one per reader.
honey the codewitch 20-Sep-20 5:10am View
It is familiar, but it's also a pain to demonstrate the use of it in this format because there's just a lot to hooking it up. And every method I gave him spawns a background thread. Either way, it looks like his issue is a design one since he is using member variables in Reader() and wants multiple instances of those variables (1 per reader instead of 1 per form)
honey the codewitch 20-Sep-20 4:57am View
It looks like you're going to have to modify your code extensively then because your reader routine uses member fields from the looks of it. That means one reader per form which is not what you want. You should be putting those members you are using in a class, and using one class per reader call. Something like that anyway. I can't see enough of your code to be sure.
honey the codewitch 20-Sep-20 4:45am View
I mentioned it, but it's actually more code to use it, which is one of the reasons I don't like it. More code = more potential for bugs, and frankly, BackgroundWorker kind of obscures things a little too much for my taste. Just my $0.02 but I don't think the class should even exist.
honey the codewitch 5-Aug-20 11:26am View
Richard, I agree with you and I'm guessing his prof is feeding him .NET 1isms. And it doesn't surprise me that it's javalike naming if it's coming out of a school. Seems like all those cats deal in is java, even if they're mucking about in a different language.
honey the codewitch 4-Aug-20 11:31am View
If you are writing web server code keep everything synchronous! ASP.NET is not designed for async. The page lifecycle runs beginning to end, so all processing must be done sequentially for the page to render anyway. All you'd be doing is messing up ASP.NET's thread pool heuristics since it's not designed for this. Better to not use Task at all. Hope this helps!
honey the codewitch 4-Aug-20 11:15am View
Thanks folks =)
honey the codewitch 3-Aug-20 15:40pm View
You should use a ManualResetEvent object to trigger when the thread is done. do a different one for each thread. When you need to wait call WaitHandle.WaitAll() and pass it all if your ManualResetEvent objects. You set one of those with Set(). If you do WaitAll() it will wait until they are all set.
honey the codewitch 3-Aug-20 15:13pm View
I won't post this as an answer, because it's not, but you'd have a much easier time I think using Tasks instead of threads. Then you can just await them
honey the codewitch 7-Feb-20 13:41pm View
Thanks so much. I figured out what it was doing, I think, and converted it to a struct which *should* work. *knock on wood*
honey the codewitch 9-Sep-19 15:13pm View
hey, I added some stuff to make it easier to use. Quick Demo in "scratch"

You can now take the reader and do like reader.SkipTo("field1","field2",0 /*array index */,"field3");

like that

Quick and dirty Demo is in "scratch" at my github

Hope that helps. Remember that skip to field lands you on the FIELD not the Field's value, so you have to call Read() one more time if you land on NodeType of Key

Call ParseSubtree() once you're positioned on the subtree you want to parse into objects. You can then use JSON path on that.

Here's the source link

hope that helps!
honey the codewitch 8-Sep-19 12:43pm View
That only accepts a flat field name. If it can't find it it returns null. It's literally looking for a field with slashes in it in your query (and that's doable in JSON) Instead you have to do like:

reader.Read(); // i think you need this. maybe not. comment out if need be

to navigate to "foo/bar"

I don't support JSON path in the queries, nor "xpath" here because i didn't write the JSON path part and it only works on the trees you get back from ParseSubtree()

adding, if it was supported it would be JSON Path syntax is more like "$"
honey the codewitch 6-Sep-19 2:07am View
Not so easily, it's a lot of code. The whole point of this exercise is to avoid having to write it.

If you don't get what I'm asking, that's totally cool. I found another solution anyway that sidesteps this whole issue.
honey the codewitch 5-Sep-19 4:42am View
Unfortunately I can't lock the source classes because they aren't mine.

In order to do so I'd have to make wrappers for every single item.

Basically I want .NET to do it for me, except .NET uses a different technique to accomplish the same (it uses a form of message pumping/signalling to synchronize calls)
honey the codewitch 2-Sep-19 23:38pm View
things like concurrentdictionary are not what i want. I'm not looking to use synchronized dictionaries. I'm looking to martial calls and sink them on a particular thread, hopefully with .NET doing the marshalling for me like it does with ISychronizeInvoke
honey the codewitch 30-Jul-19 1:19am View
thanks! and just what I was hoping for.
honey the codewitch 25-Jul-19 10:25am View
One of these days, I should install VB =D
honey the codewitch 25-Jul-19 10:20am View
I think that's one bounded, like VB's default. I'll have to check.
honey the codewitch 25-Jul-19 10:09am View
what's the proper syntax for declaring this (zero bounded of course) in VB?

if you know.
honey the codewitch 25-Jul-19 9:58am View
you have some serious google fu. I'm rusty I guess. Frankly, I wanted to declare this DFA table as a simple nested int array like my parse tables but despite a DFA (the structure i'm serializing above) being conceptually simpler than a PDA (the ints i'm serializing) mathematically, the data structures for them are more complex than such a nested array solution would allow for.

I've half a mind to declare a DfaEntry struct and be done with it.

Frankly I don't even know the proper syntax for that in VB so I can't really blame the VBCodeProvider LOL
honey the codewitch 25-Jul-19 9:39am View
i'll update my question. Thanks. I tried not using the initializers, and just setting it to [0] in CodeDom but it didn't change anything. I may have to special case for VB and insert a CodeSnippet object to do this =(

thanks for your help. I'm fresh out of coffee and have been slow this morning. heh.
honey the codewitch 25-Jul-19 9:26am View
whoops. sorry, never used the site before. i thought it just edited in place.

here you go: Demo
honey the codewitch 25-Jul-19 9:24am View
I repro'd it. Check the demo at your link. and thanks again
honey the codewitch 25-Jul-19 9:23am View
Richard I repro'd it. Check your Demo link
honey the codewitch 25-Jul-19 9:15am View
Thanks Richard. I guess I didn't repo it right because the same code breaks on my machine.

I'd give you the actual data I'm serializing to the codedom but it's pages long.
honey the codewitch 24-Jul-19 15:19pm View
i mean sure. but now how to get the codedom to render that properly.
honey the codewitch 23-Jul-19 17:11pm View
well yeah i think it is a value type in that it derives from ValueType instead of directly from object, but that's not really what i'm looking for as int also returns true there too.

you can't declare partial generics but you can call typeof on them so like typeof(IList<>) works but class foo : IList<> {} does not

i think the ValueTuple just uses ref internally (is a ref type) or something like that. i'd have to check
honey the codewitch 23-Jul-19 12:54pm View
That's what I figured but Richard Demming below found the magic I was looking for. Requires .NET 4.71 but that's fine.
honey the codewitch 23-Jul-19 12:52pm View
There's the magic I was hoping for! re: ITuple
honey the codewitch 23-Jul-19 12:32pm View
i'm pretty sure i tried that and it didn't work for me. My tuples i'm using as a test set have two arguments. That might have something to do with it. I also tried typeof(Tuple<>) on a lark. I can't do typeof(Tuple<,>) because i don't know how many arguments the tuples will have in advance. I'll try Tuple again just to be sure and amend my response if i'm wrong
honey the codewitch 23-Jul-19 12:31pm View
whoops my mistake. I had my mind on other things. I've kind of retired the question as I stopped using tuples here but I'd still like to know a solution
honey the codewitch 12-Jun-19 8:21am View
can you give us a C/C++ header for the struct you are importing?

I need to see the native types to get you a proper p/invoke

it may need to marshal stringbuilders or fixed length strings inside the struct or something. it could be anything. i need to see the native header for the struct
honey the codewitch 5-Jun-19 9:35am View
honey the codewitch 10-May-19 11:51am View
Aaand I solved it. Sure enough, an inner loop was required (could have been done recursively)

It's kind of involved. Your solution didn't quite do it, but it almost worked. I am using a variation of the concept in it anyway
honey the codewitch 10-May-19 11:39am View
I don't think I'm explaining myself well. I mean recursive in the same way a sort() method might be. recursive comparisons, not comparisons over a recursive data structure, if that makes sense.

adding, it's possible to make those things recursive.

expr -> term expr

honey the codewitch 10-May-19 10:34am View
yeah I'm using a dictionary in my code, but thanks for the heads up anyway. I'm basically adapting what you solved to see if it works. It looks too simple. I'm almost positive the solution will be recursive or at least use nested loops, but maybe I'm wrong. If you're interested, this is part of a larger problem called left factoring LL grammars

honey the codewitch 10-May-19 9:28am View
you might have something there but i have to wrap my head around it. MOAR coffee. =) Thanks.
honey the codewitch 10-May-19 9:08am View
but how do I know what the prefix is without other items to compare it to?

like in

expr -> ambig2 ambig3

is the prefix expr->ambig2 or expr-> ambig2 ambig3

the trouble is I only know the prefix when compared to other items.
honey the codewitch 10-May-19 8:49am View
you can consider them strings for the purpose of the question.

but they are arrays of System.Object - where the object is usually a string. Consider the objects to be comparable with equals

Consider the Left of a -> to be the first element, if that helps

The problem is independent of whether they are arrays or strings, the algorithm will be the same either way.
honey the codewitch 27-Apr-19 1:02am View
It used to be de rigueur to do as much validation as realistic in each of the tiers of a multi-tiered app. For the same reason you'd sanitize db inputs on a webpage, but also to protect against attacks if they manage to secure a user level connection to the DB directly.

But that was years ago. 3 tier is old school these days.

Basically though, you'd have the web page provide first tier validation, the middleware perform 2nd tier validation, and where possible, do validation in the DB stored procs.

that way no matter what, your data is hardened against being poisoned by external actors no matter what tier they are operating at.
honey the codewitch 1-Apr-19 14:47pm View
whoops, i need more coffee. Still that should be easy enough to port to javascript.

just using string concatenation instead of stringbuilder
honey the codewitch 20-Mar-19 4:19am View
Thanks. The last time I tried using ILMerge for this it wound up breaking for some builds and never could figure out why. That was years ago when it was still posted over at MSR or someplace and experimental. I forgot about it until you just mentioned it.

I'll certainly revisit that again.

I want to avoid embedding references as resources (something I've considered) because of the additional concerns it raises in terms of .NET security restrictions and non-fixed disk space requirements - usually doesn't matter but when it does it breaks bad.

I'm going to hold off accepting just to see what other ideas people have, if any.

Your answer regarding ILMerge is potentially a good solution, but I need to look into it.
honey the codewitch 19-Jan-18 13:22pm View
part of the reason i'm asking the question is to determine how useful it would be to release the generation tools i built and use to work around this. they're terribly unpolished and work for my narrow scenarios. but they help me get around this issue.

the other reason i'm asking the question is I don't like to use the generated code for that in certain areas of my source, so I've developed some patterns to work around using foreach/yield everwhere, but the patterns look "stupid" unless you know why I do it. they look like anti-patterns. I don't like code that looks like anti-patterns. I get suspicious - even of my own code. =) I also tend to assume I am kinda stupid compared to the people that designed the language. it keeps me humble enough to make assumptions in the right order, to wit, first assume error or ignorance on my part since it's most likely.
honey the codewitch 19-Jan-18 12:59pm View
i don't think the VM is the problem.

it's more just the way iterator/yield and linq work.

stuff performs fine when i hand roll it.

honey the codewitch 19-Jan-18 12:58pm View
that's what I assumed.

the question was in service to checking that assumption.

i prefer asking questions before deciding on a conclusion.
honey the codewitch 19-Jan-18 12:51pm View
you were arguing with Wes Dyer's conclusions, not mine. That's why I said argue it with him.
honey the codewitch 19-Jan-18 12:50pm View
not without rewriting pretty much all of linq AND doing code gen on all iterators instead of relying on yield.

i've considered it.
honey the codewitch 19-Jan-18 12:48pm View
if i was writing business logic or something they'd probably be fine, even on the server end.

but what i'm doing falls closer into compiler/parsing tools and learning systems (together) - which unfortunately, tend to nest a lot more, and tend to require a bit more "real time" responsiveness compared to displaying a web search or something.

(different types of performance basically, because of different problem domains)

and while my code isn't doing something like DSP/Digital Signal Processing where truly fast streaming would be necessary, it's basically somewhere between that and the larger, chunkier performance issues in dealing with most applications, especially biz-data based applications like many web apps, which is what a lot of .NETs features are geared for.
honey the codewitch 19-Jan-18 12:47pm View
if i was writing business logic or something they'd probably be fine, even on the server end.

but what i'm doing falls closer into compiler/parsing tools and learning systems (together) - which unfortunately, tend to nest a lot more, and tend to require a bit more "real time" responsiveness compared to displaying a web search or something.

(different types of performance basically, because of different problem domains)

and while my code isn't doing something like DSP/Digital Signal Processing where truly fast streaming would be necessary, it's basically somewhere between that and the larger, chunkier performance issues in dealing with most applications, especially biz-data based applications like many web apps, which is what a lot of .NETs features are geared for.
honey the codewitch 19-Jan-18 12:42pm View
helpful! thank you
honey the codewitch 19-Jan-18 12:41pm View
i don't use LINQ precisely because of this.

> Right now I hand roll a lot of enumeration stuff, because LINQ performance is unacceptable for extensive use in things like GLR parsers, and part of it is this limitation of yield.

But it's just a lot of work *not* to use it.

Which is why it's looking more and more appealing for me to move away from C# and back to unmanaged code.


honey the codewitch 19-Jan-18 12:36pm View
which is what I do. currently.

and it's a side-effect of programming things that rely heavily on set based operations, like most parser generators, just for example.

and yeah, whether it's LALR(1), LL(x) or even FAs there's going to be a lot of iteration and set functions.

nature of the beast.

typically, i'd be using STL in C++ to do things like this.

but for reasons that are outside the scope of this, I've been moving a lot of research code to C#. That includes compiler/parser stuff.

Like I said, if you don't have an answer, that's okay.

I honestly didn't expect anyone to have one.

But it's a good idea to check expectations, especially give i don't usually muck about with the newer C# language features.

hence why i asked the question.
honey the codewitch 19-Jan-18 12:28pm View
like is typical with lots of LINQ queries, similarly my code nests these operations deeply.

so yes, it's an issue.

oh, and depending on the collection, we're dealing with things like LR rules so 1500 isn't even uncommon

honey the codewitch 19-Jan-18 12:25pm View
fine, it's called concat.

the point still stands. because Union isn't the point. perf is the point.

rename it concat if it helps you answer the question i was asking.

and if you don't have an answer that's fine.
honey the codewitch 19-Jan-18 11:58am View
also the reason for the overhead is that those two inner iterators - also yields, could have been rolled into this class. instead you have 3 classes each running their own state machines. it leads to spikes in the perf graph as Wes Dyer already shows at the link.

unless you want to call his perf graphs a lie
honey the codewitch 19-Jan-18 11:55am View
you're more than welcome to argue with guy who on the C# dev team that wrote the article I linked to.

but i don't see the need to reargue it.
honey the codewitch 19-Jan-18 11:00am View
I don't care about bit twiddling overhead.

Look at the article in the link. This isn't about a little bit of overhead.

It's about time complexity of O(m+n) where m is the number of items in the first sequence and n is the number of items in the second sequence. And it gets worse as you nest, the outermost call is O(m+1). The next call has O((m-1)+1), then O((m-2)+1), ... O(1+1). There are m of these calls so the running time should be O(m^2). Essentially, composing concats together like this causes O(m^2) yield returns to be executed.

(from the article, with performance graphs)
honey the codewitch 17-Jan-18 22:27pm View
have iterators changed that much in 9 years?
honey the codewitch 17-Jan-18 22:25pm View
this isn't about blaming anything.

it's about not writing enumerator classes by hand anymore if there's a better way to avoid it.

consider me a nihilist when it comes to frameworks and blame.

i don't care who is at fault. i'm just looking for a way to keep using C# even as i basically have to hand-roll a significant subset of what linq and yield provides from scratch an awful lot more than I'd like to.