Jump to content

Recommended Posts

Hello Everyone,

I am new to this community and to Unitronics PLC. I have worked on the PLCs but I am not familiar with Unitronics PLC and its software.

I am trying to connect with sensor that responds to data over RS485 (polling). I have the sensor registers and commands that are obviously in ASCII.

I need to write and read from sensor over RS485.

Can someone please just provide me a sample program to initialize COM, Send Command, Read Response and display this on HMI?

I just a sample then I can workout for the whole program, the controller I am using is V130-33-T38.

 

Looking for guidance

Shahid

Link to post
Share on other sites

Thanks for the reply

I have attached pics of the protocol used by sensor.

For RS485, it supports polling EE (Controller sends 2 byte message and Sensor No. 2 responds with only speed message) and EA (Controller sends 4 byte command and sensor responds in A Format).

I just need a simple example for init com, polling EE, receiving response and display it on HMI for now.

Using this example , I will go for and EF (configuring).

Thanks

1.JPG

2.JPG

3.JPG

Link to post
Share on other sites

I've said this before, but here it is again.....

Don't do anything PLC wise until you've done lots of preliminary work using your PC.  The best method to start with anything Modbus that you don't really know, is to use one of the various (free) modbus programs available to get your PC communicating correctly with the device.  You then learn all the registers you want to use and how to go about it.  Doing this via the PC is far, far easier than mucking around with the PLC trying to get an unfamiliar device to work.

With that knowledge you then transfer the relevant details to the PLC, and if done correctly it will work first go.  Remember the addressing differences of 1 that the Vision's do.

As mentioned by others there are numerous examples in the various Help files within Visilogic.  Also understand that the Help files are where many questions can be answered during your learning curve, and if you look for MODBUS using the Help Index you'll find lots of info that you need to thoroughly understand.  For actual examples, go to Help/Examples/Version 900/ Project examples/Communications/Modbus.

cheers, Aus

  • Like 1
Link to post
Share on other sites

Hello everyone,

I have just completed this program and want some suggestions/ inputs before testing to get this done efficiently.

I'll be really grateful for any suggestions/ errors pointed out.

This is the overall program.

1.thumb.JPG.3a8f3f0a913168ee00c346b7d56a81c6.JPG

Initialized com port

2.JPG.35d2d5b029e140cc8eaab9ad4112e462.JPG

Protocol Configuration

3.JPG.96f38fa176594de05ec2f5cbd15e4506.JPG

I need to send this request and stored EA020113 in MI-1.

send.JPG.fa80671454544330296ca24c42f0f998.JPG

Stored value (EA020113) is sent after 100ms interval.

4.JPG.535bf1d7daef8627984ec6092eca1b53.JPG

This is the send protocol which I have used.

5.JPG.3a895890aab481be7398c3a7f20faa44.JPG

Following is the expected response from the sensor.

recieve.JPG.a7a5759f85eab8840ea3b46c56e81fa3.JPG

I have used STX, 2 byte variable and checksum.

6.thumb.JPG.5410a7a7f9e813b4e6cf77e3dff21edb.JPG

This is my checksum byte setting.

7.thumb.JPG.579182b88c72485d3de9e64ee457de32.JPG

The two byte response is stored in MI-10 and as per response 0-11 bits contain speed. So, I have used following masking technique (0x0FFF AND Response) to get 0-11 bits which are then stored in MI-15.

8.JPG.f86135665f6786886f699c47b192dbe6.JPG

Then finally created this Numeric variable on HMI (Link: MI-15) to display speed.

9.thumb.JPG.a788bea9734a3b4c07cacf84f745d91c.JPG

 

Please someone go through steps and check everything is fine. Specially, checksum in receive and masking of received message.

Regards

Shahid

Link to post
Share on other sites

You're sending the request 10 times a second in rung 2 without waiting for the sensor to reply.  I'd block the SEND block with a NC of MB 2 and reset MB 2 with a NO of MB 4.  You'll also have to reset MB 4 yourself.

8 hours ago, Shahid said:

lease someone go through steps and check everything is fine

It looks OK, but I'd follow Aus's recommendation and check it with a terminal program on your PC that is capable of displaying raw hex values such as Bray's Terminal.  You'll need a USB to RS485 adapter as well for this.

I'd go ahead and download it.  You're not going to break anything.

If you don't have a second COM port installed in your V130 you need to do that - either a serial port or an Ethernet port so you can go online with the PLC.  Otherwise you'll be blind trying to troubleshoot your program.

Joe T.

  • Like 1
Link to post
Share on other sites
15 hours ago, Shahid said:

some suggestions/ inputs before testing

You can use info mode for test what PLC send to sensor and what sensor send to PLC.

It is possible to find com port settings and see RX and TX buffer.

Please try to load program and check this useful option.

I use it for configure communication with not standard protocol device.

If tx buffer is the same as on PC than RX from device must be the same

  • Like 1
Link to post
Share on other sites

Thanks

By info mode, I assume that it sniffers everything has been received (RX)? Even it doesn't fulfill the scan criteria. Once, the buffer is reset it is gone?

Secondly, I used store block to store value of EA020113 in MI-1 but during online test it showed only lower 2 bytes i.e. 0113 as shown below. Then I used EE12 instead.

send_bytes.JPG.260eef48abce1aff41737aafe1ee15a1.JPG

Regards

Shahid

Link to post
Share on other sites

I have sorted out most with help of you guys, thanks.

I think there is some issue between hex to ASCII conversion whilst sending on protocol. I was trying to send HEX as ASCII but wasn't working then I inserted relevant ASCII characters to which sensor responded. Do I need to convert stored value to ASCII first then link in Scan FB Protocol?

Also, Scan FB is working on when I insert checksum byte as control character as shown below. As a variable it is not working, is it the same issue of ASCII to HEX conversion?

checksum_cr12.JPG.88842dcfe3c186353a26466c5dbe575d.JPG

Thanks

 

Link to post
Share on other sites
5 hours ago, Shahid said:

Do I need to convert stored value to ASCII first then link in Scan FB Protocol?

Scan FB Protocol used for "read-in" not standard messages. Main problem is to find correct message format. 

If i can not find correct check sum method - i try to read-in message without it.  It works....  Sended by another device message do not need to be scanned

directly as it appear in manual. Only start of message must be correct (for separate message) and message length must not be longer then scanned variable - message can be written to buffer and it can be parsed by byte operation.

But in this method some Silent period must be prepeared. (without  it FB Protocol sometimes react on checksum as message start).

Check sum needed only if you must 100% correct  data scan.  For testing it is not needed.

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...