01-06-2014 01:26 PM
Hello Precious Developers,
How do we send the following string command from a PC to a Modbus Ethernet device at starting address 411000 using LVDSC:
"<ID 0><CLR><WIN 0 0 287 31><POS 0 0><LJ><BL N><CS 2><RED><T>H</T>""$0D""$0A"
(Function code 16 - Write multiple Holding registers)
Any pointers / suggestions / example code shall be deeply appreciated.
Solved! Go to Solution.
01-06-2014 04:38 PM
Do you know how many registers this will need? (I'm guessing 1 register for every 2 characters).
Use string to byte array to get an array of the ascii characters that make up the message string. I would use decimate array to get 2 1-D arrays of every other U8 byte. Then use join numbers to get a 1-D array of U16's. Then you can send this array of U16's using the LVDSC module to the correct register address for however many registers it needs.
01-09-2014 01:05 PM
Thanks Raven. You definitely got it going !!!
09-12-2014 03:37 PM
hi,
I implemented your solution but when there is an odd number of character, the last character is not included in the u16 array. Is my implemented correct?
Regards,
Cedric
09-12-2014 04:11 PM
The implementation looks fine.
But why would you have an odd number of characters? If the device is sending U16 data, then you should have 2 x N number of bytes where N is the number of U16 registers. It can't be odd.
09-12-2014 04:17 PM
hi RavensFan,
In my case, I want to send string to MODBUS. To do that, I need to send U16 to the register. If I send 'ab' or 'abc', the output is the same (array containing one value = 24930), you can try with the VI I posted in my previoius post. This is what I wanted to explain in my previous post.
Regards,
Cedric
09-12-2014 06:59 PM
How many registers are put together to define the string?
What byte value is used if a character doesn't exist? (e.g. space, null)
Basically, how does the device pad the unused parts of the string?
You really don't have just an even/odd problem, but also a short string problem. Let's say it allocates 8 registers of U16, which means you have 16 characters. If you have an odd number of characters, you have the problem you have now. But supposed you only use 10 characters out of the 16? You are even, but your data string is still too short.
I would take the string and make sure it is padded to so that you have the full number of bytes you need. Basic string length and concatenation functions along with basic math will solve your problem.
09-30-2020 09:36 AM
I am in the exact same situation as the original poster. However, I am very new to pyModbus and not the best at understanding the solution you posted. Is it possible that you could write out how that code should look for me? I would greatly appreciate it as I think the poster is doing the exact same thing as I am.
Thank you.