Author Topic: Urgently need your help to solve Auto485 problem  (Read 12355 times)

Han

  • Newbie
  • *
  • Posts: 5
  • I'm a llama!
    • View Profile
Urgently need your help to solve Auto485 problem
« on: December 10, 2005, 11:03:47 PM »
Hi, I have a problem with auto485 card. Here is the senario:
In my project, 3 H-series (T44H) are used to control 24 cylinders. Inside each PLC, a program is burnt in to control the movements of cylinders. 3 PLC is coordinated by a Main PC. Through a Auto485 card, 3 RS485 linked PLC card connected to PC. The software we use to control PLC is C++, and the communication mode of Auto485 is set to RTS. However, when I power on my pc for the first time, I always got communication probelm with Auto485 card. When I tried to quiry the status of PLCs, the light and red indicator on Auto485 kept on blinking. I give u a example; I sent a commond "@01RI0000*" to PLC, the received data is like "RI0005A*". Since I am not getting the correct data, so my program will keep on looping until I got the correct data. Sometimes, i have to wait for 5 minutes to get a correct format response.
The Funny thing is: when I close my own program and turn on WINTriLogi 3.52 software and send out the same commond thru controller->serial port setup interface, I would get a message like "No response from PLC". So I close this WinTriLogi 3.52 software and turn on my own program to try again, amazingly, everything is working properly!! So I want to know in your WinTriLogi source code, what you have done to configure the serial port? In my program, the code was written properly to control RTS line, but why my program just can't work properly at start up? And only can work well after having tried WinTriLogi??
Answer from you is Urgently needed!
Thanks!!

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Urgently need your help to solve Auto485 problem
« Reply #1 on: December 11, 2005, 12:05:19 AM »
From what you described, it seems like when you first run your program, the strings that your program sent to the PLC is probably incomplete and that's why the PLC is not responding (the TX LED blinks but RX LED does not blink).

I think it is likely a timing problem of when your VC++ program turns ON and OFF the RTS line that controls the RS485 transmitter.

Your program may have turned OFF the RTS BEFORE the last data bit has been transmitted out of the PC serial port . That means that the PLC did not receive a correct last data byte (CR byte) and it treat the command string as error and therefore did not respond.  Note that you can't just turn OFF the RTS right after you call the O/S to transmit the last character. This is because the O/S will put the character into a shift register when you ask it to send a character, and it need 10 bit times to shift out the entire character.  So your program must be structured such that an interrupt is generated when the transmit shift register become empty, and the interrupt service routine must then turn OFF the RTS line so that the PC can start to listen to response from the slave PLC.

If you happen to have another Auto485 you could connect another PC running HyperTerminal software to monitor what's actually going on between your VC++ program and the PLC. That way you can see exactly what the PLC is seeing and it is the best way of monitoring the communication between two RS485 devices.

Regarding your experience of how "WinTRiLOGI" somehow has "corrected" some behavior in your VC++ program,  we can't really think of what's so speial about WinTRiLOGI initialization. What it does is quite normal:

1) Set port to 9600, 8 data bits, 1 stop bit, no parity
2) Turn OFF any hardware flow control
3) set the Rx timeout to 500ms.

Also note that WinTRiLOGI uses a different serial driver: "JSPWIN.DLL" which is installed into the JRE subfolder to communicate with the PLC. Whereas the C++ program probably uses the "MSCOMM32" control provided by Visual C++ so they are different. Unfortunately You can't use the JPSWIN.DLL with your VC++ program.

The only plausible reason I try to guess is that somehow the JSPWIN.DLL may setup the PC such that the RTS is only turned OFF after the last stop bit has been sent. If that is the case, then you will have study VC++ program to setup the interrupt to achieve the same.

« Last Edit: December 11, 2005, 12:13:55 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Han

  • Newbie
  • *
  • Posts: 5
  • I'm a llama!
    • View Profile
Re:Urgently need your help to solve Auto485 problem
« Reply #2 on: December 11, 2005, 03:56:54 AM »
Thanks! But I still facing the same problem. So I repeat my problem and hope you can help me out of difficulty.
1. Power on pc.
2. Open my own program.
3. send a commond to quiry PLC status using my own program.
4. Both green and red light indicator keep on blinking, data I collect     back all no "@01" (using another monitoring program)
5. Close my own program.
6. Open WinTriLogi program.
7. Open serial port using WinTriLogi and send a command like"@01"
8. The messgae displayed in WinTrilogi is "No response from PLC"
9. Close WinTriLogi program.
10. Open my own program and start working.
11. Wooo! Everything seems fine!
12. power off PC.
13. Turn on PC again, and I face the same problem.

Note: PC I used is industrial PC from Advantech and the serial port I use is COM1


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Urgently need your help to solve Auto485 problem
« Reply #3 on: December 11, 2005, 04:51:41 PM »
If both red and green LEDs (Tx and Rx) are blinking, it shows that the PLC has received the correct command string and has sent the responses. Now the problem seems to be that your VC++ is too slow to turn off the RTS such that the first few characters of the response string ("@01" that you mentioned) sent by the slave are lost (because the RS485 transmitted is still driven by the PC).

However, we don't quite understand why after running the WinTRiLOGI program suddently your program seems to be able to receive the response string in time. It definitely has something to do with your VC++ configuration of the serial port. You may like to search Microsoft website for some discussions regarding control of RTS line in VC++ codes.

Note that the unlike the M-series and E10 PLCs, the H-series PLCs does not deliberately insert a 10ms delay after receiving the command string before it sent the response string. Although this allows the host program to talk to the PLC as fast as possible, but it also demands that the host computer program  must accurately manage the timing of the RTS line in order to achieve successful commuication every time.

The T100MD1616+ and E10+ PLCs would be much more forgiving in terms of RTS timing (in fact you don't need to control RTS and you can let the Auto485 do the auto turnaround). In this case since you are using the H-series PLC you will need to work on your VC++ program to resolve the timing issue.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Han

  • Newbie
  • *
  • Posts: 5
  • I'm a llama!
    • View Profile
Re:Urgently need your help to solve Auto485 problem
« Reply #4 on: December 12, 2005, 01:12:32 AM »
Thank you for your reply. but the problem still exists. I tried many timer setting, yet couldn't find a proper one.
So can you please kindly tell me how you control transmission in your WinTriLogi program? I really have no clue why my program can't work without having tried yours first?
FYI, it seems WinTriLogi couldn't work well under RTS mode either. (as "no response from PLC" displayed)
At first, I tested my program using Auto turnaround mode, 95% of the time it works well. However, as a industrial control system, I couldn't afford any data transmission error. WinTriLogi also works well when set to Auto Turnaround mode.


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Urgently need your help to solve Auto485 problem
« Reply #5 on: December 12, 2005, 11:20:58 AM »
From what I understand, the default serial port driver provided by Microsoft is not a very robust piece of software and other VC++ programmers have also complained of various kind of timing related issues with regards to hardware control. In WinTRiLOGI it uses a third party serial driver jspwin.dll which is written to interface with Java programs only. However, there are also other vendors that provide third party .dll file that claimed to be able to handle handshaking with RTS better than Windows. You can do a google search for VC++ serial driver. One of those links I found is as follow:

http://www.hallogram.com/compare/comm.html

However, since we don't program in VC++ we won't know if what they claims are valid.

Anyway, you could still use the Auto485 in Auto turnaround mode. Just make sure that in your VC++ program you check that the response string matches the header of the command strings (the first five characters) and then verify that the FCS is received correctly before accepting the response message as valid. If you receive an error package, simply discard it and resend again. It is not uncommon for errors to affect communication due to presense of noise etc in industrial applications, so it is important that your program code must check for the validity of the response strings. In WinTRiLOGI the program also verify the received string and rejects any malformed response with wrong FCS so it would work well with Auto485 in Auto mode even if there are missing characters caused by the transmitter turnaround delays.
« Last Edit: December 12, 2005, 11:22:26 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Han

  • Newbie
  • *
  • Posts: 5
  • I'm a llama!
    • View Profile
Re:Urgently need your help to solve Auto485 problem
« Reply #6 on: December 12, 2005, 04:58:11 PM »
Thanks.

Han

  • Newbie
  • *
  • Posts: 5
  • I'm a llama!
    • View Profile
Re:Urgently need your help to solve Auto485 problem
« Reply #7 on: December 13, 2005, 06:45:59 PM »
DAER SIR, BELOW IS PORTION OF H-COMMUNICATION MANUAL TOGETHER WITH H-SERIES PLC. CAN I HAVE THE SAMPLE C PROGRAM MENTIONED IN THE MANUAL??



   Host Communication Program Examples

Two sample programs, one written in Microsoft GWBASIC (HOSTCOMM.bas) and the other written in Borland International's Turbo C (HOSTCOMM.C), are provided in the TRiLOGI distribution diskette to help programmers get started. Both programs essentially perform the same functions,  as follows:

(a)    Prompt user to enter the desired command block via the PC's keyboard.

(b)   Initiate a communication session (for point-to-point protocol only) and send the command string to the controller.

(c)   Wait to receive the response block from PLC and display the response block on the PC's screen.

These two programs incorporate all the codes needed to communicate successfully with the T20/28/44H in either BASIC or C language using the point-to-point protocol. Programmers can therefore build their applications using either of the programs as building blocks.

For those who wish to experiment with the RS485 network, A program "Host485.C" in Turbo C language has also been included. This program assumes that an RS232-to-RS485 adapter is used such that the direction of communication of the RS485 bus is controlled by the state of /RTS line of the RS232C. This program accepts both point-to-point and multipoint commands from the keyboard and automatically initiates the correct communication protocol with the control. If your RS485 adapter works differently then you must modify the functions "transmit485()" and "receive485()" to control the direction of the half-duplex RS485 bus. Please refer to the technical manual of your RS485 adapter for details.

Although written for RS485 bus, you can also experiment with this program using PLC's RS232 interface, you would however not be able to link more than one H-series PLC to the host PC in this case.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Urgently need your help to solve Auto485 problem
« Reply #8 on: December 14, 2005, 07:18:26 AM »
In your WinTRiLOGI CD-ROM there is a folder called "DOS" and a zip file called "DOS TRiLOGI v 4.13.zip". You can unzip the file to run the "DOS TRiLOGI.exe" file to extract all the files of DOS TRiLOGI to a folder. Then you can find example files host485.BAS and host485.C inside the subfolder TL3. Note that these example programs only runs under DOS but it give you some idea of how the RTS is controlled.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS