![Cape comms2의 Modbus RTU RS485를 Beaglebone black에서 작동하게 만드는 방법은 무엇입니까?](https://linux55.com/image/196467/Cape%20comms2%EC%9D%98%20Modbus%20RTU%20RS485%EB%A5%BC%20Beaglebone%20black%EC%97%90%EC%84%9C%20%EC%9E%91%EB%8F%99%ED%95%98%EA%B2%8C%20%EB%A7%8C%EB%93%9C%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
저는 Cape comms2를 설정하고 데비안을 실행하면서 Modbus RTU RS 485를 Beaglebone Black에서 작동시키려고 며칠 동안 머리를 쥐어뜯었습니다.
/dev/ttyS0
나는 다음과 같이 9600보드, 8비트 데이터, 1비트 정지, 패리티 없이 NodeJS 소프트웨어에 연결합니다.
let SerialPort = require("serialport");
let serialport = new SerialPort(this.device, { autoOpen: false, baudRate: 9600, stopbits: 1, databits: 8, parity: 'none' }, false);
this.log('Opening serial connection… (client = ModbusRTU())')
const client = new ModbusRTU(serialport)
this.success('client is', client)
this.log("Port Open Status: " + client.isOpen);
client.open()
// set a timout for requests default is null (no timeout)
client.setTimeout(2e3)
setInterval(() => {
this.log("Port Open Status: " + client.isOpen);
if (!client.isOpen) return
run()
},10e3)
var i=0
const run = () => {
this.success(`Connected!`)
this.success('--> Running…')
if (i&1) read()
else write()
i++
this.log('<-- Leaving run, but wait for the response in the future call back…')
}
/**
* Read the RS485 packet: start adress 0x0C count 1 register
*/
const read = () => {
// read the 2 registers starting at address 5
// on device number 1.
this.log('About to read, setting the ID to 0xD2…')
client.setID(0xD2)
this.log('Now reading 1 register from start address 0x2A, wait for the response…')
client
//.readHoldingRegisters()
.readHoldingRegisters(0x2A, 1)
.then(args => this.log('Received SoC:', ...args))
.catch(err => this.error('Received eror:', err))
.finally(() => this.log('Received: finally'))
}
/**
* Write to the RS485 register
*/
const write = () => {
// write the values 0, 0xffff to registers starting at address 5
// on device number 1.
//this.log('Writing: 0xD2, [0x03, 0x00, 0x0C, 0x00, 0x01, 0x57, 0xAA,]')
this.log('Writing: FC3 0xD2,0x2A,1')
client.setID(0xD2)
if (true) {
client
.writeFC3(0x06,0x2A, 1, (err, data) => {
if (err) {
this.error('writeFC3:', err)
} else {
this.success('writeFC3:', data)
}
})
}
}
내가 얻은 로그는 다음과 같습니다.
Pepsr v2.2.236 9:56:14 AM