从串口读取Excel [英] Read from Serial port to Excel
问题描述
我需要在Excel中创建一个按钮,从串口读取数据。我不能连接到Excel工作表中的任何其他文件。我需要传递这个excel文件到另一台计算机上读取该数据。
下面是该文件是怎么想的功能:preSS按钮,选择串口。然后,preSS另一个按钮,读取串口数据到Excel单元格中。
可能有人请告诉我如何做到这一点?使用VB宏或ActiveX宏?对不起,这是我第一次使用Excel这一点。请帮助。同样,我不能连接到Excel工作表中的另一个文件。谢谢!
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 computer to read this data. Here is how the file is suppose to function: Press button to select the serial port. Then, press another button to read data from serial port into the excel cell. Could someone please tell me how to do this? Use VB macro or ActiveX macro? Sorry, this is the first time i'm using excel for this. Help please. Again, I can't have another file attached to the excel sheet. Thank you!
推荐答案
我发现在德国microcontroler.net论坛这里正是这个话题的讨论:
I found a discussion on exactly this topic in the german microcontroler.net forum here:
http://www.mikrocontroller.net/topic/64788
由于我在Linux上运行,我不能,如果code是正确的验证。总之,这里是它的一个副本:
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
这篇关于从串口读取Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!