Jump to content

JSON protocol - how to query the OpenScope programmatically? [SOLVED]


Recommended Posts

Hi,
I am trying to use the JSON protocol to access programmatically the OpenScope (https://reference.digilentinc.com/reference/software/openscope/communication-protocol). However, I am unable to get a correct ACK from the device, regardless of what I transmit.

A bit of background. I am running the Digilent agent on a Mac, which is then connected through USB to the Openscope. From another device I am wirelessly connecting to the IP address of this computer, using the default port 42135 (I wrote some custom Java software for the socket connection). I am sending a query of the kind {"mode":"JSON"} but instead of receiving the correct answer, I receive 

HTTP/1.1 413 entity too large
Connection: close
413 Entity too large
Client got end-of-stream.

FYI, I also tried to connect wirelessly directly to the OpenScope, without passing through the Mac. So after setting up the WIFI, I see my OpenScope correctly connected to the network, but I am still unable to access it (PORT 42135 refuses a connection). Finally, I tried to connect to the device simply using serial, but I could not find any specific baudrate in the documentation: I tried few (115200, 9600) but nothing was successful.

So, here the question. Is there any way I can wirelessly connect to the OpenScope from another computer and query its state through the JSON protocol? Is there any example I could follow?

Thank you

Link to comment
Share on other sites

I'll try to answer to myself, in case it might help someone else.

1) Connect the OpenScope to a PC, open a terminal such as Putty for PC, or Serial for the MAC. Setup a connection and ensure to put your baud rate to 1250000. After starting up the device, you should see a screen with a menu as in the figure.

1.jpg

Click 1 to use the JSON mode, and then enter the string {"debugPrint":"on"} to get in debug mode.

2) After setting up and connecting to the WIFI (the blue LED on the OpenScope should be a solid blue), make sure that your computer see the OpenScope. You can use the "ping" command from the terminal to ensure that the devices see each other. Then go ahead and download a software like Postman. Create a new request, make sure you select POST as a method. In my case, the url is the IP of the OpenScope - something like http://10.0.1.24

For the body put a key (anything should be fine) and a value (such as {"debugPrint":"on"}). Then send the request. On the serial console you should see what happened to your request. In my case, I receive a strange

Quote

JSON Post Detected
Jumping to HTTP File Not Found page
HTTP Error

message (see Figure).

2.jpg


=====>> IN CONCLUSION

I am stuck here. The message gets delivered, but nothing comes back. I tried to use different ports (http://10.0.1.24:80 or http://10.0.1.24:42135) but I don't get any JSON value back. Interestingly enough, if I put as an address that of another computer, running the Digilent Agent, I get an answer to my query like in the picture below.

3.jpg

Does anyone have any suggestion?

 

Link to comment
Share on other sites

Hey uaiti,

As you've already discovered you can talk directly to the OpenScope via wifi or go through the Digilent Agent if the OpenScope is connected to a computer via USB.

WaveForms Live uses both of these methods:

  • If you click Add A Device and choose Agent WaveForms live sends commands from your browser to the agent using HTTP POSTs.  The Agent forwards these messages out on the UART (at a baud rate of 1250000), waits for a response from the OpenScope, and forwards the response back as the response to the HTTP POST request.
  • If you click Add A Device and choose Network WaveForms Live sends the same HTTP POSTS directly to the OpenScope.

In both cases the same Digilent Instrumentation Protocol commands are sent, however there are a few additional commands to configure the Agent.

WaveForms Live needs a way to tell the Agent which USB device to connect to.  This is done with the 'Set Active Device' command which is also an HTTP POST command from WaveForms but sent to a different endpoint (<AGENTS_IP_ADDRESS>:<PORT>/config).  The last image you posted is the Agent telling you that it does not have an active device (ie you didn't tell it which USB device to forward commands to).  Unfortunately I don't think we published much / any documentation on this part.

You can see the Digilent Agent code that handles these commands here.  Scroll all the way to the bottom and starting on line 217 you'll see the command string to command enum mapping.  The Digilent Agent parses and executes the commands you send it in the processCommand() function in that same file.

As for the JSON mode issue, can you confirm that you are including the "\r\n" in your command?

You could also try connecting to the device from WaveForms Live and navigating to the instrument panel.  This will put the OpenScope MZ in JSON mode. Then just close that browser and start sending other JSON commands to the device.  The OpenScope will remain in JSON mode until it reboots.

Hopefully that helps.  Let us know what other questions you have.

Thanks!

-Kristoff

 

Link to comment
Share on other sites

Hi Kristoff,

thank you for the reply. I was about to give up, as I was continuously getting a HTTP error. I think that the problem boiled down to parsing and how I was transmitting the POST request. So I changed tool and used the terminal and curl, to send out a request. If I send something like 

curl -v -H "Content-Type: application/json" -X POST -d '{"debugPrint":"on"}\r\n' http://10.0.1.24

where in bold you can see my command, and also the IP of my device, everything works!

Thanks a lot

Andrea

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...