Public RT As Object 'Realterm object is in workbook so it can be accessed from all sheets
Private Sub Workbook_BeforeClose(Cancel As Boolean) Realterm_Close End Sub
Public Sub Realterm_Close() If Not RT Is Nothing Then RT.Close Set RT = Nothing End Sub
Public Sub Realterm_Open() Set RT = CreateObject("Realterm.RealtermIntf") RT.HalfDuplex = True RT.Caption = "Realterm Controlled from Excel" RT.portopen = True RT.SelectTabSheet ("I2C") End Sub
Private Sub Workbook_Open() ' Could start Realterm here! Realterm_Open End Sub
Public Sub SendStringToLED(S As String) 'You need the I2CHelper DLL, and to register it for this to work 'http://www.i2cchip.com/digital_display_module.html#I2CHelper DLL Dim IH As Object Set IH = CreateObject("I2CHelper.M5451") RT.PutString ("YW0000000000") 'this always resets the display LED_Data = "Y101" + IH.Str2M5451D4(S) RT.PutString (LED_Data) End Sub
'-------------- Worksheet Code ---------------
Private Sub CommandButtonSendA1_Click() ThisWorkbook.RT.PutString (Cells(1, 1)) End Sub
Private Sub CommandButtonSendA2ToLED1_Click() ThisWorkbook.SendStringToLED (Cells(2, 1)) End Sub
Private Sub Worksheet_Change(ByVal Target As Excel.Range) ' This seems to be an unreliable excel event. Depending on your version ' of excel, it may not fire when you would expect it to! Dim VRange As Range Set VRange = Range("A2", "A2") If Not Intersect(Target, VRange) Is Nothing Then _ ThisWorkbook.SendStringToLED (Cells(2, 1)) End Sub
Private Sub CommandButtonHideRealterm_Click() ThisWorkbook.RT.Visible = Not ThisWorkbook.RT.Visible End Sub
|