早上好
我用C#和Windows Forms开发了一个应用程序,它可以打开一个串行端口并在txd,dtr和rts上进行传输。
我希望能够使用tcl / tk做到这一点,但是在tcl / tk上找到串行端口教程非常困难。我确实在Stackoverflow Here上找到了一些东西。但是运行时:
它说“无法打开串行“ COM7”:权限被拒绝”
有人知道为什么拒绝权限以及如何授予权限吗?该代码甚至也可以工作。
有人可以尝试使用任何示例代码吗?或者可以将我指向一个易于理解的好来源?
答案 0 :(得分: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上逐字记录的)
编辑:很抱歉,但是我没有足够的声誉来发表评论,但是指定平台来缩小权限问题的范围可能是个好主意。