打开一个serialport,在txd,dtr和rts上传输

问题描述 投票:0回答:1

大家早,

我开发了一个带有C#和Windows Forms的应用程序,它打开一个serialport并在txd,dtr和rts上传输。

我想能够用tcl / tk做到这一点但是在tcl / tk上找到serialport教程证明是非常困难的。我确实在Stackoverflow Here上找到了一些东西。但是在运行时:

它说“无法打开串行”COM7“:许可被拒绝”

有谁知道为什么许可被拒绝以及如何授予许可?此代码甚至可以工作。

有没有人有我可以尝试的示例代码,或者可以指向一个好的可理解的来源吗?

serial-port tcl tk
1个回答
1
投票

您可以查看此示例,该示例使用Tcl / tk从串行端口读取数据:

############################################
# A first quick test if you have a modem

# open com2: for reading and writing
# For UNIX'es use the appropriate devices /dev/xxx
set serial [open com2: r+]

# setup the baud rate, check it for your configuration
fconfigure $serial -mode "9600,n,8,1"

# don't block on read, don't buffer output
fconfigure $serial -blocking 0 -buffering none

# Send some AT-command to your modem
puts -nonewline $serial "AT\r"

# Give your modem some time, then read the answer
after 100
puts "Modem echo: [read $serial]"

############################################
# Example (1): Poll the comport periodically
set serial [open com2: r+]
fconfigure $serial -mode "9600,n,8,1"
fconfigure $serial -blocking 0 -buffering none

while {1} {
    set data [read $serial]             ;# read ALL incoming bytes
    set size [string length $data]      ;# number of received byte, may be 0
    if { $size } {
        puts "received $size bytes: $data"
    } else {
        puts "<no data>"
    update      ;# Display output, allow to close wish-window
}

############################################
# Example (2): Fileevents
set serial [open com2: r+]
fconfigure $serial -mode "9600,n,8,1" -blocking 0 -buffering none -translation binary
fileevent $serial readable [list serial_receiver $serial]

proc serial_receiver { chan } {
    if { [eof $chan] } {
        puts stderr "Closing $chan"
        catch {close $chan}
        return
    }
    set data [read $chan]
    set size [string length $data]
    puts "received $size bytes: $data"
}

(免责声明:这是从here逐字逐句采取的)

编辑:我很抱歉,但我没有足够的声誉来评论,但是指定平台来缩小与权限问题相关的内容可能是一个好主意。

© www.soinside.com 2019 - 2024. All rights reserved.