Shahid Posted December 16, 2020 Report Posted December 16, 2020 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
Cam Posted December 16, 2020 Report Posted December 16, 2020 Check in sample programs under communications. I’m fairly certain one already exists there. 1
MVP 2023 kratmel Posted December 16, 2020 MVP 2023 Report Posted December 16, 2020 Please post sensor nameplate or model. If sensor protocol is standard modbus - it is simple solution. If non standard protocol used - you must setup FB Protocol TX sender and RX scanner. In Visilogic you can find Example project with Communication configuration. 1
Shahid Posted December 18, 2020 Author Report Posted December 18, 2020 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
MVP 2023 Ausman Posted December 18, 2020 MVP 2023 Report Posted December 18, 2020 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 1
Shahid Posted December 22, 2020 Author Report Posted December 22, 2020 Thank you very much for replies. I have gone through some of the examples and I will be using FB Protocol not Modbus. Once, I'm finished, I will show here to see if there is/ are any mistakes. Thanks a lot Shahid
Shahid Posted December 28, 2020 Author Report Posted December 28, 2020 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. Initialized com port Protocol Configuration I need to send this request and stored EA020113 in MI-1. Stored value (EA020113) is sent after 100ms interval. This is the send protocol which I have used. Following is the expected response from the sensor. I have used STX, 2 byte variable and checksum. This is my checksum byte setting. 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. Then finally created this Numeric variable on HMI (Link: MI-15) to display speed. Please someone go through steps and check everything is fine. Specially, checksum in receive and masking of received message. Regards Shahid
MVP 2023 Joe Tauser Posted December 28, 2020 MVP 2023 Report Posted December 28, 2020 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. 1
Shahid Posted December 28, 2020 Author Report Posted December 28, 2020 Dear Joe T. Thanks for replying and will follow as per your suggestion. I connected sensor with PC on RS232 and response was as follow for the same request. I have only port that is the problem. I think the checksum byte is also fine in scan function. Thanks
MVP 2023 kratmel Posted December 28, 2020 MVP 2023 Report Posted December 28, 2020 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 1
Shahid Posted December 29, 2020 Author Report Posted December 29, 2020 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. Regards Shahid
Shahid Posted December 29, 2020 Author Report Posted December 29, 2020 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? Thanks
MVP 2023 kratmel Posted December 29, 2020 MVP 2023 Report Posted December 29, 2020 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. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now