Answer the question
In order to leave comments, you need to log in
/bin/sh and RS-485: how to send 9 bytes to /dev/ttyS1?
This question is a continuation of this one .
1. There is a PLC with RS-485. Linux is running on the PLC.
2. There is also a BPI with RS-485. A temperature sensor is connected to the BPI. BPI via RS-485 is able to transmit the current temperature value.
The BPI implements a data exchange protocol.
Here is a brief description of the protocol:
=========================================== ==============
Frame format frame
length during reception and transmission does not change and is equal to 9 bytes
b0 -Es0 - Synchro 0 0xCA
b1 -Es1 - Synchro 1 0x35 reception (from the computer to the device) / 0x53 transfer (from device to computer)
b2 -Ed0 - byte 0 of the data block
b3 -Ed1 - byte 1 of the data block
b4 -Ed2 - byte 2 of the data block
b5 -Ed3 - byte 3 of the data block
b6 -Eid - device identifier
b7 -Ecm - Command/response
b8 -Eid - CRC CS addition to 0
===================== ======================================
Data transfer rate 19200 bytes/sec.
stop bits - 2
parity - no.
Device identifier ID: 1-255 //Set in BPI, in our case = 1
Response code bits (Ecm)
Rerr 7 // Error present err+cdr+nop
Rcdr 6 // Frame error cdr
Rcrc 5 // CRC error
Rnop 4 // Error (no command specified) nop
Rrnq 3 // Specified address is out of range of valid addresses
Rrdy 2 //
Rack 1 // Command completed
Rbsy 0 // Unable to execute the command, the device is busy
1. If the Slave receives a valid request and can process it normally, then returns a normal response.
2. If Slave does not accept any value, no response is sent. The master diagnoses the error by timeout.
3. If the Slave accepts the request but encounters an error (ID), no response is sent. The master diagnoses the error by timeout.
4. If the Slave accepts the request, but cannot process it (a non-existing command is specified, etc.), a response containing error data is sent.
===============================================
To get the temperature value, you must send a request to the BPI specialist:
CA 35 00 00 00 00 01 0C F4
The protocol description says that the response should be returned in the form:
ca 53 ww ww ww ww ID Ecm CRC
, where is the
hex ww ww ww ww
-float temperature value
Tried like this:
/dev/ttyS1
echo "\xCA\x35\x00\x00\x00\x00\x01\x0C\xF4" > /dev/ttyS1
Answer the question
In order to leave comments, you need to log in
Probably, you need to somehow configure the transmission parameters: wakeup rate, start / stop bits, data bits. How to do this in Linux, unfortunately, I will not tell.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question