#WinUI Serial Monitor

1380 messages · Page 2 of 2 (latest)

honest pulsar
#

ligthmode

#

and lightmode is even worse

night peak
#

You can restyle it

#

Tho this is a little tedious in this framework

#

Do you want to make it so that the background colour never changes?

#

Or do you only want to disable the orange underline?

honest pulsar
#

uh I like theres an indicator that ure in the box

#

if it just changed colour slightly and had no underline it would be nice

night peak
#

It just doesn't fit your design tho

honest pulsar
#

sorry for the late reply had to clean something up

night peak
#

Anywhere

honest pulsar
night peak
#

No not MAUI

#

You would write Grid.Resource or something instead

honest pulsar
#

doesnt accept that eitehr

night peak
honest pulsar
night peak
#

No remove that maui thing

#

Just Grid.Resources

honest pulsar
#

I also need to fix this

night peak
honest pulsar
#

the orange should be gone

#

and maybe a different colour on the rest as well

night peak
#

You need to override the accent colour just for the application

#

I think you can override SystemAccentColor under Application.Resources

honest pulsar
#

btw do numberboxes return integers?

night peak
honest pulsar
#

oh

night peak
#

But you can disable entering non-integers I think

honest pulsar
#

yea I saw something about it

#

gave me errors

#

lol

night peak
#

Maybe you need a 'formatter'

honest pulsar
#

tbf I think Ill just cast it to an integer

#

wait u can put letters in a numberbox wth

night peak
#

No?

honest pulsar
#

ooh it does remove the contents afterward

honest pulsar
#

figured Id do something like this to save data I receive

night peak
#

How is it letting you assign to a std::string directly

honest pulsar
#

oh no thats just temporary

night peak
honest pulsar
#

oh no not at all

#

I just took the screenshot before it made the red line below

night peak
# honest pulsar
std::ofstream fileOut{ "data.txt" };
fileOut << data;

You can shorten this to two lines

#

Unlike Java, C# or other languages you need not close the file manually thanks to RAII

honest pulsar
#

oh damn

honest pulsar
#

or can I just save it in a textfiile as a hstring?

night peak
#

winrt::to_string

honest pulsar
#

what would happen

night peak
#

UTF-8 is much more common for text files, even on Windows

honest pulsar
night peak
#

It's a free function

honest pulsar
#

ooh

night peak
#

Or well since you are already in the winrt namespace, can write just to_string

honest pulsar
#

btw do I have to premake the data.txt file

night peak
#

No?

honest pulsar
#

very nice

night peak
#

Wait though where do you want it to go?

honest pulsar
#

oh uh

#

whereever ig

#

can it be controlled easily?

night peak
# honest pulsar

This might put it in the app installation folder or maybe the folder it was launched from in the command line

night peak
#

That's a better option

honest pulsar
#

hm

#

that sounds a lot more difficult lol

night peak
#

/home/user/ is only on Linux

honest pulsar
#

oh ye this is just something I found on stack overflow

night peak
#

Not sure if this works, but could you try if it accepts %homepath% to refer to the current user's folder?

#

Otherwise you'd have to query for the current user's folder

honest pulsar
#

trying

honest pulsar
night peak
honest pulsar
honest pulsar
#

cant find a file

#

either it didnt work or idk where it went lol

#

doesnt send it to the desktop either

night peak
night peak
# honest pulsar that sounds a lot more difficult lol

This should work:

#include <shobjidl_core.h>
#include <Microsoft.UI.Xaml.Window.h>
#include <winrt/Windows.Storage.Pickers.h>

HWND windowHandle;
check_hresult(try_as<IWindowNative>()->get_WindowHandle(&windowHandle));

Windows::Storage::Pickers::FileSavePicker picker;
check_hresult(picker.as<IInitializeWithWindow>()->Initialize(windowHandle));
picker.SuggestedFileName("data.txt");
picker.FileTypeChoices().Insert(L"Plain text", single_threaded_vector<hstring>({ L".txt" }));
auto const file = co_await picker.PickSaveFileAsync();
// use file.Path()

It's a bit tedious due to their bad API.

honest pulsar
#

oh boy

#

howd u get all that from that link

#

👀

night peak
#

But IInitializeWithWindow isn't in the code which is necessary in a non-UWP app; there's only a mention at the top.

#

Their documentation isn't very well organised nowadays

#

But in my experience, Apple's is often even worse

honest pulsar
#

I could imagine

night peak
#

Oh you don't know it

honest pulsar
#

ive heard it before I just forgot cuz Ive never used it

night peak
#

p->x is the same as (*p).x

#

With references, however, you just use dot like regular objects

honest pulsar
#

so when I do something like:

#

StopbitPortBox().SelectedIndex()
this is a reference to the location of the selected index of the stopbitbox?

night peak
#

Yes

#

While SelectedItem gives you the item itself

honest pulsar
# night peak Yes

so then StopbitPortBox()->SelectedIndex() would output the location?

night peak
honest pulsar
#

what would happen if I did ->

night peak
#

It won't work

honest pulsar
#

in what cases does it work with ->?

night peak
#

When you have pointers

#

C++/WinRT mostly exposes references and values rather than pointers

night peak
#

It's hard to explain

#

But that's how it is

honest pulsar
#

damn

#

I always found pointers a bit confusing

#

but its mainly because I havent had to use them that often so its hard to get used to the concept

night peak
#

In C++ a pointer is just a nullable and reassignable reference

#

And references are aliases to existing objects

night peak
honest pulsar
#

thats fair

honest pulsar
night peak
night peak
honest pulsar
#

@night peak I just tested the serial monitor with an atmega

#

I cant receive data

#

with the UI

night peak
#

Maybe try putting a breakpoint where you read the data?

#

@honest pulsar

honest pulsar
#

wait I need to verify the base code works first one sec

#

it used to work in my separate program

#

ye it still works

night peak
honest pulsar
#

the base code

#

not the UI

night peak
#

Put breakpoints and see what values you get

honest pulsar
#

it doesnt seem to reach this breakpoint

night peak
honest pulsar
#

nothing happens

night peak
#

Is the function even called?

honest pulsar
#

doesnt seem like it

night peak
#

Ah there's a bug there

honest pulsar
#

it does reach into this point

night peak
#

You need ==, not just =

honest pulsar
#

so keeprunning should be called

night peak
#

keeprunningINIT == false

#

Or !keeprunningINIT

honest pulsar
#

oh crap

#

lol

night peak
#

= assigns false to the variable and then the if evaluates false which means nothing happens

honest pulsar
#

yeaa its just a typo

#

wops

#

uh oh

night peak
#

Maybe you got confused with bit

#

ReadFile takes size in bytes

honest pulsar
#

honestly I was kinda confused about the readfile altogether

#

in the reference they used an 8 byte buffer

#

and im pretty sure they read from the referenced dwbytesread

#

wait let me find it

night peak
honest pulsar
#

yea right??

#

I was talking with an irl about this

#

he said it gave the byte itself

#

like the data

#

this is what we read

night peak
honest pulsar
#

yea exactly lol

#

I showed him that and he still kept saying the other thing haha

#

oh shit it does something

little star
#

The problem is that there are more than 2 bytes, for example 4 bytes, available.
Now ReadFile will say 4 is less than the max of 8 bytes given to me, so I will write dataReadBuff[3] and dataReadBuff[3], and put 4 into dwBytesRead - which corrupts the stack as there are no dataReadBuff[3] and [4]

TL;DR, change the 8 to a 2, so you don't run into the issue of it corrupting the stack

night peak
night peak
# honest pulsar

In this you forgot to put a newline character when appending new output

honest pulsar
#

ok fixed it pog

#

it does output the correct initial value

#

but it doesnt seem to update

#

nvm it doe

#

does

night peak
honest pulsar
#

the textbox just doesnt follow the text

#

like it just disappears super far down

#

and u have to scroll

night peak
#

Because there's no space?

honest pulsar
#

isnt that correct?

honest pulsar
#

instantly

night peak
#

Because you have lots of data?

little star
honest pulsar
#

a lot

night peak
#

Hmm

honest pulsar
#

im running an atmega at 8 mhz

#

although an ADC which I think is 1 mhz iirc

#

I can show u my code for the atmega if u want

#

its just taking a potentiometer output voltage into an adc, converts it back to voltage and then into characters and sends them one by one with a terminator

honest pulsar
#

is there any way for the textbox to follow the bottom on its own?

night peak
#

Tho it's not in C++/WinRT so you'll have to port

honest pulsar
#

lemme look through it

honest pulsar
#

the serial monitor can also send data pog

#

it does crash though when I send b for begin

#

like if I send an e it does stop transmitting

#

but if I send a b to it it crashes

night peak
#

Hmm

honest pulsar
#

kinda odd

night peak
#

Why do you need an array of 2 chars when you are only going to send or receive one

honest pulsar
#

but does an array not always include the null character in the end?

honest pulsar
#

aah

honest pulsar
#

jaiganesh would u happen to know why get usernameA doesnt work in this project

#

but it does in another

#

nvm it works now

honest pulsar
#

it seems like theres problems regarding resetting the serial device handle

#

even if I just doublepress confirm settings so it should just replace the handle with an identical one it stops receiving data

night peak
# honest pulsar

You shouldn't CloseHandle there it will continue to be used by keepRunning until a line terminator is reached.

#

Instead, close it here:

if (serialDeviceTemp != serialDevicePass)
{
    CloseHandle(serialDeviceTemp);
    serialDeviceTemp = serialDevicePass;
}
night peak
honest pulsar
honest pulsar
night peak
#

No

honest pulsar
#

its complaining that its unidentified

prisma jasper
#

I think this is the most messages I've seen in a thread lol

honest pulsar
#

not sure if this what u wanted me to try jaiganesh

#

with the file pointer

night peak
honest pulsar
night peak
#

No not 1

#

You need to skip all the characters written

#

So hstr.size()

honest pulsar
#

alrightg

#

oh boy

#

sometimes it breaks at the scoped_lock

#

I saw it once break into readChar

#

the problem might be that it gets stuck trying to read while no data is transmitted

#

it is afterall always when theres no data transmitted from the atmega and I try to send something it crashes

#

the old program had the same problem I just checked

#

and that program only ran on 1 thread

#

I also got 1 bug where it started reading but all empty stuff so it only kept the '\r' newline and just spammed nothingness

#

but I cant recreate that one

#

but yea it seems like it gets stuck on reading nothing and then cant write at the same time

night peak
#

I imagine ReadFile waits for something to be sent from the other end

honest pulsar
#

yea it really looks like that

#

problem is how to make it not read while nothing is being sent lol

#

because I kinda have to check with read to know if anythings been sent..

#

u reckon this could help

night peak
#

Maybe

#

You could call this from where you are writing

honest pulsar
#

what do I type as the handle thread?

#

its the background thread id want to close

#

or cancel

night peak
#

Note that it may change after every resume_background

honest pulsar
#

what is the type of a thread?

night peak
honest pulsar
night peak
#

Global or class member

honest pulsar
#

yep

night peak
#

Or well it might be better to create a dedicated thread than using the pool since you continously use it

#

But shouldn't be a big issue

honest pulsar
#

instead of resume background?

night peak
#

Yes

#

Tho resume_background is cleaner

honest pulsar
#

if it works lol

#

nah still crashes

#

wait

night peak
#

Hit a breakpoint to where CancelSynchronousIo is called

night peak
honest pulsar
#

before the llock tho

#

1 sec

night peak
#

Cancel it before the loop

#

Well maybe before the loop, not so sure

honest pulsar
#

it still dies

night peak
#

You'd also have to modify the code in Keeprunning

honest pulsar
#

it still breaks at the lock

night peak
#

You've cancelled the thing but the lock still isn't unlocked

honest pulsar
#

oh I thought itd just go through readChar and through the lock

night peak
honest pulsar
#

I put one here and it isnt hit

#

so the cancel io thing doesnt seem to do its job

night peak
#

Otherwise it wouldn't reach here

#

Wait one thing, can you enclose ReadFile inside winrt::check_bool

#

That will throw the value of GetLastError as an exception

#

Or at least check the bool return value of ReadFile

#

Is it false when cancelled? I'm not sure

honest pulsar
night peak
honest pulsar
#

like usually it looks like this when it breaks at my breakpoints

night peak
#

Because they are thread-pool threads, which can change

#

Otherwise create a regular thread with std::thread or Win32 CreateThread

honest pulsar
night peak
#

You might also want the backgroundThread variable to be atomic

honest pulsar
#

ok yea it definitely gets stuck at readFile

#

I just used the step thing from while(true) down to readChar

#

and into readChar

#

when it hits readFile it just dies

night peak
#

I'm not sure if ReadFile gives a GetLastError error

#

Or maybe CancelSynchronousIo does

honest pulsar
#

like that?

night peak
#

The docs page doesn't clearly say where these flags are sent from

night peak
honest pulsar
#

what does check bool do

#

checks if its true?

night peak
#

check_bool is an helper function in C++/WinRT that throws it as an exception

honest pulsar
#

should I output it somewhere?

night peak
honest pulsar
#

I dont think it did anything

night peak
#

Or well then print out what ReadFile returns?

#

The bool

honest pulsar
#

damn I tried this and it also didnt work

night peak
#

Wait perhaps dwBytesRead is 0 when cancelled

#

You could use that to handle the failure case

honest pulsar
#

still breaks

night peak
#

You always to need to return something

honest pulsar
#

yea I mean it just doesnt move out of readFile

night peak
honest pulsar
#

doesnt seem like it

night peak
honest pulsar
#

I also set the read timeouts down to 1

#

also didnt help

#

there is this

#

ReadFileEx

#

and cancello

#

?

#

cancelloEx

night peak
#

Yes but more complex

honest pulsar
#

how complex is it?

night peak
#

Little

honest pulsar
#

I have to make a completion routine function

#

F

ancient berryBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.

honest pulsar
#

I was gone a bit had to focus on some other work but

#

Im genuinely not sure whether or not its necessary to add anything to my completion routine

#

it seems as though the completion routine is mainly for releasing memory by closing handles and/or processing the data

#

but that is all done outside of my read function