more G-Labs products

Author Topic: How to package a MIG module  (Read 1072 times)

September 18, 2016, 04:06:48 AM
Read 1072 times

sambuddy200471

  • *
  • Information
  • Newbie
  • Posts: 1
Hello All,
I have a relay module that has 8 relays and i can talk to it using http through either curl or C#.
From reading, it seems that the most appropriate way to integrate it into HG is to write a MIG module
I have downloaded and built the skeleton code for a mig module and it produces a DLL but from what i can gather, to install a mig module, it needs to be in a zip file with some other files.
Can anyone tell me what i need to include in the zip file for the mig module to install correctly?
If I install the MIG module, how do i handle having several of these modules? Do i install the mig module several times or is it something i need to handle in my mig module code?
Thanks for your help
Regards
Stuart

September 19, 2016, 02:00:09 AM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Since you can control your device by using HTTP API (curl), there's no reason for implementing a MIG interface.
A MIG interface is mostly required when you need to access device specific libraries directly.
So I would suggest writing a simple HomeGenie program (Javascript or C#) by using the Net helper class to call your device HTTP API.
There's already a bunch of example in this forum. Also for your original question there's already a thread I think.


October 22, 2016, 07:46:30 PM
Reply #2

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
for packaging modules I wrote this powershell script for use on windows as a post build activity in visual studio:

oh and you need to edit the files in the solution to contain !Release Date! and !Version!

Code: [Select]
[CmdLetBinding()]
param
(   
[Parameter(Mandatory = $true, Position = 0)]
[string]$TargetDir,

[Parameter(Mandatory = $true, Position = 1)]
[string]$ProjectName,

    [Parameter(Mandatory = $true, Position = 2)]
[string]$TargetFileName,

    [Parameter(Mandatory = $true, Position = 3)]
[string]$ProjectDir

)

$TargetDir = $TargetDir.Replace('"',"")
$ProjectDir = $ProjectDir.Trim()

function Test-Net45 {
    if (Test-Path ‘HKLM:SOFTWAREMicrosoftNET Framework SetupNDPv4Full’) {
        if (Get-ItemProperty ‘HKLM:SOFTWAREMicrosoftNET Framework SetupNDPv4Full’ -Name Release -ErrorAction SilentlyContinue) {
            return $True
        }
        return $False
    }
}

Write-Host "Target Dir: $($TargetDir)"
Write-Host "Project Name: $($ProjectName)"
Write-Host "Project Dir: $($ProjectDir)"
Write-Host "Target File Name: $($TargetFileName)"

if (Test-Net45 -eq $false) {Write-Error ".Net 4.5 is required to create the archive." -ErrorAction stop}
Add-Type -assembly "system.io.compression.filesystem" -ErrorAction stop

$destination = "$($ProjectDir)Output\$($ProjectName).zip"

# Determine Assembly version to version the interface
$file = "$($TargetDir)\$($TargetFileName)"

$ass = [System.Reflection.Assembly]::LoadFile($file)
$v = $ass.GetName().Version;
$version = [string]::Format("{0}.{1:00}.{2:00}.{3}",$v.Major, $v.Minor, $v.Build, $v.Revision)
write-host "DLL $file Version is: $version"


# Replace Date and Version in Package.json
(Get-Content "$TargetDir\Package.json").replace('!RELEASE DATE!', (Get-Date)) | Set-Content "$TargetDir\Package.json"
(Get-Content "$TargetDir\Package.json").replace('!VERSION!', $version) | Set-Content "$TargetDir\Package.json"


# Replace Date and Version in Readme.TXT
(Get-Content "$TargetDir\Readme.TXT").replace('!RELEASE DATE!', (Get-Date)) | Set-Content "$TargetDir\Readme.TXT"
(Get-Content "$TargetDir\Readme.TXT").replace('!VERSION!', $version) | Set-Content "$TargetDir\Readme.TXT"

If(Test-path $destination) {
Write-Host "Removing existing interface archive"
Remove-item $destination -Verbose -Force
}


# Create interface archive
[io.compression.zipfile]::CreateFromDirectory($TargetDir, $destination)

Write-Host "`nInterface zip created at: $($destination)`n"

#If(Test-path "$($ProjectDir)\Output\TexecomWidget.zip") {
# Write-Host "Removing existing widget archive"
# Remove-item "$($ProjectDir)\Output\TexecomWidget.zip"
#}

# Create widget archive
#[io.compression.zipfile]::CreateFromDirectory("$($ProjectDir)TexecomWidget", "$($ProjectDir)Output\TexecomWidget.zip")

#Write-Host "`n Widget zip created at: $($ProjectDir)Output\TexecomWidget.zip`n"

#if $(ConfigurationName) == Release (
#    Rem TODO: Push Release to public repository
#)

# Inteface.Import

Then in post build activities (properties on interface project, then Build Events, and in Post-build event command line add:

Code: [Select]
powershell.exe -executionPolicy Bypass -file "$(SolutionDir)package.ps1" -ProjectDir "$(ProjectDir) " -ProjectName "$(ProjectName)" -TargetFileName "$(TargetFileName)" -TargetDir "$(TargetDir)"

Next step is to suss the interface api commands to disable existing interface, import this one  and enable..

David
« Last Edit: October 22, 2016, 07:49:09 PM by [email protected] »