i have a vb.net app that plays converted midi files and sends the data to a k8055 to trigger relays. i want to make the system all in one so i dont need a pc to control it so i will need to be able to play them from a sd card. Heres the vb.net source
Public Class Form1 Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer Private Declare Sub CloseDevice Lib "k8055d.dll" () Private Declare Sub Version Lib "k8055d.dll" () Private Declare Function SearchDevices Lib "k8055d.dll" () As Integer Private Declare Function SetCurrentDevice Lib "k8055d.dll" (ByVal CardAddress As Integer) As Integer Private Declare Function ReadAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Integer Private Declare Sub ReadAllAnalog Lib "k8055d.dll" (ByRef Data1 As Integer, ByRef Data2 As Integer) Private Declare Sub OutputAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer, ByVal Data As Integer) Private Declare Sub OutputAllAnalog Lib "k8055d.dll" (ByVal Data1 As Integer, ByVal Data2 As Integer) Private Declare Sub ClearAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) Private Declare Sub SetAllAnalog Lib "k8055d.dll" () Private Declare Sub ClearAllAnalog Lib "k8055d.dll" () Private Declare Sub SetAnalogChannel Lib "k8055d.dll" (ByVal Channel As Integer) Private Declare Sub WriteAllDigital Lib "k8055d.dll" (ByVal Data As Integer) Private Declare Sub ClearDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) Private Declare Sub ClearAllDigital Lib "k8055d.dll" () Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) Private Declare Sub SetAllDigital Lib "k8055d.dll" () Private Declare Function ReadDigitalChannel Lib "k8055d.dll" (ByVal Channel As Integer) As Boolean Private Declare Function ReadAllDigital Lib "k8055d.dll" () As Integer Private Declare Function ReadCounter Lib "k8055d.dll" (ByVal CounterNr As Integer) As Integer Private Declare Sub ResetCounter Lib "k8055d.dll" (ByVal CounterNr As Integer) Private Declare Sub SetCounterDebounceTime Lib "k8055d.dll" (ByVal CounterNr As Integer, ByVal DebounceTime As Integer) Const gGreen As Integer = 1 Const gRed As Integer = 2 Const gYellow As Integer = 4 Const gBlue As Integer = 8 Const gOrange As Integer = 16 Const gStar As Integer = 32 Const gStrum As Integer = 64 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click Dim CardAddress As Integer Dim h As Integer Console.Write("Connecting to card 0...") CardAddress = 0 h = OpenDevice(CardAddress) Select Case h Case 0, 1, 2, 3 ListBox1.Items.Add("Connected") Case -1 ListBox1.Items.Add("Card not found!") GoTo nd Case -2 ListBox1.Items.Add("EXE NOT FOUND?!") GoTo nd End Select WriteAllDigital(0) Dim cs As String = (OpenFileDialog1.FileName) ListBox1.Items.Add("Loading File..." & cs) FileOpen(1, cs, OpenMode.Input) Dim Data(10000, 3) As Double Dim n As Integer = 0 Dim s As Double = -1 Do Until EOF(1) Dim d As String = "" Input(1, d) If d <> "" And Microsoft.VisualBasic.Left(d, 1) <> "#" Then n += 1 Dim ds() As String = Split(d, "|") Data(n, 0) = ds(0) If s = -1 Then s = ds(0) Data(n, 1) = Play(Mid(ds(1), 1, 1), Mid(ds(1), 2, 1), Mid(ds(1), 3, 1), Mid(ds(1), 4, 1), Mid(ds(1), 5, 1), Mid(ds(1), 6, 1)) Data(n, 3) = Play(Mid(ds(1), 1, 1), Mid(ds(1), 2, 1), Mid(ds(1), 3, 1), Mid(ds(1), 4, 1), Mid(ds(1), 5, 1), 0) Data(n, 2) = Mid(ds(1), 6, 1) End If Loop FileClose(1) ListBox1.Items.Add(n & " lines of data read.") Dim b As Double Dim c As Integer = 1 ListBox1.Items.Add("Press enter to start") Console.ReadLine() Dim OldTicks As Long = Now.Ticks - 100000 Do Until c > n b = Now.Ticks - OldTicks If b >= Data(c, 0) - s Then ListBox1.Items.Add("Beat (ticks): " & b & ", Data: " & Data(c, 1)) WriteAllDigital(Data(c, 1)) c += 1 End If If Data(c, 2) = 1 And Data(c - 1, 2) = 1 And b >= Data(c - 1, 0) + ((Data(c, 0) - Data(c - 1, 0)) / 2) - s Then WriteAllDigital(Data(c - 1, 3)) Loop Threading.Thread.Sleep(1000) WriteAllDigital(Data(c - 1, 3)) nd: ListBox1.Items.Add("Done, press enter to exit") WriteAllDigital(0) CloseDevice() End Sub Function Play(ByVal Green As Boolean, ByVal Red As Boolean, ByVal Yellow As Boolean, ByVal Blue As Boolean, ByVal Orange As Boolean, ByVal Strum As Boolean) As Integer Dim d As Integer = 0 If Green Then d = d + gGreen If Red Then d = d + gRed If Yellow Then d = d + gYellow If Blue Then d = d + gBlue If Orange Then d = d + gOrange If Strum Then d = d + gStrum + gStar Play = d End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click OpenFileDialog1.ShowDialog() End Sub End Class
and this is the files it reads then sends to the k8055
5012750|000011 5531310|000101 6049871|001001 6568431|010001 7086991|100001 7605552|010001 8124112|001001 8642672|000101 9161233|000011 9679793|000101 10198353|001001 10716914|010001 11235474|100001 11754034|000101 12272595|000011 12791155|000101 13309716|001001 13828276|010001 14346836|100001 14865397|000101 15383957|000011 15902517|000101 16421078|001001 16939638|010001 17458198|100001 17976759|000101 18495319|000011 19013879|000101 19532440|001001 20051000|010001 20569560|100001 21088121|000101 21606681|000011 22125241|000101 22643802|001001 23162362|010001 23680922|100001 24199483|000101 24718043|000011 25236603|000101 25755164|001001 26273724|010001 26792284|100001
and so on, the numbers before the "|" are the ticks for when to trigger the relay. the numbers after the "|" are what relay to trigger so "100001" would be 1 and 6 on and 2, 3, 4 and 5 off. ive never coded in C sharp and i dont know what to do