Read from Serial port to Excel

前端 未结 1 1587
迷失自我
迷失自我 2021-01-23 08:30

I need to create a button in Excel to read data in from serial port. I can\'t have any extra files attached to the excel sheet. I need to transfer this excel file to another com

1条回答
  •  梦毁少年i
    2021-01-23 08:51

    I found a discussion on exactly this topic in the german microcontroler.net forum here:

    http://www.mikrocontroller.net/topic/64788

    Since I am running on Linux I can not verify if the code is correct. Anyway, here is a copy of it:

    Sub Send_and_Read()
      '--------------------------------------------------------
      cmnd$ = "Hello World"        'A string to send
      '--------------------------------------------------------
      Open "COM1" For Binary Access Read Write As #1
      cmnd$ = cmnd$ + Chr(13)      'add [CR] to command string
      Put #1, , cmnd$              'write string to interface
      '--------------------------------------------------------
      answer = ""                  'clear response string
      char = Input(1, #1)          'get first character
      While (char <> Chr(13))      'loop until [CR]
        If (char > Chr(31)) Then
          answer = answer + char   'add, if printable char
        Else
          ' Do what ever you like
        End If
        char = Input(1, #1)        'get the next character
      Wend
      Close #1
      '--------------------------------------------------------
      Cells(1, 1) = answer         'put response in cell("A1")
    End Sub
    

    0 讨论(0)
提交回复
热议问题