Announcement

Collapse
No announcement yet.

Some observation on Web To Serial Library

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • mariano
    replied
    I can't replicate the problem.

    I use the following command from the command line:

    Code:
    curl -u admin:PASSWORD -X POST -d "group=Line&optionalGroupInstance=1&optionalItem=Transmitter&action=Hex Transmit 2424534D00C0000D" http://192.168.1.3/action/status
    And in RealTerm I see the right output on Line 1 of the xPico Wi-Fi. Maybe Pcommlite is the problem? I would try with RealTerm.

    hextransmit.jpg

    Leave a comment:


  • BC_FR
    started a topic Some observation on Web To Serial Library

    Some observation on Web To Serial Library

    I dl the new firmware and I'm focusing on the new library who allows to send and receive data from web server to serial port.

    In my example, I want to send the following command:
    "$$SM"(ascii)+0x00(an option)+0xc0+0x00 (a check sum)+0x0d(CR).

    I proceed like this :

    - My hmtl page, which is copied from your example :

    HTML Code:
    <html>
     <head>
    	<script src="xpwJslib.js"></script>
    	<title>Test dialogue serie</title>	
     </head>
    	<body>
    	
    <!--------------------------------------------------------------------------------------------------------------------------------------------->	
    		<script>
    
    			function envoyer_message(){
    
    				xpw.serialTransmit({Line: 1,message: "$$SM"});// Envois de la commande "$$SM" au port s?rie n?1 
    			}
    			
    			function updateData(){
    				var textBox=document.getElementById("textBox");
    				xpw.serialReceive({line:1,done:function(data){
    					if(data.success){
    				
    						textBox.textContent = textBox.textContent+data.message;
    					}
    					setTimeout(function(){updateData();}, 100);
    					}
    				});			
    			}
    		
    			window.onload=function(){
    				updateData();
    			}
    		</script>
    <!--------------------------------------------------------------------------------------------------------------------------------------------->		
    
    		<input type="button" value="Envois commande" onclick="envoyer_message();"></input>
    		<div style="float:left;width:50%;">
    			Data from the serial port (updated once per second):
    			<div style="color:white;background-color:gray;width=400px;height=400px;overflow:scroll;"id="textBox">&nbsp
    			</div>
    		</div>
    		
    	</body>
    </html>
    And then, I modified your method "serialTransmit" like this :

    Code:
    serialTransmit: function (args) {
    			if (typeof args === "undefined")
    				return;
    			var line = (args.line == '1' || args.line == '2') ? args.line : '1';
    			if (typeof args.message === "undefined") {
    				if (typeof args.done !== "undefined")
    					args.done({success: false,
    								error: "No Message to send"});
    				return;
    			}
    			else {
    				// Setup the status action with group=Line
    				var postMsg = "group=Line&optionalGroupInstance=";
    				// Here we add the optionalGroupInstance which is 1 or 2 (the Line)
    				postMsg += line;
    				// We're going to transmit in hex, note the space after Hex Transmit!
    				postMsg +="&optionalItem=Transmitter&action=Hex Transmit ";
    				// After the space we add the string we want to send (in hex)
    				
    				postMsg += String(a2hex(args.message));// The begining of my message("$$SM");
    				
    				
    				postMsg+="00" // the option 0x00
    				// My Checksum, on 2 Bytes with little endian first (I calculated myself) :
    				postMsg+="c0"
    				postMsg+="00"
    				
    				postMsg+= "0d";// I finish with (CR) 
    				var xmlhttp=new XMLHttpRequest();
    
    				if (typeof args.done !== "undefined")
    					xmlhttp.onreadystatechange=function() {
    						if (xmlhttp.readyState==4)
    							if (xmlhttp.status==200)
    								args.done({success:true});
    							else
    								args.done({success:false});
    					}
    
    				xmlhttp.open("POST", "/action/status", true);					// This is the URL for Status Actions
    				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    				xmlhttp.send(postMsg);											// Send!
    			}
    		},
    As you can see I only injected directly in hex the end of my message.
    But, when I capture what I send with PcommLite (a terminal), I have this sequence :

    24 24 53 4D 20 C0 20 0D
    The fourth characters are send perfectly, like "0xc0" and "0x0d" but as you can see, "0x00" is transformed on "0x20" !

    Do you have any explanation ?
Working...
X