Menu

GCBasic USB driver installer for x64 and x86, windows 7 to 11, circumvents non signed problem

Angel Mier
2021-09-18
2021-09-28
  • Angel Mier

    Angel Mier - 2021-09-18

    So first of all, an apology in advance, English is not my main language.

    I was testing the USB demos and I realized that for someone who is starting it would be a bit difficult and frustrating the part of installing the drivers, due to the fact that these drivers are not signed; for people who are more seasoned there will be no problem when testing them, but even for any useful project, a more viable solution will be required.

    So, I took the task of creating an installer that would take care of circumventing these problems, the installer unzips the files in C:\drivers\, puts the operating system in disable driver signature enforcement mode, installs the drivers, reverts to normal mode and delete the contents of C:\drivers.

    The two main disadvantages are the following: requires (automatically) restart the computer 2 times to change modes. And also requires that the computer does not have secure boot enabled to be fully autonomous. In case secure boot is enabled, the installer automatically detects it, and will restart the computer in boot selection mode to choose the driver signature enforcement mode manually and continue with the driver installation (I know that this way is convoluted but I have not found another way in case of having secure boot enabled and not having drivers signed by Microsoft).

    In the zip file I add the compiled exe and all the source code to build it. the main installer (which only takes care of unzipping the files and adding a key to the windows registry) is done in Install Creator Pro 2, It is a freeware available here https://www.clickteam.com/download-centre/install-creator-pro-2

    the other two applications inside (one is responsible for detecting if the secure boot is present on the computer and determining the best way to change mode and restart the computer, and the other is responsible for installing the driver, reverting the mode and deleting the content from the folder) both are console applications written in C#. uses .Net Framework 3.0 (I purposely chose it to run easily on legacy OS) If you are going to play with those assemblies remember that they are programmed to restart the computer without asking, so be careful.

    the drivers as they were in the demo does not work for windows 11, so I made they work now.

    I personally tried that it worked (both installer and drivers) in:

    Windows 11 pro x64 secureboot disabled, os build Dev 21H2 22000.194
    Windows 11 pro x64 secureboot enabled, os build Dev rs_prerelease 22458.1000
    Windows 10 pro x64 secureboot disabled, os build stable 20H2 19042.867
    Windows 7 pro x86 secureboot disabled, os service pack 1 build 6.1.7601

    in those environments runs perfect.

    I am aware that the code can be improved (my goal was to make it work) I hope I do not receive too much heat :) think that it was only a day's work; feel free to modify it, use it, or add it to the demos or whatever you want. I hope that it would be useful to someone.

    So it was a long day. greetings to all.

    Angel.

     
  • Angel Mier

    Angel Mier - 2021-09-19

    Hi, I can’t open the OneDrive link, it says that it doesn’t exist, it expired or I don’t have permissions to access it.
    In regards of the help page; did you mean the steeps to how to install it?
    I’m glad to do it.
    I know that it will be a good idea to add images of what to select when windows restart in WinRE (windows recovery environment), I think it will be the most awkward for the ones that have secure boot enabled.
    I suppose that you will need it in the “Great-Cow-BASIC-Help/source/” repo in .adoc format, that’s right?
    What file name you need for it?
    Best regards.
    Angel

     
  • Anobium

    Anobium - 2021-09-19

    Any ASCII file will do. To convert to ADOC will take a few seconds. So, if you write, I can change to ADOC.

     
  • Angel Mier

    Angel Mier - 2021-09-25

    Hi Evan, I already do another little project for the USB part that I think it will be of interest for your project. I see that the pic programming is very easy thanks to the USB.h library. But the vb.net part may be a little confusing to someone’s because one needs to understand all the code in the example and needs something like 500 lines of code for a just simple program.
    I have the idea to make one library for vb.net and C# of the GCB USB functions, but I want only one DLL, I don’t want to import LibUsbDotNet.dll + Another.dll and make a mess.

    I looked for the git repo of the LibUsbDotNet project, cloned it and revert it to version 2.2.9.110, a little bit a head of the old release (actual work in the repo is mainly trying to convert it to .Net Core and still doesn’t work) that release solved some minor bugs and its fully functional.

    After that I started cleaning up the project to get rid of all the unneeded code and parts for an easy future mod. Then I make another name space inside the dll called GCBlib and started to translate your demo code to C# (because LibUsbDotNet is written in C# and I only want one dll) I just do some little code optimization of your actual code, added overloads to the functions for easy use, added a function to send and array to the PIC, etc.
    At the end I have a little dll called GCBlib.dll of only 146kb whit a class named USBlib that facilitates programming of the usb part.

    Whit this a simple hello world program can be like this:

    Imports GCBlib
    Public Class Form1
    
        Dim USB As New USBlib
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Initialize USB daemon from start
            USB.InitializeUSB()
        End Sub
        Private Sub TimerDeviceConnection_Tick(sender As Object, e As EventArgs) Handles TimerDeviceConnection.Tick
            'Get the device connection status
            If USB.GetConnectedStatus = True Then
                Label1.Text = "Device Connected"
            Else
                Label1.Text = "Device not Connected"
            End If
        End Sub
        Private Sub HelloButton_Click(sender As Object, e As EventArgs) Handles HelloButton.Click
            'Send a simple command whitouth data
            USB.SendData(100)
        End Sub
    End Class
    

    The timer of your code is embedded on the class and runs internally, the final programmer doesn’t need to interact whit that, in the zip file I uploaded here, I added a full demo whit every one of the functions of the USBlib class, even whit this dll if you are an advanced programmer you can access the LibUsbDotNet name space and classes.
    Whit this project in the future will be easier to add new functionality to the USB part, I would like to se if there is a chance to send a command from the PIC to the PC and catch it in an event handler on the dll, I think it will be useful.

    In the ZIP:
    “USB Test” folder is the demo project whit all functions covered (User Solution)
    “GCBlib” folder is the full library project (GCBlib and LibUsbDotNet) when you open the project, look for the USBlib.cs object inside of the GCBlib directory.
    USB demo 45k50.gcb is the test program used whit “USB Test”
    If you are interested, just tell me to add it to a repo and start making the help page for it.

    Greetings
    Angel

     
  • Angel Mier

    Angel Mier - 2021-09-25

    I forget to mention that:

    • You can send simple commands (without data)
    • Send command whit bit data
    • Send command whit byte data
    • Send command whit byte array data
    • Receive bit data
    • Receive byte data
    • Receive array data
    • Access device object
    • Access devicenotifier object
    • Change PID REV and VID

    Code for all examples of the class:

    'USB Demo for the GCBlib USB Library
    Imports GCBlib
    Public Class Form1
        Dim USB As New USBlib
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'Initialize USB daemon from start
            USB.InitializeUSB()
        End Sub
        Private Sub TimerDeviceConnection_Tick(sender As Object, e As EventArgs) Handles TimerDeviceConnection.Tick
            'Get the device connection status
            If USB.GetConnectedStatus = True Then
                Label1.Text = "Device Connected"
            Else
                Label1.Text = "Device not Connected"
            End If
            'Show if the USB daemon is running
            DaemonStatusRadioButton.Checked = USB.Initialized
        End Sub
        Private Sub HelloButton_Click(sender As Object, e As EventArgs) Handles HelloButton.Click
            'Send a simple command whitouth data
            USB.SendData(100)
        End Sub
        Private Sub LCDlightCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles LCDlightCheckBox.CheckedChanged
            'Send a command and data as Bit
            USB.SendData(102, LCDlightCheckBox.Checked)
        End Sub
        Private Sub ByteTrackBar_Scroll(sender As Object, e As EventArgs) Handles ByteTrackBar.Scroll
            'Send a command and data as Byte
            ByteLabel.Text = ByteTrackBar.Value
            USB.SendData(103, ByteTrackBar.Value)
        End Sub
        Private Sub SendArrayButton_Click(sender As Object, e As EventArgs) Handles SendArrayButton.Click
            'Send a command and a data array
            Dim data(2) As Byte
            data(0) = 100
            data(1) = 255
            data(2) = 22
            USB.SendData(104, data)
        End Sub
        Private Sub GetStatusButton_Click(sender As Object, e As EventArgs) Handles GetStatusButton.Click
            'Poll and read 1 Byte from the device
            PORTaLabel.Text = USB.ReadData(101)
        End Sub
        Private Sub GetArrayButton_Click(sender As Object, e As EventArgs) Handles GetArrayButton.Click
            'Poll and read a data array
            Dim data() As Byte
            data = USB.ReadData(105, 3)
            If data Is Nothing Then
                MsgBox("No data received...")
            Else
                MsgBox("Data Received: " & data(0) & "," & data(1) & "," & data(2))
            End If
        End Sub
        Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
            'Initialize USB daemon
            USB.InitializeUSB()
        End Sub
        Private Sub TerminateUSBButton_Click(sender As Object, e As EventArgs) Handles TerminateUSBButton.Click
            'Terminate USB daemon
            USB.TerminateUSB()
        End Sub
    End Class
    
     
  • Anobium

    Anobium - 2021-09-28

    Got some screen shots? :-) Very good to see the USB in use.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.