Communication with NI Vision

Hi All,
I am very new to Arduino programming. I have a very little background in embedded systems.

In this project I am trying to communicate over Modbus TCP/IP with NI Vision Builder AI software to make a fail/pass judgement and communicate it to ATmega 2560 over modbus TCP/IP. I am still short of establishing any form of communication between the vision software and the controller online. I have tried to imitate various tutorials online but they have barely helped.

I am using a ATmega 2560 controller. The NI Vision Builder AI software is installed on a computer.

Has anyone tried this or have worked with NI vision software and Arduino?

Any help and guidance will be much appreciated!

Thank you!

~B

Please provide links to those and explain how they fell short. If you wrote code, please post entire sketches in code tags.

Provide links to any information resources that you used, that might help us help you. Also any external hardware that is attached to the Mega.

Also, please fill in the blanks about what you have tried. For example, have you got modbus working at all, like with example sketches and so on...

Hi,
Thank you for the response.

The software I am trying to use for vision inspection is "NI Vision Builder for Automated Inspection".

I have tried to remotely communicate with using ATMega as a Client and Server (used local modbus application to read/write data) and was successful doing so but when I try to do so using the NI software, I cannot.

I have also attached the arduino programs and libraries I am using to do so.

Tutorial I have used to understand and learn:
https://www.udemy.com/course/how-to-program-an-arduino-as-a-modbus-tcp-client-server/learn/lecture/7404746#questions

Please let me know if you need any other information from my end.

I was not able to attach any code/libraries here. So please refer to the link below (for google drive access).
https://drive.google.com/drive/folders/1gfBAqC1AzGrQ2ALZW3ibGD4q2j_bL7c8?usp=sharing

Greatly appreciate your help.

-B

Your account privileges are increased after the first 24 hours. So you can post code here now.

I did ask for hardware information and none was posted. It's great that you tested your hardware, but some detail is needed for context, while viewing the code.

1 Like

The arduino hardware is ATMega 2560.

The software is installed on windows 10, 64 bit laptop.

Below is the code with Arduino being used as a client (the MgsModbus library was downloaded from Github:[GitHub - andresarmento/modbus-arduino: A library that allows your Arduino to communicate via Modbus protocol, acting as a slave (master in development). Supports serial (RS-232, RS-485) and IP via Ethernet (Modbus IP).]

CODE:

#include <MgsModbus.h>
#include <Ethernet.h>
#include <SPI.h>

int SerialNumber;
int Last_SerialNumber;
int BoxQuantity;
int BoxQuantity_Old;
bool PolyBagDetected;
bool PolyBag_Old;
bool CamInspectionResult;
bool CamInspection_Old;

MgsModbus Mb;  //Modbus Object to encapsulate all the feature of the library 

int acc = 0; //Accumulator, seconds counter

// Ethernet settings (depending on MAC and Local network)
byte mac[] = {0x90, 0xA2, 0xDA, 0x0E, 0x94, 0xB5 };
IPAddress ip(192, 168, 1, 119);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

void setup() {
  Serial.begin (9600);
  Ethernet.begin(mac, ip, gateway, subnet); //Initializes the network connection

  //Server (NI) IP address
  Mb.remServerIP[0] = 192;
  Mb.remServerIP[1] = 168;
  Mb.remServerIP[2] = 1;
  Mb.remServerIP[3] = 165;
    
  SerialNumber = 100;
  Last_SerialNumber = 100;
  BoxQuantity = 30;
  BoxQuantity_Old = 30;
  PolyBagDetected = false;
  PolyBag_Old = false;
  CamInspectionResult = false;
  CamInspection_Old = false;


 DisplaySerialNumber();
  }

void loop() {
 //  mb.task();  
 //  BoxQuantity = mb.Hreg (BoxQuantity_hr); //Modify Box Quantity from the display screen
 //  CamInspectionResult = mb.Coil (CamInspectionResult_cl); //Modify coil status remotely from display screen

   DataPoll();  // Decides which registers to poll the data from everytime the function is called
   Mb.MbmRun(); //Function that runs & implements modbus Client services
   NewCycleRan();
   }

void DataPoll(){
 delay (01);    // 1ms delay
 acc = acc + 1;

//Reading the value of the input register (SERIAL NUMBER OF THE POLYBAG)
  if (acc == 3000){
    Mb.Req(MB_FC_READ_INPUT_REGISTER, 100,1,0);  //Sends a messsage to the server and initiates the reading of the register value from the server
  }

  if (acc == 3200){
    SerialNumber = Mb.MbData [0]; //checks to see if recieved a message from the server and Stores the value in address of the input register 100 at the 1st array block (0)
      }

//Reading the value of the holding register (BOX QUANTITY FOR TOTAL NUMBER OF POLYBAGS IN A BOX)
  if (acc == 4000){
  Mb.Req(MB_FC_READ_REGISTERS, 100,1,0);  // Initiates the reading of the holding register value from the server
  }

  if (acc == 4200){
  BoxQuantity = Mb.MbData [0]; //Stores the value in address of the holding register 100 at the 1st array block (0)
    }

//Reading the status of the discrete input status (POLYBAG PRESENT OR NOT)
  if (acc == 5000){
  Mb.MbData [0] = 0;
  Mb.Req(MB_FC_READ_DISCRETE_INPUT, 100,1,0);  // Initiates the reading of the input status register value from the server
  }

//Stores the value in address of the input register 100 at the 1st array block (0)
  if (acc == 5200){
      if (Mb.MbData [0] == 1){
      PolyBagDetected = true; 
    }
    else {
      PolyBagDetected = false; 
    }
  }

//Read coil status value  
  if (acc == 6000){
  Mb.MbData [0] = 0;  
  Mb.Req(MB_FC_READ_COILS, 100,1,0);  // Initiates the reading of the input status register value from the server
  }

//Stores the value in address of the input register 100 at the 1st array block (0)
  if (acc == 6200){
      if (Mb.MbData [0] == 1){
      CamInspectionResult = true; 
    }
    else {
      CamInspectionResult = false; 
    }
  }
      acc = 0;

 }

//Checks for change in the data values 
void NewCycleRan(){
boolean ChangeDetected = false;

      if (Last_SerialNumber != SerialNumber){
      ChangeDetected = true;
      Serial.println ("New Cycle was ran");
      Last_SerialNumber = SerialNumber;
          }

      if (BoxQuantity_Old != BoxQuantity){
      ChangeDetected = true;
      Serial.println ("Box Quantity Changed");
      BoxQuantity_Old = BoxQuantity;
          }

      if (PolyBag_Old != PolyBagDetected){
      ChangeDetected = true;
      PolyBag_Old = PolyBagDetected;
          }

      if (CamInspection_Old != CamInspectionResult){
      ChangeDetected = true;
      CamInspection_Old = CamInspectionResult;
          }


    if (ChangeDetected == true){
      DisplaySerialNumber();
    }
}

void DisplaySerialNumber() {
  String SrNo;
  String BagStatus;
  String CamStatus;

  if (PolyBagDetected == true){
    BagStatus = "Bag is detected, ready to inspect";
  }

  else{
    BagStatus = "Waiting for bag, cannot initiate inspection";
  }

    if (CamInspectionResult == true){
    CamStatus = "Label Info Correct";
  }

  else{
    CamStatus = "Label Info Not Correct";
  }
  
  SrNo = "Product Serial No is :" + String (SerialNumber);
  SrNo = SrNo + "| And Box Quantity is:" + String (BoxQuantity_Old);
  SrNo = SrNo + "|" + String (BagStatus);
  SrNo = SrNo + "|" + String (CamStatus);
  Serial.println (SrNo);
}

Thank you for the follow up and please let me know if you need any other information from my end.

Thanks, at least, for posting the code. Yes, I need (and other people who might help need) the hardware information I asked for. "The arduino hardware is ATMega 2560" as information is completely insufficient. Please read the forum introductory threads, there is a section there about how to support a question with useful documentation.

You've already been asked for it, two times.

I'm guessing you are using a hardware such as this one described in this manual:
https://manualzz.com/doc/24938004/ni-vision

not sure if you have already been through this iteration of development but if it was me, I would create a 'simple' VI to output some value on RS 232/RS485 and see if on the Mega side, I am receiving the data correctly (via the correct Transceivers of course!)

Once I've confirmed all the settings required to enable this communication, I would then move to my actual project.

NI stuff is quite niche and you probably might be able have better luck find a solution on the NI forums (their forum is actually quite proactive I found! :wink: )

hope that helps...

Below is the detailed hardware information:
o Digital IO
24v 3x Isolated Digital output
24v 3x Isolated Digital Input
o Isolation: 3750VRMS
o Analog IO
8x ADC 0-10V/ 4-20mA max.
10 / 16 bit ADC resolution
3xDAC 0-10V
1x 4-20ma TX
3xADC 0-5v
o Wired Connectivity
RS485 MODBUS, RS232 & USB
Ethernet 10/100Mbps, RDL Expansion Bus
o Memory FRAM 25KB, SD CARD 16GB
o Wireless connectivity
Wi-Fi: 802.11 b/g/n/e/i (802.11n @ up to 150 Mbit/s) Bluetooth: v4.2 Bluetooth Low Energy (BLE) LoRa / Xbee, GPRS/GPS
o RTC
Built-in RTC for stamped data logging
o Protocol
TCP-IP, UDP, MODBUS, FTP, RESTFULL, JSON & MQTT
o Security: SSL
o Power supply DC 12 - 24v

The hardware supports various Open Source Programming IDE including Arduino IDE, Atmel Studio and Arduino Compatible Compiler for Lab View.

Please let me know if you need more information. Thank you for the feedback and support.

Hi Sherzaad,
That is what I am trying to achieve to begin with.

Create a simple program, send an output from NI's Vision Builder AI software to controller (ATMEGA 2560 based) over Modbus TCP.

I have already reached out over NI forum, no luck so far. Anything else you would like to recommend?

Thank you for responding!

unless you have an actual need to use MODBUS why not try using some of the 'simpler' protocols?

for example, since the NI hardware support TCP/IP/UDP why not just try using that?

NI LabVIEW code: UDP sender and receiver and "UDP ping" application (walk-through) - YouTube

Arduino Example code: Sending and Receiving String via UDP ~ Arduino Tutorial

even simpler would to be use plain RS232 protocol. if you're worried about interference on RS232 you can increase it reliability by using RS485 as your physical layer.

hope that helps...

You only posted a list of specifications for something. It looks like you just copy and pasted it from somewhere. Still you haven't even said what it is. Let alone shown how it is connected...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.