简体   繁体   English

区分大小写的MSComm字符串

[英]Case Sensitive MSComm String

I some experience coding, but none with VBA (Excel 2013). 我有些编码经验,但没有使用VBA的经验(Excel 2013)。 I am attempting to write an extremely simple program which, through the serial port, 1.) Tells a remote device to accept external commands ("PHOTO"), 2.) Sends an external command ("M5" & Chr$(13)), and 3.) Tells the device to no longer accept external commands ("q"). 我正在尝试编写一个非常简单的程序,该程序通过串行端口1.)告诉远程设备接受外部命令(“ PHOTO”),2.)发送外部命令(“ M5”&Chr $(13) )和3.)告诉设备不再接受外部命令(“ q”)。

Private Sub CommandButton1_Click()

    ' Use COM2
    MSComm21.CommPort = 2

    ' 9600 baud, no parity, 8 data, and 1 stop bit.
    MSComm21.Settings = "9600,N,8,1"

    ' Open the port.
    MSComm21.PortOpen = True

    MSComm21.Output = "PHOTO" ' Step 1
    MSComm21.Output = "M5" & Chr$(13) ' Step 2

    ' Do some stuff


    MSComm21.Output = "Q" ' Step 3

    ' Close the port
    MSComm21.PortOpen = False

 End Sub

My problem is that, while I can confirm that steps #2 and #3 work, step #1 does not. 我的问题是,虽然我可以确认步骤2和步骤3可以正常工作,但步骤1却不能。 When talking to the device in Tera Term, the "PHOTO" command must be sent in all caps, while the "M5" and "q" commands are not case sensitive. 在Tera Term中与设备通话时,必须全部大写发送“ PHOTO”命令,而“ M5”和“ q”命令不区分大小写。 I'm wondering if the MSComm21.Output command disregards case? 我想知道MSComm21.Output命令是否忽略大小写吗? I haven't been able to find anything specifically talking about this. 我还没找到任何专门谈论这个的东西。 If not, is there something obvious that I am missing? 如果不是,是否有明显的我想念的东西?

This "simple" program is driving me insane, any help at all is appreciated. 这个“简单”的程序让我发疯,任何帮助都值得赞赏。

I switched the line: 我换了线:

MSComm21.Output = "PHOTO" ' Step 1

with: 与:

MSComm21.Output = "P"
MSComm21.Output = "H"
MSComm21.Output = "O"
MSComm21.Output = "T"
MSComm21.Output = "O"

And I was able to get it to work. 而且我能够使它正常工作。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM