shawty / sn76489arduino

Project and Supporting files to turn an arduino into a BBC Micro music player.
MIT License
23 stars 3 forks source link

dotnetcore 2 is EOL, how can we upgrade to 7? #2

Closed ReinouddeLange closed 1 year ago

ReinouddeLange commented 1 year ago

As discussed using twitter; your project uses dotnetcore 2 and that is eol. I installed dotnetcore 7 but that seems to be incompatible. I tried to use the upgrade assistant but it is not supported on macOS. How can I proceed? Can you upgrade your program to dotnetcore 7?

shawty commented 1 year ago

Let me have a look at the code over the weekend and see if I can determine the parts that are not compatible, see what I can do.

In the meantime, if you can plug the details of what the upgrade wizard into a note on here, or any error messages you got trying to run the code, that will at least give me a place to start looking.

ReinouddeLange commented 1 year ago

Peter,

The UA doesn't run at all on a mac, it is not supported.

When I try to start your program I get these errors:

Reinoud@MBP-van-Reinoud ~/D/s/VGMPlayer> dotnet run /usr/local/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/Reinoud/Desktop/sn76489arduino-master/VGMPlayer/VGMPlayer.csproj] /usr/local/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/Reinoud/Desktop/sn76489arduino-master/VGMPlayer/VGMPlayer.csproj] /usr/local/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/Users/Reinoud/Desktop/sn76489arduino-master/VGMPlayer/VGMPlayer.csproj] You must install or update .NET to run this application.

App: /Users/Reinoud/Desktop/sn76489arduino-master/VGMPlayer/bin/Debug/netcoreapp2.0/VGMPlayer.dll Architecture: x64 Framework: 'Microsoft.NETCore.App', version '2.0.0' (x64) .NET location: /usr/local/share/dotnet/

The following frameworks were found: 7.0.0 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Learn about framework resolution: https://aka.ms/dotnet/app-launch-failed

To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=osx.11.0-x64 Reinoud@MBP-van-Reinoud ~/D/s/VGMPlayer [SIGTTOU]>

shawty commented 1 year ago

@ReinouddeLange I've updated the project sources to compile & build under .NET Core 3.1, which is still supported (Only just mind) but it is compliable.

I've not gone any higher just yet however, as to do so means rewriting a crucial part of the player loop.

From .NET 5 onwards, Thread.Abort has been deprecated and removed from the BCL.

The play routine uses a class called "HighResTimer" which I downloaded from here : https://www.codeproject.com/Articles/98346/Microsecond-and-Millisecond-NET-Timer a good few years ago.

The web page has a good explanation of what the class is, but the upshot in my case is that the project board that had the sn76489 PSG on it, was running off of a 4Mhz crystal oscillator, and the regular .NET timer classes were just too slow for me to push the data out of the serial port fast-enough to get real-time playback.

So, I employed the high-res timer code, to get microsecond accuracy, and never really thought too much about how it all worked :-)

Bottom line is, the high-res timer code uses Thread.Abort, and while I don't recall using it anywhere in my code, to go higher than 3.1 right now, without figuring out what needs re-writing and how, is going to break the code.

And don't have time right now, to do a re-write on the loop, or figure out a good async way of re-writing the high-res loop used.

One possibility, might not even be to re-write the .NET code, it might be more performant to re-write the code at the Arduino end, and do some buffering on the Atmel (The mega which is what I used originally has something like 256k of sram), that would allow the .NET code to send slower, and thus re-write the play loop using the slower system.timer, timers.

I could also just spin the loop as fast as possible and push it out to a thread pool with a cancelation token.

Few ideas here: https://stackoverflow.com/questions/53465551/net-core-equivalent-to-thread-abort

Might be a month or more before I can sit down and look at it in depth (I have a hectic workload between now and Dec 20th)

For now, at least however, you should be able to build and run it on a supported platform, I don't use a mac so I can't test it I'm afraid, I have only Windows and Linux based PC's available.

Shawty

ReinouddeLange commented 1 year ago

Hi Shawty,

I tried to use .Net framework 3.1.0, and it runs but unfortunately it doesn't work yet. I get the following exception:

Reinoud@MBP-van-Reinoud ~/D/s/VGMPlayer> dotnet run Unhandled exception. System.TypeInitializationException: The type initializer for 'VGMPlayer.Program' threw an exception. ---> System.PlatformNotSupportedException: System.IO.Ports is currently only supported on Windows. at System.IO.Ports.SerialPort..ctor() at VGMPlayer.SerialSender..ctor() in /Users/Reinoud/Desktop/sn76489arduino-master 2/VGMPlayer/SerialSender.cs:line 8 at VGMPlayer.VgmFile..ctor() in /Users/Reinoud/Desktop/sn76489arduino-master 2/VGMPlayer/VgmFile.cs:line 16 at VGMPlayer.Program..cctor() in /Users/Reinoud/Desktop/sn76489arduino-master 2/VGMPlayer/Program.cs:line 12 --- End of inner exception stack trace --- at VGMPlayer.Program.Main(String[] args) in /Users/Reinoud/Desktop/sn76489arduino-master 2/VGMPlayer/Program.cs:line 69 Reinoud@MBP-van-Reinoud ~/D/s/VGMPlayer [SIGABRT]>

I guess this will require much more effort on you side, so I will try to find other ways or wait until you had time to modify it again.

Thanks for the help so far!

Kind regards,

Reinoud

shawty commented 1 year ago

Actually no, that's a .NET support error, which is strange because .NET serial support in core does in fact actually work on Linux as well as windows, so that one is a bit of a mystery to me.

There was a time when System.IO.Ports.SerialPort only worked on windows but that hasn't been the case for a very long time, and it's certainly not the case for .NET core 3.1 because I have many other bits and pieces that use the same runtime libs and run perfectly well on Windows and on Linux with the only change needed being to the com port name.

So to be fair, that one is a definately a mystery to me, as it should indeed not be the case.

I even have a Q&A answer on stack overflow somewhere that I wrote ages ago, that explains it all.

shawty commented 1 year ago

Ahhhhhh ..... That'll be the problem then :-)

image

Current version of the Serial ports assembly for .NET is 7.0.0, my app is using 4.4.0

shawty commented 1 year ago

Ok, give that a try.

I upgraded to V7, but got a build error saying V7 is not supported under core 3.1, so I dropped it back to V6.0.0 which is as high as I can go under .NET Core 3.1.

I know from other apps I've written that Core 3.1 does support serial use across Windows and Linux just couldn't tell you what version it was I've used :-)

ReinouddeLange commented 1 year ago

Ok, So I try V6 too?

shawty commented 1 year ago

Nope, I've upgraded the NuGet package in the project to V6, just pull it then let things update in VS or which ever IDE you use.

If command line, you may have to do "dotnet restore"

ReinouddeLange commented 1 year ago

oh, ok... I installed v6 already and it works! :-)

Thanks a lot!

shawty commented 1 year ago

No worries, feel free to close this if you want to, if I get time over the Christmas break, I'll look to see if I can improve the player loop to get rid of the Thread Abort call.