0

我想测试我的 Märklin Digital 模型铁路系统的一些功能。基本上它由一个(Märklin)中央单元和一个(Märklin)接口组成。这是通过 ComPort 从 PC 向接口发送系统命令以设置螺线管或控制系统的最低配置。信息也可以从轨迹检测模块通过接口 ComPort 发送回 PC。在这种情况下,两个字节被发回。对于这种情况,说明中给出了 Basic 示例,我尝试将其转换为 Win Power Shell。

基本示例:

10 OPEN "COM1:2400,N,8,2"FOR OUTPUT AS #1
20 OPEN "COM1:2400,N,8,2"FOR INPUT AS #2
10 OPEN "COM1:2400,N,8,2"FOR OUTPUT AS #1
20 OPEN "COM1:2400,N,8,2"FOR INPUT AS #2
30 PRINT #1,CHR$(193);:a$=INPUT$(2,#2)
30 PRINT #1,CHR$(193);:a$=INPUT$(2,#2)
40 contact=ASC(LEFT$(a$,1)):PRINT contact
50 contact2=ASC(RIGHT$(a$,1)):PRINT contact2

我的“翻译”:

$connectionproxy = new-object System.IO.Ports.SerialPort com1

$connectionproxy.BaudRate = 2400

$connectionproxy.stopbits = "two"

$connectionproxy.DataBits = 8

$connectionproxy.Parity = "None"

$connectionproxy.open()

do { $connectionproxy.write([char]([int]193)) $ShowBytes = $connectionproxy.ReadLine() Write-Host $ShowBytes } while($connectionproxy.IsOpen)

问题:我无法安全地保存从检测模块请求的文件/显示数据。

我的翻译有什么问题/遗漏了什么?

4

1 回答 1

0

With some serious support (brother and a good friend) I can now deliver the requested functions. All functions have been tested with Märklin 6020/ 6023/6050/6088.

1.) "Windows 7 Power Shell", but without functionality of the Rückmeldemodul S88 (6088):

#---init command sets---
$commandset = @()

#---init connection---
$connectionproxy = new-object System.IO.Ports.SerialPort com1
$connectionproxy.BaudRate = 2400
$connectionproxy.stopbits = "two"
$connectionproxy.DataBits = 8
$connectionproxy.Parity = "None"

do {
$userimput = Read-Host -Prompt "Numbers seperated by space"
$currentcommand = $userimput.split(" ")
$connectionproxy.open()
for ($i=0;$i -lt $currentcommand.length;$i++) {
$connectionproxy.write([char]([int]$currentcommand[$i]))
start-sleep -milliseconds 10
}

$connectionproxy.close()

}while($true)

2.) "Ruby On Rails" for usage of Rückmeldemodul S88 (6088). This program reads the bytes sent back by S88 and shows its pin assignment:

require 'rubyserial'
class Integer
 def to_bin(width)
 '%0*b' % [width, self]
 end
end

puts "open serial port..."
serialport = Serial.new "COM1", 2400, 8, :none, 2
puts serialport.inspect
puts "Reset command for S88:"
bytes_written = serialport.write 192.chr
puts bytes_written.to_s + " bytes written"

sleep(0.1)

puts "Read first S88:"
bytes_written = serialport.write 193.chr
puts bytes_written.to_s + " bytes written"

sleep(0.1)

b1 = serialport.getbyte.inspect
puts "Byte 1: " + b1 + " (" + b1.to_i.to_bin(8) + ")"
b2 = serialport.getbyte.inspect
puts "Byte 2: " + b2 + " (" + b2.to_i.to_bin(8) + ")"

Issue 1: Windows Power Shell is not able to recover any bytes upon request. If anyone knows a good solution, you are welcome to share it. Issue 2: The Rückmeldemodul 6088 and its cable to the central station or interface have to be placed away from the rails, because of inteferences with the signals. (Shielding of the sixcore cable is absolutely miserable.)

于 2021-03-20T13:27:07.320 回答