So this is fun: a war story
-
honey the codewitch wrote:
plus it has been drilled into me to avoid crit secs
Not sure why you say that: critsects are lighter sync objects that can be used only inside a process. That might avoid an expensive context switch. That's my thinking at least.
Mircea
Unlike mutexes & semaphores, a critical section is not a Kernel object. Acquiring a mutex or semaphore always requires a switch into kernel mode, which is not necessarily true for critical sections. The major disadvantages of critical sections are: 1. They are not shareable between processes (unlike semaphores and mutexes) 2. They are not recursive (unlike mutexes)
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
Unlike mutexes & semaphores, a critical section is not a Kernel object. Acquiring a mutex or semaphore always requires a switch into kernel mode, which is not necessarily true for critical sections. The major disadvantages of critical sections are: 1. They are not shareable between processes (unlike semaphores and mutexes) 2. They are not recursive (unlike mutexes)
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
That matches exactly what I knew. In my case I didn't need inter-process synchronization. I just needed to serialize access to a ring buffer between a producer and consumers.
Mircea
-
I'll keep it as a crit sec i think. Performance isn't critical in this in any case. If anything the PC runs too fast for what I need it for, except when doing SPI and I2C emulation. It's basically a way to connect Arduino's HardwareSerial class instances like Serial, Serial1, Serial2 etc to actual COM ports. Eventually I plan to also expose a virtual COM port so that you can connect to the PC without a loopback (which I'm currently using for testing). Current attempts at that have gone... poorly. No BSOD, but given i have to enable test signing to even get the driver to install, I don't want to force that on people, so i may nix it unless there's an easy way to get a software cert. I haven't looked into it. Oh and when I did try to install the DDK sample, it installed, but didn't show up as a COM port and so I have no way to uninstall it that's apparent.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
honey the codewitch wrote:
unless there's an easy way to get a software cert.
If you find one, please share it with us. I'm looking for the same.
Mircea
-
Oh it's definitely a deadlock. I'm just not sure where, and I think a lot of it has to do with me misunderstanding the behavior when reading COM ports under win32.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
found this on stack overflow: "Serial port causes deadlock after some non fixed number of writes (C++)" It is from 8 years ago. https://stackoverflow.com/questions/28438045/serial-port-causes-deadlock-after-some-non-fixed-number-of-writes-c[^]
-
Oooh I'll take a look. Right now I'm getting a hang on open, which is unfortunate. I may need to reboot and start fresh, but I'll download what you linked to first. Thank you. There's obviously some black magic here, and COM ports have never been particularly friendly when they decide not to work.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
Are you running open loop (continuous polling the buffers)? Are hardware interrupts involved? It's been too long ago for clarity, but my serial port adventures usually ended up by running some sort raw polling routine and do all the character interpretation and buffering if needed in the same loop. But I may just understand your problem. I do sympathize with need for solution. couldn't sleep on it either. BTW I did not C file I/O opens and reads.
"A little time, a little trouble, your better day" Badfinger
-
Are you running open loop (continuous polling the buffers)? Are hardware interrupts involved? It's been too long ago for clarity, but my serial port adventures usually ended up by running some sort raw polling routine and do all the character interpretation and buffering if needed in the same loop. But I may just understand your problem. I do sympathize with need for solution. couldn't sleep on it either. BTW I did not C file I/O opens and reads.
"A little time, a little trouble, your better day" Badfinger
I am running a loop on a thread for each COM port, using non-overlapped I/O. It's primitive, but it works well enough. Well, it does now. It was freezing up on the call to
FileOpenW(L"\\\\.\\COM25",...)
but a reboot fixed it and it's all working great now.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
It's hanging on Opening the com port with
FileOpenW(L"\\\\.\\COM25"...)
despite it being valid. I may need to reboot as prior crashes could have hung the COM port or something. Still, I wish it would time out.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
You need something like this ... RS232 Breakout Tester LED Monitor, DB9 Male to Female Breakout Module : Amazon.com.au: Computers[^] but using a breadboard and LEDs would be far cheaper. Then you can see what is happening. It was one of most trusted testing tools, back in the day...
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
-
You need something like this ... RS232 Breakout Tester LED Monitor, DB9 Male to Female Breakout Module : Amazon.com.au: Computers[^] but using a breadboard and LEDs would be far cheaper. Then you can see what is happening. It was one of most trusted testing tools, back in the day...
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
A reboot fixed it. I guess a previous crash maybe left the com port in a bad state.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
A reboot fixed it. I guess a previous crash maybe left the com port in a bad state.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
Yeah, it can get stuck and confused... Glad it is sorted
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
-
I am running a loop on a thread for each COM port, using non-overlapped I/O. It's primitive, but it works well enough. Well, it does now. It was freezing up on the call to
FileOpenW(L"\\\\.\\COM25",...)
but a reboot fixed it and it's all working great now.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix