Formatting Modbus requests in ruby - ruby

I have a modbus device I am trying to communicate with using an ethernet to RS485 device. I'm not sure whether the device uses modbus ASCII or RTU.
I am trying to format a request to a device with address 1. The command code is 11h. I'm not sure I'm formatting the request properly
Here is the string I am using for ASCII - ":010B000000000C\x0D\x0A"
Here is the hex I'm using for RTU: "\x01\x0B\x00\x00\x00\x00\x0B\xA4"
When I send this command it is echoed back but I'm not getting responses. I've been through the modbus documentation and I think I have the correct byte structure. I'm wondering if I'm encoding it right for ruby?

It turned out my ethernet to RS485 device wasn't capable of the correct timing for modbus. Once I purchased a new unit the ascii strings worked.

Are you sure the checksum should be written in pure bytes, not in ASCII? I mean, try to send :010B000000000C0D0A instead of :010B000000000C\x0D\x0A.
Also, you wrote that the command is 11h - for my understanding it is 0x11 (hex), and you are sending 0x0B. Or the command is 11 (dec)?

Related

ttyusb/uart sends 'USB' during transfer

I am using Go for a project and am transmitting data to an embedded device via the serial port (ttyusb). During fast and "large" transfers I've noticed that the transmitted data did not match the values I'd wanted to send.
I've tried various available libraries, in the end they all read and write using syscalls. So I've attached a Logic Analyzer to see what's going on.
Then I noticed that the data mismatch in the output had a clear pattern: Instead of sending my data the serial port would interleave my data with the following values:
0x55, 0x53, 0x42, 0x53, 0x70, 0x02
Followed by zeros (0x00). In total 22 Bytes. The total number of bytes transmitted via the serial line did match the number of bytes I wanted to write > so essentially my data was masked with these 22 Byte-Blocks. The weird thing is that I can translate those bytes to ASCII
0x55, 0x53, 0x42, 0x53, 0x70 = "USBSp"
Now my Question is: Can't I send arbitrary data (HEX values) over the serial port or are there some control characters that I should be aware of that would make the serial port send out Identity information or the like?
[EDIT]: Additional Information:
Host is MacOS running Go v1.10; tried with go.bug.st/serial.v1 and github.com/tarm/serial, various communication settings (bitrate etc.)
Target is nRF52840 preview development kit, using Nordic nRF5 SDK v12.3.0_d7731ad (not the newest, I know, but the only one supporting other boards too). Using app_uart_x API
you have to configure the serial port. the settings for both devices for baud rate, start/stop bits, ... have to match. then there are libraries in go like https://github.com/jacobsa/go-serial that enable standard serial port communication with that you can also use any hex values.
i can not say why the USBSp is sent because you did not post any code and gave no information what libraries you use. very likely this is not generated by the kernel module and instead by higher layer software because the kernel module used is usb-serial and USBSp does not appear in the source code :
https://elixir.bootlin.com/linux/v4.0/source/drivers/usb/serial/usb-serial.c
also not in kernel module ftdi-sio ( if you use ftdi chip )
https://elixir.bootlin.com/linux/v4.0/source/drivers/usb/serial/ftdi_sio.c
and also not in https://elixir.bootlin.com/linux/v3.3/source/drivers/usb/core/urb.c

Listening to 2 senders on the same USB Port using Docklight

I am currently working on a script in docklight v2.0.
My setup is the following:
I have a splitter connected in the USB port of my PC.
That splitter is connected on a wire on which a communication is made between 2 devices.
Docklight is connected on the USB port and receives all the information transmited through that wire.
I have a script on docklight set up to put every byte in a buffer once docklight sniffs them.
My script is coded using the functions in Docklight and VBScript.
The problem I have is the following:
I put all the bytes in the same buffer, that mixes up the messages from both devices and it becomes impossible to analyse them.
What I need to do:
I need to know which byte comes from which device, Docklight is already able to do so, but I need to do that in my script so I can put the bytes in 2 different buffers to treat the data properly.
Using the fonction DL.OnReceive_GetChannel() solved my problem.

What is a ethernet frame sample which can be sent?

i want to send a ethernet frame from FPGA to my PC for wireshark to receive
i pass payload into CRC generator to get the CRC result, but i guess CRC error as wireshark not received any thing which is my payload
i got 2 ideas
1. find a ethernet frame in hex code in internet and copy to VHDL to send in order to make sure no CRC error and check whether it send or not? could you post a correct ethernet frame in hex code here?
1b. any free CRC generator code in VHDL available in internet? and any free CRC generator code in C++ language or C# language or Java language for hard code CRC in ethernet frame?
2. use layer 2 programming in ubuntu to send a ethernet frame to another computer,
whether i can send and display the ethernet frame which i send in ubuntu or i need to capture with wireshark in another computer?
Use your FPGA tools to create an Ethernet core. This will usually create a testbench for you too. Run that testbench, note down the values of the data produced.
As another alternative, there are some Python libraries I've used in the past to create Ethernet packets.
http://code.google.com/p/dpkt/source/browse/trunk/dpkt/ethernet.py
I've never used this, but it looks like it might be helpful:
http://packeth.sourceforge.net/packeth/Home.html

TFTP packet example?

I'm writing a TFTP server in Ruby and I don't understand a couple things.
First, I read through the entire RFC and I understand the TFTP part of the packet (2 bytes opcode, etc), but I don't know where the TID's go. Also, I've never done anything in Ruby at a byte level. I don't know how to create a variable that's 2 bytes this and then 1 byte that and then whatever.
If someone could show me an example of how to construct a read request packet in ruby, that'd be sweet. Say I'm on the client side and I select port #20000 (for my local TID) and I want to read the file named /Users/pachun/documents/hello.txt on the server which has a TID of 69 right now because it's the first request. How would I construct that packet in Ruby?
Check out this project:
https://github.com/spiceworks/net-tftp
The code there should answer your questions regarding how to construct byte sequences for communicating with tftp protocol.

Serial Port Data Structure

I need to send data to a hardware device over serial port. I'm using a program called serial port tool for os x.
After I connect to the device there is a form box where I can type data to send. I have no idea how to format the data.
Here is an excerpt from the manual for the device.
"The Net Manager Command structure consists of one start byte, one command byte, five bytes of data, and a one byte checksum. Each message packet is formatted as follows:"
an example command is:
Byte0=30 Byte1=7 Byte2=5 Byte3=1 Byte4=2 Byte5=0 Byte6=245
How do I type that into the form box in serial port tool?
Thanks,
Seth
Does the "serial port tool" you're using come with any documentation?
Assuming the "form box" is expecting printable characters, what you're looking for is a way to input an arbitrary byte value. For example, there might be a mechanism that lets you use an octal or hexadecimal escape sequence (such as \036 or \24).

Resources