UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor deandre_hj
Visitor
1,115 Views
Registered: ‎05-20-2018

Visual Basic Application with Zybo Board using TCP Server

Jump to solution

Hi guys, I am currently working on a Application on the Zybo Zynq-7000. I am able to run a simple application. It is just by using Hercules and input some binaries. For example, in Hercules, if I were to put 1111, the 4 leds would light up. if I were to put 1100, the first 2 leds would light up. Now, my problem is with Visual Basic 2017. I am unable to do the same thing as in Hercules. However, when I put 1111 in the first counter box, the last 2 leds would light up instead. How should I go able solving this? I am rather new to the scene of FPGA and do excuse me for poor English. If any other files are required, do let me know so I can send it over. Thanks in advance.

Screenshot (3).png
Screenshot (4).png
0 Kudos
1 Solution

Accepted Solutions
Moderator
Moderator
1,162 Views
Registered: ‎10-06-2016

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution
Hi @deandre_hj,

In your image I only can see the value of length variable within the p pointer. What you need to check is the content of payload, I mean the values you are getting in the target.

Regards
Ibai

Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos
8 Replies
Moderator
Moderator
1,015 Views
Registered: ‎10-06-2016

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution
Hi @deandre_hj,

To be honest, at least for me it's not clear what you are trying to do and the issues facing. Could you elaborate bit more?

What I do infer from your description is that you have an application running on your Zybo board and you are trying to "send commands" from your host machine using some kind of serial protocol? If you use HWGroup Hercules application everything works fine but as soon as you try to write a VB application to do the same you are not able to make it work, isn't it?

Regards

Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos
Visitor deandre_hj
Visitor
1,014 Views
Registered: ‎05-20-2018

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution

First of all, sorry that it isn't clear. The problem I am facing now is that when I put "1111" into Hercules TCP Cilent, the 4 leds would light up. No problem with that. However, when I input the same "1111" into Visual Basic Application, the 2 led on the right side would light up. Based on my observation from debugging, the line " tcp_recved(tpcb, p->len); " below, would store a value of 4 for Hercules and 6 for Visual Basics.

 

/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "xparameters.h"
#include "xgpio.h"
#include "lwip/err.h"
#include "lwip/tcp.h"
#if defined (__arm__) || defined (__aarch64__)
#include "xil_printf.h"
#endif
XGpio led;
void AXI_GPIO_Init();
void set_led(char cmd[4]);
int transfer_data() {
 return 0;
}
void print_app_header()
{
 xil_printf("\n\r\n\r-----lwIP TCP echo server ------\n\r");
 xil_printf("TCP packets sent to port 6001 will be echoed back\n\r");
}
err_t recv_callback(void *arg, struct tcp_pcb *tpcb,
                               struct pbuf *p, err_t err)
{
 char cmd[4];
 char msg[23];
 /* do not read the packet if we are not in ESTABLISHED state */
 if (!p) {
  tcp_close(tpcb);
  tcp_recv(tpcb, NULL);
  return ERR_OK;
 }
 /* indicate that the packet has been received */
 tcp_recved(tpcb, p->len);
 /* Copy command */
 memcpy(cmd, p->payload, 4);
 /* Echo back the command */
 /* In this case, we assume that the msg is < TCP_SND_BUF (8192) */
 if (tcp_sndbuf(tpcb) > sizeof(msg))
 {
  sprintf(msg, "\nEntered Command: %s\n", (char*)p->payload);
  err = tcp_write(tpcb, msg, sizeof(msg), 1);
 }
 else
 {
  xil_printf("no space in tcp_sndbuf\n\r");
 }
 /* Process command */
 set_led(cmd);
 /* free the received pbuf */
 pbuf_free(p);
 return ERR_OK;
}
err_t accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err)
{
 static int connection = 1;
 /* set the receive callback for this connection */
 tcp_recv(newpcb, recv_callback);
 /* just use an integer number indicating the connection id as the
    callback argument */
 tcp_arg(newpcb, (void*)(UINTPTR)connection);
 /* increment for subsequent accepted connections */
 connection++;
 return ERR_OK;
}

int start_application()
{
 struct tcp_pcb *pcb;
 err_t err;
 unsigned port = 7;
 /* create new TCP PCB structure */
 pcb = tcp_new();
 if (!pcb) {
  xil_printf("Error creating PCB. Out of Memory\n\r");
  return -1;
 }
 /* bind to specified @port */
 err = tcp_bind(pcb, IP_ADDR_ANY, port);
 if (err != ERR_OK) {
  xil_printf("Unable to bind to port %d: err = %d\n\r", port, err);
  return -2;
 }
 /* we do not need any arguments to callback functions */
 tcp_arg(pcb, NULL);
 /* listen for connections */
 pcb = tcp_listen(pcb);
 if (!pcb) {
  xil_printf("Out of memory while tcp_listen\n\r");
  return -3;
 }
 /* specify callback to use for incoming connections */
 tcp_accept(pcb, accept_callback);
 xil_printf("TCP echo server started @ port %d\n\r", port);
 /* Initialize AXI GPIO */
 AXI_GPIO_Init();
 return 0;
}
void AXI_GPIO_Init()
{
 XGpio_Initialize(&led, XPAR_AXI_GPIO_0_DEVICE_ID);
 XGpio_SetDataDirection(&led, 1, 0x00000000);
 xil_printf("AXI GPIO initialized as output.\n");
}
void set_led(char cmd[4])
{
 uint8_t led_value = 0;
 // Translate command to LED value
 led_value = (cmd[0] == '1') ?
   (led_value | (1 << 3)) : (led_value & ~(1 << 3));
 led_value = (cmd[1] == '1') ?
   (led_value | (1 << 2)) : (led_value & ~(1 << 2));
 led_value = (cmd[2] == '1') ?
   (led_value | (1 << 1)) : (led_value & ~(1 << 1));
 led_value = (cmd[3] == '1') ?
   (led_value | (1 << 0)) : (led_value & ~(1 << 0));
 xil_printf("LED value = %X\n", led_value);
 // Write LED value to AXI GPIO
 XGpio_DiscreteWrite(&led, 1, led_value);
}
0 Kudos
Moderator
Moderator
1,012 Views
Registered: ‎10-06-2016

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution
Hi @deandre_hj,

If the same code is running in the target (zybo board) then the issue clearly is in your VB application. You are sending different data to your target!

As a tip print the payload data in your Zybo code to check the first N bytes send by Hercules and your VB application.

Regards
Ibai

Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos
Visitor deandre_hj
Visitor
1,003 Views
Registered: ‎05-20-2018

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution

They have the same number of bytes. First photo is Hercules. Second photo is Visual Basic.

Screenshot (5).png
Screenshot (6).png
0 Kudos
Moderator
Moderator
1,000 Views
Registered: ‎10-06-2016

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution
Hi,

In your screenshots there is no information about the content of the payload. The syze of p->payload is the size of the pointer, not the value of the array.

You need to check the content, so either check it on memory or print from serial line.

Regards
Ibai

Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos
Visitor deandre_hj
Visitor
936 Views
Registered: ‎05-20-2018

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution

Hi, Im not very sure what you are looking for but this are the things that I can provide with my limited knowledge. First is Hercules, second is Visual Basic.

Screenshot (14).png
Screenshot (15).png
0 Kudos
Moderator
Moderator
1,163 Views
Registered: ‎10-06-2016

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution
Hi @deandre_hj,

In your image I only can see the value of length variable within the p pointer. What you need to check is the content of payload, I mean the values you are getting in the target.

Regards
Ibai

Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos
Visitor deandre_hj
Visitor
872 Views
Registered: ‎05-20-2018

Re: Visual Basic Application with Zybo Board using TCP Server

Jump to solution

Hi, ive solved the issue. Seems like I need to remove something off Visual Basic for it to work. Thanks for all advices and suggestions tho.

0 Kudos