0

First of all, I'm a noob. I'm doing my best here. I really do.

I have a pressure sensor called KITA KP70. This is it's manual: https://drive.google.com/file/d/1ED1kr3cW1mmgM_-hSxhoo-Cbr2zI3ZSo/view

I'm trying to read anything from it using python without any luck. All I get back is an empty response after the code times out.

This is the code I'm using:

import serial

port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=2)

while True:
    port.write("30H30H31H32H".encode())
    rcv = port.read(10)
    print (rcv)

Now the thing is connected as this: The sensor itself is connected to UART to RS485 Converter. This is the device: https://www.amazon.com/HiLetgo-Reciprocal-Hardware-Automatic-Converter/dp/B082Y19KV9

The converter is connected to c232hm-ddhsl-0. This is the product: https://ftdichip.com/products/c232hm-ddhsl-0-2/

And the c232hm-ddhsl-0 is connected using USB to my PC.

I can see the device when checked using the terminal:

ahmad@Ahmad-PC:~/Desktop$ sudo dmesg | grep tty
[    0.073387] printk: console [tty0] enabled
[   13.131371] usb 3-1: FTDI USB Serial Device converter now attached to ttyUSB0

When I execute the command above, the write LED blinks, but nothing else happens. I've checked the cables and everything seems to be correctly connected and to the right color.

Can anyone help me read anything from this device? The list of codes this device accept are listed in the manual.

Thank you in advanced!

1 Answer 1

1

You have been fooled by poor documentation. When they say "30H30H31H32H", they are using an antique method of indicating hex digits. What they mean is the four-byte sequence 0x30 0x30 0x31 0x32, which happens to be the string "0012".

For what it's worth, that number style comes from Microsoft's MASM assembler.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the reply. I've changed "30H30H31H32H" with "0012" without any luck. All I'm getting is still a blank response. Am I using the correct code to read the values?
This thing speaks MODBUS. You have to do the protocol. The "0012" is just the function code. You have to provide a header (\x3a, which is ':'), two-digit ID code, two digit command, THEN the function code, then 4 bytes of data, then an LRC checksum, then a trailer, \r\n. That's assuming you are in ASCII mode, and not MODBUS binary. There is a PyModBus module that might save your life here.
As far as I understand, and before I look into the modbus thing, the command should be like this: port.write(b':0103020001F9\r\n'). This still return an empty response. I've also tried this one port.write(':0103020001F9\r\n'.encode()) and this: port.write(b':0103020001F9') without any luck.
That's the right philosophy, but I don't think that's quite enough digits. ID (01), command (03), function (0200), data needs to be 4 bytes, then the CRC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.