Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: PLCwannabe on March 05, 2021, 09:34:45 AM

Title: How to set up Ascll
Post by: PLCwannabe 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.
Title: Re: How to set up Ascll
Post by: franji1 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.
Title: Re: How to set up Ascll
Post by: Greg 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...

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.
Title: Re: How to set up Ascll
Post by: PLCwannabe 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?
Title: Re: How to set up Ascll
Post by: franji1 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.
Title: Re: How to set up Ascll
Post by: PLCwannabe 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.
Title: Re: How to set up Ascll
Post by: Greg 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:
Then use 4 STRGETBs:
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.
Title: Re: How to set up Ascll
Post by: Greg 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.
Title: Re: How to set up Ascll
Post by: PLCwannabe 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.