News:

  • October 18, 2026, 07:26:10 PM

Login with username, password and session length

Author Topic: How to set up Ascll  (Read 9815 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
How to set up Ascll
« on: March 05, 2021, 09:34:45 AM »
So I've got a new 4 line display  that uses modbus rtu comms  but has ascii characters.  Unit ID is 2. I've done a bit of modbus stuff, but never ascii stuff.  What is the quickest way to set this up?  For now i just want to write the $now .second value to the display so i can see it working.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: How to set up Ascll
« Reply #1 on: March 05, 2021, 10:48:04 AM »
Do STRPRINT to a string (say SS0).  The new editor for STRPRINT lets you format it easily.  Make sure it's the way you want in SS0.

Then use STRPUTB to Put bytes from SS0 to your data buffer for the MWX instruction, say V memory, e.g. V100

Then use MWX to Write Holding Registers referencing that V100 for the number of WORDs.

You may need to tweak the last BYTE and make it 0.  The easiest way to do that is you can use SETNUMR V100 0 for the whole buffer before you do the STRPUTB.

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: How to set up Ascll
« Reply #2 on: March 05, 2021, 02:35:55 PM »
PLCwannabe,

Actually, I think franji1 meant to say for you to use the STRGETB "Get Bytes Out of a String", not the STRPUTB. I still get those swapped because it seems counterintuitive when you are going one way instead of the other. So...
  • Execute a STRPRINT to put whatever ASCII text you want into, say, SS0 (e.g. "My dog has fleas.")
  • Execute a STRGETB to get the ASCII bytes out of SS0, starting at Index zero, and the Length can be, e.g. fixed, or maybe SS0.Length, and stuff them into, e.g. V100 like franji1 said. In the example string I mentioned, this will stuff "M" (ASCII 0x4D) into V100:B0, and "y" (ASCII 0x79) into V100:B1, etc. If you looked at these in Data View, in ASCII format, you'd see them.
  • Execute the MWX that will write this data, starting in V100, either a fixed length or the variable length, to your Modbus RTU slave/server.

All this should work just fine unless your 4-line display is expecting the ASCII characters in a different order (which has been the case plenty of times in my experience). Of course, if they show up weird on your display, then you may have to use something like the PUBLISH instruction to swap bytes.
There are two types of people in the world; those that can extrapolate from incomplete data sets.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: How to set up Ascll
« Reply #3 on: March 06, 2021, 12:10:53 AM »
I'm having trouble even reading registers from this display. Attached is the display spec sheet.Am I doing this right by trying to use the MRX command to communicate or will I have to figure out the stream in/ streamout instructions for this display?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: How to set up Ascll
« Reply #4 on: March 06, 2021, 09:31:12 AM »
Key phrase is "applicable holding registers".  Please posr thoe details om that, then that will tell us how to fill in the MWX instruction.  Provide a link to the complete manual.  That stuff is in a chapter or appendix.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: How to set up Ascll
« Reply #5 on: March 06, 2021, 10:17:02 AM »
Attached is the complete manual. Only 16 pages. The last few pages describe the comm format and holding registers.

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: How to set up Ascll
« Reply #6 on: March 06, 2021, 01:01:28 PM »
PLCWannabe, looks pretty straightforward to me. You could use your STRPRINT to format 4 20-character strings (1 for each line of the LCD display), or 1 80-character string (as long as you know that it is 20-characters per line). Then, use the STRGETB to get the ASCII bytes out of each of your 4 strings (or the one long one), and store that somewhere. For example, if you did 4 strings (one for each line on the LCD, then you might have 4 STRPRINTs:
  • SS0 = "Mary had a lamb"
  • SS1 = "Fleece was white"
  • SS2 = "Everywhere Mary went"
  • SS3 = "Lamb sure to go"
Then use 4 STRGETBs:
  • SS0 --> V100-109
  • SS1 --> V110-119
  • SS2 --> V120-129
  • SS3 --> V130-139
Then use 1 MWX writing 40 Holding Registers (FC = 16 "Write Multiple Holding Registers") starting at Holding Register "40001" which should be Register zero as shown in the manual page 13.

Of course, this is just a test to get it working. But it should work. Then you can tweak your PLC code to make the display look the way you want.

Also, you can use the MRX to read (FC = 03 "Read Holding Registers") to read Holding Registers 40040-40059 (20 registers) to get the status of things listed on page 14. You can store these wherever you like in the BRX PLC. Or use multiple MRXs and just get then one at a time.

Anyway, you get the idea. Hope this helps.
« Last Edit: March 06, 2021, 01:03:13 PM by Greg »
There are two types of people in the world; those that can extrapolate from incomplete data sets.

Greg

  • HostTech
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 702
  • Hmmm...
    • Host Engineering, Inc.
Re: How to set up Ascll
« Reply #7 on: March 06, 2021, 01:09:08 PM »
PLCWannabe, actually there is a paragraph on page 12 that may mean you cannot write as many Holding Registers as 40 like I said. It says:

Quote
"PACKET LENGTH: According to the Modbus specification, the packet length shall be maximum 253 bytes including address and CRC. Maximum length of packet (serial line PDU including address byte and 2 bytes CRC) supported by the sensor is 28 bytes. Packets of larger size are rejected without any answer from sensor even if the packet was addressed to the sensor."

So, you may have to use multiple MWXs instead of one big one.
There are two types of people in the world; those that can extrapolate from incomplete data sets.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: How to set up Ascll
« Reply #8 on: March 06, 2021, 11:59:50 PM »
Success! I just got this to work just the way you guys described it. Thanks for the awesome instructions. 
P.S.  I did have to use the Byteswap instruction, every set of 2 letters was inverted.