plc to pc communication using VB


Thread Starter


My PC tool is VB. I want to receive a data string from FX2n-4AD mitsubishi PLC. I tried MSComm in VB with 9600,n,8,1 settings. Following is the code in form load MSComm1.CommPort = 1 MSComm1.settings = "9600,N,8,1" MSComm1.InputLen = 0 MSComm1.PortOpen = TRUE Text1.Text = MSComm1.Input MSComm1.PortOpen = FALSE Data was easily transfered in DOS mode using PROComm communication software. Mode of communication is RS 232. Can anybody suggest the right way of serial communication using VB for RS 232. MSDN documentation examples were tried. I will be happy if the process of communication at low level is also explained.

Crucius, Wesley

What you need to do is handle the MSComm control's OnComm event, and in it you must check if the event is a received character event. If so, then you execute the code to get the data, such as "Text1.Text = MSComm1.Input". The way you have it right now, the data would have to arrive in between execution of these two lines: MSComm1.PortOpen = TRUE Text1.Text = MSComm1.Input That's not very likely... Also, in your OnComm event, after you get whatever chars where in the buffer, you should go back and check if more chars have come in while you were getting/processing the ones that got you into the OnComm event, otherwise you won't process those chars until more chars arrive causing a new OnComm event. I have seen a decent book specificaly addressing use of the MSComm control, but I don't recall Title or Author. Try Amazon?

Eric Johnson

A good book for programming serial communications in VB is Visual Basic Programmer's Guide to Serial Communications by Richard Grier, Zane Thomas (Editor), James Shields (Editor), Phounsavan

Rocco F. Dominick

Take a look at Home Automation Basics, Practical Applications Using Visual Basic by Thomas E. Leonik, P.E., published by Prompt Publications, SAMS Technical Publications. The ISBN is 0790612143. The book explains how to use Visual Basic 6 in a home-monitoring system using an Allen-Bradley MicroLogix Controller. Given the basics, you should be able to communicate with any PLC. Hope this helps. Best regards, Rocco F. Dominick