Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

Electronic scale pos interface

By
Erbeia
on 2/21/13, 11:17 AM 3,152 views

Hello, I'm creating a proxy server to manage the interface between the pos module and the electronic scale. I receive well the http get request on my server, but I don't understand in wich format I have to answer with the actual weight... Can somebody tell me the correct answer format for this json request?

Here is the request I receive:

/pos/weighting_start?jsonp=jQuery18302055237984620708_1361460794237&id=r360&r=%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22call%22%2C%22params%22%3A%7B%22context%22%3A%7B%7D%7D%2C%22id%22%3A%22r360%22%7D&_=1361460812032

Url = {htp://localhost:6655/pos/weighting_start?jsonp=jQuery18302055237984620708_1361460794237&id=r360&r={"jsonrpc":"2.0","method":"call","params":{"context":{}},"id":"r360"}&_=1361460812032}

For the javascript code, it's the original device.js (..\server\openerp\addons\point_of_sale\static\src\js):

//returns the weight on the scale. 
        // is called at regular interval (up to 10x/sec) between a weighting_start()
        // and a weighting_end()
        weighting_read_kg: function(){
            var self = this;
            if(this.bypass_proxy){
                return this.weight;
            }else{
                this.message('weighting_read_kg',{})
                    .done(function(weight){
                        if(self.weighting && !self.bypass_proxy){
                            self.weight = weight;
                        }
                    });
                return this.weight;
            }
        },

I'm making the server in C#.

I have every data I need but don't know how to format them... Here is the reponse code:

private void HttpWebServer_SendData()
        {
            if (context == null) return;

            string responseString = RxString;
            byte[] buffer = Encoding.UTF8.GetBytes(responseString);
            context.Response.ContentLength64 = buffer.Length;

            context.Response.Headers.Set(HttpResponseHeader.Server, "Serial to http Server");

            System.IO.Stream output = context.Response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            output.Close();
        }

where RxString is the actual weight, ex: "120.5"

Thank you

Can you post your json structure? That way you will get more opportunities to have some answer. Maybe you just have a minor error on the json structure or alike and it will be easier to detect it.

Yaroslav
on 2/21/13, 11:19 AM

Edit your question and add there the code. Use the Edit option, it's the small pencil under the question, aligned to the right.

Yaroslav
on 2/21/13, 11:49 AM

Sorry, I'll do this

Swiss-Ecotechnologies Sarl, Erbeia
on 2/21/13, 11:49 AM

Nobody can give me an example of proxy answer that the POS 7.0 is waiting in the weighting_read_kg loop?

Swiss-Ecotechnologies Sarl, Erbeia
on 2/28/13, 3:33 AM

Here is the JQuery - JSON Exchange I get: Request: {http://localhost:6655/pos/weighting_start?jsonp=jQuery183021106903867513827_1362069234058&id=r360&r={"jsonrpc":"2.0","method":"call","params":{"context":{}},"id":"r360"}&_=1362069249742}

Response: "{\"jsonrpc\": \"2.0\", \"result\": 12.5, \"id\": \"r360\"}"

I still get a script error in the POS frontend.

Swiss-Ecotechnologies Sarl, Erbeia
on 2/28/13, 12:41 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 2/21/13, 11:17 AM
Seen: 3152 times
Last updated: 12/19/15, 8:27 AM