10-13-2010 03:32 AM
Hi, does anyone have any example on how to send data out from VBAI and receive command by VBAI from VB or C#.
I plan to give command to the VBAI to on and off, start acquire image and stop.
For the data to be send out is the result of the calculation by the calculator function. The data will be send out each time the calculation have been done.
I have search in the forum and I know that this can be done by using labVIEW. However, due to the require of the question, I can't do it by using labVIEW.
Thanks.
Yen
Solved! Go to Solution.
10-13-2010 01:22 PM
Vision Builder AI ships with an ActiveX control you can use for exactly that purpose.
Look at the examples located in National Instruments\Vision Builder AI\ActiveX Support\Examples\MSVB
The ActiveX contains methods and properties that allow to drive Vision Builder AI from another application i.e. open an inspection, run it once or continuously and retrieving the image and inspection results.
It seems like this should help solve your application.
To share more data between the 2 application, you can use the TCP/IP step, or another protocal like Modbus (Vision Builder AI is a Modbus Slave device and you can use the Modbus step to read and write VBAI modbus registers). This would require you having a Modbus Master library you can call from your application to read/write the VBAI registers.
Best regards,
-Christophe
10-17-2010 12:15 AM
thx Christophe
but i have no ideal on how to use the TCP/IP and Modbus.
Can you give me some explaination on how to use those function?
What are all of the references that I need? Thx
Yen.
10-19-2010 09:45 AM
Vision Builder can act as a TCP master or slave. In Slave mode, a bakground task monitors a port for incoming TCP communication.
The step allows you to send data and read data from that port. You VB or .NET application just needs to open a TCP communication channel and either wait for or send data to Vision Builder.
Take a look at the TCP/IO step in the Communicate tab.
Vision Builder is also a Modbus Slave device. It hosts a set of registers that can be read/written from within Vision Builder using the Modbus Slave step and from your VB .NET application using the Modbus master protocol. This protocol is based on TCP/IP and you can find some implementation online (google Modbus .NET library).
The Modbus Slave step is located in the Communicate tab.
Best regards,
Christophe
10-20-2010 08:32 AM
Thx ChristopheC.
Now I plan to use modbus function to do the communication.
I found an example in NI web site, but the problem is that I using V in my project but the example is using labVIEW.
For both V and LabVIEW, I also face the same problem which is I cannot neither read or write the register address that I have been set in VBAI to store the data.
Is there any information that I can look for to solve my problem?
Here is the link of the example
http://zone.ni.com/devzone/cda/epd/p/id/5320
and I will attach the V program that I use for my project. Hope that you can give my some advise on this problem.
Thx.
YEN
10-20-2010 08:39 AM
Sorry that the attachment for the previous post having some problem on the VB program so now i post the attachment again
10-20-2010 10:29 AM
Hi Yen,
You're almost there. Here are the steps to get that example to work.
Once you open the inspection in Vision Builder, go to Tools>>Communication Device Manager...
You have to create a Modbus Master Device, that corresponds to your VB application communication with Vision Builder.
Click New Device. Give it a name, say "VB Program".
Select Modbus TCP for the protocol.
Click OK.
On the Modbus Server line, click Start Server. This starts the background task that listens on port 502 for the incoming Modbus messages.
Click OK to exit the dialog.
Now, a couple things to understand about Modbus: the protocol specifies how a Modbus master device can read and write registers located on a slave device. Vision Builder has 4 64k register tables:
- Coils (binary, read/write by the master).
- Discrete Inputs (binary, read only by the master).
- Input Registers (16 bit, read only by the master).
- Holding Registers (16 bit, read/write by the master).
The step Read Tolerances of the inspection read the Minimum and maximum Intensity in the Modbus Holding Registers 0x0 and 0x1.
So you want your VB application to write these values.
Here are the Modbus Function codes. You can get the full list by downloading the Modbus specification at Modbus.org.
0x01 Read Coils
0x02 Read Discrete Inputs
0x03 Read Holding Registers
0x04 Read Input Registers
0x05 Write Single Coil
0x06 Write Single Register
0x0F Write Multiple Coils
0x10 Write Multiple registers
To use your Modbus example program to read and write the Vision Builder registers, first enter the IP address where Vision Builder is running:
127.0.0.1 (localhost)
For this example, use Function Code 6 to write a single holding register.
The Modbus data must be formated as follows: the first 2 bytes are the start address, the second 2 bytes correspond to the value (U16) you want to write to the register. So to write the value 1 at address 0 (corresponding to the min intensity), set Modbus Data to 00000001. Click Send.
Now, set the Maximum Intensity to 50. Set the Data to 00010050. Click Send.
The step Write Data writes the Minium Intensity of the Check Cap Presence step in the Modbus Input Register 0x0, and Step Status in Discrete Input 0x0.
To read the Minimum Intensity written by VBAI, set the Function Code to 4 (Read Input Register). For the Modbus Data, the first 2 bytes represent the address, the next 2 bytes, the number of registers to read. Set the Modbus Data to 00000001 to read one input register at Address 0. Click Send. The Response data can be for example 0x1E, which corresponds to 30 decimal.
To read the step status, set the Function Code to 2 to read discrete inputs. Set the Data to 00000001, to read the first register of the discrete input table located at address 0. The Response Data is either 0 or 1 (Pass or Fail).
Hope this helps. Let me know if you need other information. But this should get you started.
Best regards,
-Christophe
10-21-2010 09:09 AM
Thx ChristopheC
I think I almost get what I want to do, but I have a litter confuse on the Modbus Serial and Modbus TCP.
Actually what is the different in between the Modbus Serial and Modbus TCP.
As I know that the Modbus Serial is use for the serial communication for 2 devise. Is that right?
If I going to use the VB program in a laptop to communicate with the VBAI in another desktop(by using a USB to 9 pin cable) so I need to set the protocol in VBAI as Modbus Serial or Modbus TCP.
For the VB program that I show in previous post, is modbus address refer to the Vision Builder AI ModBus Slave Address?
Can the VB program read the result back from VBAI?
I am a beginner in VB so I am not understand on the VB program that I use. This program I found in my college.
Thx.
Yen
10-21-2010 11:37 AM
> what is the different in between the Modbus Serial and Modbus TCP
The communication Layer. With Modbus Serial, the master and the slave must be connected with a serial cable RS 232 or RS 485.
With Modbus TCP, master and slave must be on the same network subnet (or be running on the same machine). Ethernet is faster.
> As I know that the Modbus Serial is use for the serial communication for 2 devise. Is that right?
Not necessary, but most of the time for Serial. The MODBUS Serial Line protocol is a Master-Slaves protocol. Only one master (at the same time) is connected to the bus, and one or several (247 maximum number) slaves nodes are also connected to the same serial bus. When using Modbus Serial, the Modbus frame contains a slave address, which specifies the recipient of the message. I think this is the address that you specify in the VB program you attached and that must correspond to the slave address in Vision Builder.
> If I going to use the VB program in a laptop to communicate with the VBAI in another desktop(by using a USB to 9 pin cable) so I need to set the protocol in VBAI as Modbus Serial or Modbus TCP.
If the two computers are connected to the network, I would recommend using Modbus TCP, otherwise, you'll have to connect both PCs with a serial cable.
> For the VB program that I show in previous post, is modbus address refer to the Vision Builder AI ModBus Slave Address?
Yes.
> Can the VB program read the result back from VBAI?
Yes, I explained that in my previous post, how by specifying the correct function code, the VB program can read a VBAI Modbus register. You get the data back in the field "Response Data". The data is returned in hex format, and you need might have to convert it back to a decimal value.
-Christophe