Author Topic: Re:Tech Tip & Sample Codes  (Read 6146 times)

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:Tech Tip & Sample Codes
« on: April 03, 2012, 02:33:31 AM »
I am sorry, maybe it is basic and fundamental, but because I am a newbie to this protocol, I want to ask a question.

Whether in the Modbus ASCII there are also functions like function 3,4,6,16, etc?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Tech Tip & Sample Codes
« Reply #1 on: April 03, 2012, 09:24:09 AM »
Modbus ASCII, RTU and TCP are all the same type of codes. They only differ in the representation of the data. Our PLC support the same functions: 01, 02, 03, 04,05, 06, 16 in all 3 types of Modbus protocols.

[Moderator's note]: We have moved your post from Frequently Asked Questions board to here as the former was meant to be posted by the moderator only.
« Last Edit: April 03, 2012, 09:24:52 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:Tech Tip & Sample Codes
« Reply #2 on: April 04, 2012, 03:16:04 AM »
I have Modbus ASCII RS485 slave device with request packet format as picture below.

I have been trying with

Code: [Select]
DM[101] = READMODBUS(3, 6, &H5030)
but it is error on compiling.

Im also trying

Code: [Select]
DM[101] = READMODBUS(3, 6, 20528)
there is no response on DM[101].

Im even trying

Code: [Select]
PRINT #3 "STX06RXP0ETXCRC"
A$ = INPUT$(3)

and still no response.


Previously, I have checked the setting in my slave device and it seem there is nothing strange.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Tech Tip & Sample Codes
« Reply #3 on: April 04, 2012, 03:39:11 PM »
Your command format shows that it is NOT a MODBUS ASCII and therefore READMODBUS will not work.

Since your command protocol appears to be proprietary, you may need to use the OUTCOMM 3, c command to send out the ASCII command string byte-by-byte and use INCOMM(3) command to read the data returned from the slave device byte by byte. (You may need to send out the command, wait for a small delay before reading them back from the serial port).

Note: STX is just the binary number 02, not "S", "T", and "X" - so of course your PRINT command will not work.

You can store them inside a range of DM and then use a FOR ... NEXT loop to send them out one byte at a time.
« Last Edit: April 04, 2012, 03:41:08 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:Tech Tip & Sample Codes
« Reply #4 on: April 16, 2012, 08:51:39 PM »
I have been able to send the command using FOR ... NEXT loop. But the response message is too long to store it in a DM variable.

Im using DM[111] = INCOMM(3)

and in DM[111]  there is -1 in decimal or FFFF in hexadecimal, that indicating if it is overflow.

Can I parsing it in several DM? If it is possible, how to do it?

This is the response format...
« Last Edit: April 16, 2012, 08:54:47 PM by taufiqsunar »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:Tech Tip & Sample Codes
« Reply #5 on: April 16, 2012, 09:29:44 PM »
Yes, you can use a FOR..NEXT loop to store them into DM until -1 and then exit:


E.g.  FOR I = 1 to 256
             DM[I+200] = INCOMM(3)
             IF DM[I+200] = -1  GOTO @10
        NEXT

@10
    ... continue from here.  The actual number of data received = I - 1.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS